Skip to content

Commit

Permalink
MDL-14679 converted some get courses
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 1, 2008
1 parent f400841 commit 579d45b
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 64 deletions.
52 changes: 24 additions & 28 deletions course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
$resort = optional_param('resort', 0, PARAM_BOOL);
$categorytheme= optional_param('categorytheme', false, PARAM_CLEAN);

$rename = stripslashes($rename); // TODO: remove soon

if ($CFG->forcelogin) {
require_login();
}
Expand Down Expand Up @@ -60,7 +62,7 @@
/// Rename the category if requested
if (!empty($rename) and confirm_sesskey()) {
$category->name = $rename;
if (! set_field("course_categories", "name", $category->name, "id", $category->id)) {
if (!$DB->set_field("course_categories", "name", $category->name, array("id"=>$category->id))) {
notify("An error occurred while renaming the category");
}
// MDL-9983
Expand All @@ -70,7 +72,7 @@
/// Set the category theme if requested
if (($categorytheme !== false) and confirm_sesskey()) {
$category->theme = $categorytheme;
if (! set_field('course_categories', 'theme', $category->theme, 'id', $category->id)) {
if (!$DB->set_field('course_categories', 'theme', $category->theme, array('id'=>$category->id))) {
notify('An error occurred while setting the theme');
}
}
Expand All @@ -80,15 +82,14 @@
if ($resort and confirm_sesskey()) {
if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
// move it off the range
$count = get_record_sql('SELECT MAX(sortorder) AS max, 1
FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
$count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course} WHERE category= ?', array($category->id));
$count = $count->max + 100;
begin_sql();
$DB->begin_sql();
foreach ($courses as $course) {
set_field('course', 'sortorder', $count, 'id', $course->id);
$DB->set_field('course', 'sortorder', $count, array('id'=>$course->id));
$count++;
}
commit_sql();
$DB->commit_sql();
fix_course_sortorder($category->id);
}
}
Expand Down Expand Up @@ -163,13 +164,13 @@
if ($creatorediting) {
/// Move a specified course to a new category

if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved
if (!empty($moveto) and $data = data_submitted(false) and confirm_sesskey()) { // Some courses are being moved

// user must have category update in both cats to perform this
require_capability('moodle/category:update', $context);
require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));

if (! $destcategory = get_record("course_categories", "id", $data->moveto)) {
if (! $destcategory = $DB->get_record("course_categories", array("id"=>$data->moveto))) {
print_error("cannotfindcategory", '', '', $data->moveto);
}

Expand All @@ -188,14 +189,14 @@
if ((!empty($hide) or !empty($show)) and confirm_sesskey()) {
require_capability('moodle/course:visibility', $context);
if (!empty($hide)) {
$course = get_record("course", "id", $hide);
$course = $DB->get_record("course", array("id"=>$hide));
$visible = 0;
} else {
$course = get_record("course", "id", $show);
$course = $DB->get_record("course", array("id"=>$show));
$visible = 1;
}
if ($course) {
if (! set_field("course", "visible", $visible, "id", $course->id)) {
if (!$DB->set_field("course", "visible", $visible, array("id"=>$course->id))) {
notify("Could not update that course!");
}
}
Expand All @@ -214,31 +215,26 @@
fix_course_sortorder($category->id);

// we are going to need to know the range
$max = get_record_sql('SELECT MAX(sortorder) AS max, 1
FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
$max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course} WHERE category=?', array($category->id));
$max = $max->max + 100;

if (!empty($moveup)) {
$movecourse = get_record('course', 'id', $moveup);
$swapcourse = get_record('course',
'category', $category->id,
'sortorder', $movecourse->sortorder - 1);
$movecourse = $DB->get_record('course', array('id'=>$moveup));
$swapcourse = $DB->get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder-1)));
} else {
$movecourse = get_record('course', 'id', $movedown);
$swapcourse = get_record('course',
'category', $category->id,
'sortorder', $movecourse->sortorder + 1);
$movecourse = get_record('course', array('id'=>$movedown));
$swapcourse = get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder+1)));
}

if ($swapcourse and $movecourse) { // Renumber everything for robustness
begin_sql();
if (!( set_field("course", "sortorder", $max, "id", $swapcourse->id)
&& set_field("course", "sortorder", $swapcourse->sortorder, "id", $movecourse->id)
&& set_field("course", "sortorder", $movecourse->sortorder, "id", $swapcourse->id)
$DB->begin_sql();
if (!( $DB->set_field("course", "sortorder", $max, array("id"=>$swapcourse->id))
&& $DB->set_field("course", "sortorder", $swapcourse->sortorder, array("id"=>$movecourse->id))
&& $DB->set_field("course", "sortorder", $movecourse->sortorder, array("id"=>$swapcourse->id))
)) {
notify("Could not update that course!");
}
commit_sql();
$DB->commit_sql();
}

}
Expand All @@ -264,7 +260,7 @@
}

/// Print out all the sub-categories
if ($subcategories = get_records("course_categories", "parent", $category->id, "sortorder ASC")) {
if ($subcategories = $DB->get_records("course_categories", array("parent"=>$category->id), "sortorder ASC")) {
$firstentry = true;
foreach ($subcategories as $subcategory) {
if ($subcategory->visible or has_capability('moodle/course:create', $context)) {
Expand Down
4 changes: 2 additions & 2 deletions course/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
$stradministration = get_string("administration");
$strcategories = get_string("categories");

if (! $course = get_record("course", "id", $id)) {
if (! $course = $DB->get_record("course", array("id"=>$id))) {
print_error("invalidcourseid");
}

$category = get_record("course_categories", "id", $course->category);
$category = $DB->get_record("course_categories", array("id"=>$course->category));
$navlinks = array();

if (! $delete) {
Expand Down
14 changes: 7 additions & 7 deletions course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@
} else {
redirect($CFG->wwwroot.'/course/category.php?categoryedit=on&id='.$category->id);
}
} else if (($data = $mform->get_data())) {
} else if (($data = $mform->get_data(false))) {
$newcategory = new stdClass();
$newcategory->name = $data->name;
$newcategory->name = $data->name;
$newcategory->description = $data->description;
$newcategory->sortorder = 999;
$newcategory->parent = $data->parent; // if $id = 0, the new category will be a top-level category
$newcategory->sortorder = 999;
$newcategory->parent = $data->parent; // if $id = 0, the new category will be a top-level category

if (!empty($data->theme) && !empty($CFG->allowcategorythemes)) {
$newcategory->theme = $data->theme;
theme_setup();
}

if (empty($category) && has_capability('moodle/category:create', $context)) { // Create a new category
if (!$newcategory->id = insert_record('course_categories', $newcategory)) {
if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) {
notify( "Could not insert the new category '$newcategory->name' ");
} else {
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
Expand All @@ -78,11 +78,11 @@
$newcategory->id = $category->id;

if ($newcategory->parent != $category->parent) {
$parent_cat = get_record('course_categories', 'id', $newcategory->parent);
$parent_cat = $DB->get_record('course_categories', array('id'=>$newcategory->parent));
move_category($newcategory, $parent_cat);
}

if (!update_record('course_categories', $newcategory)) {
if (!$DB->update_record('course_categories', $newcategory)) {
print_error( "cannotupdatecategory", '', '', $newcategory->name);
} else {
if ($newcategory->parent == 0) {
Expand Down
10 changes: 4 additions & 6 deletions course/editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

$id = required_param('id',PARAM_INT); // Week ID

if (! $section = get_record("course_sections", "id", $id)) {
if (! $section = $DB->get_record("course_sections", array("id"=>$id))) {
print_error("sectionnotexist");
}

if (! $course = get_record("course", "id", $section->course)) {
if (! $course = $DB->get_record("course", array("id"=>$section->course))) {
print_error("invalidcourseid");
}

Expand All @@ -20,11 +20,11 @@

/// If data submitted, then process and store.

if ($form = data_submitted() and confirm_sesskey()) {
if ($form = data_submitted(false) and confirm_sesskey()) {

$timenow = time();

if (! set_field("course_sections", "summary", $form->summary, "id", $section->id)) {
if ($DB->set_field("course_sections", "summary", $form->summary, array("id"=>$section->id))) {
print_error("cannotupdatesummary");
}

Expand All @@ -38,8 +38,6 @@

if (empty($form)) {
$form = $section;
} else {
$form = stripslashes_safe($form);
}

// !! no db access using data from $form beyond this point !!
Expand Down
2 changes: 1 addition & 1 deletion course/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
redirect($wwwroot.'/login/index.php');
}

if (! $course = $DB->get_record('course', array('id'=>$id) )) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("That's an invalid course id");
}

Expand Down
6 changes: 3 additions & 3 deletions course/import/groups/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

$id = required_param('id', PARAM_INT); // Course id

if (! $course = $DB->get_record('course', array('id'=>$id) )) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}

Expand Down Expand Up @@ -140,7 +140,7 @@
//if idnumber is set, we use that.
//unset invalid courseid
if (isset($newgroup->idnumber)){
if (!$mycourse = get_record('course', 'idnumber',$newgroup->idnumber)){
if (!$mycourse = $DB->get_record('course', array('idnumber'=>$newgroup->idnumber))) {
notify(get_string('unknowncourseidnumber', 'error', $newgroup->idnumber));
unset($newgroup->courseid);//unset so 0 doesnt' get written to database
}
Expand All @@ -150,7 +150,7 @@
//unset invalid coursename (if no id)

else if (isset($newgroup->coursename)){
if (!$mycourse = get_record('course', 'shortname',$newgroup->coursename)){
if (!$mycourse = $DB->get_record('course', array('shortname', $newgroup->coursename))) {
notify(get_string('unknowncourse', 'error', $newgroup->coursename));
unset($newgroup->courseid);//unset so 0 doesnt' get written to database
}
Expand Down
2 changes: 1 addition & 1 deletion course/importstudents.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
redirect("$CFG->wwwroot/$CFG->admin/index.php");
}

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("invalidcourseid");
}

Expand Down
2 changes: 1 addition & 1 deletion course/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@
$id = required_param('id',PARAM_INT);
$section = required_param('section',PARAM_INT);

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("invalidcourseid");
}

Expand Down
2 changes: 1 addition & 1 deletion course/scales.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$id = required_param('id', PARAM_INT); // course id

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("invalidcourseid");
}

Expand Down
2 changes: 1 addition & 1 deletion course/unenrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$userid = 0;
}

if (! $course = $DB->get_record('course', array('id'=>$id) )) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}

Expand Down
2 changes: 1 addition & 1 deletion course/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 100, PARAM_INT);

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid', 'error');
}

Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$id = required_param('id', PARAM_INT); // course

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}

Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/type/online/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// get parameter
$id = required_param('id', PARAM_INT); // course

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourse');
}

Expand Down
2 changes: 1 addition & 1 deletion mod/choice/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$id = required_param('id',PARAM_INT); // course

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}

Expand Down
2 changes: 1 addition & 1 deletion mod/data/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

$id = required_param('id', PARAM_INT); // course

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
error("Course ID is incorrect");
}

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

$id = required_param('id', PARAM_INT);

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
error("Course ID is incorrect");
}
$capabilities = feedback_load_course_capabilities($course->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
$search = forum_clean_search_terms($search);
}

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
error("Course id is incorrect.");
}

Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

$id = required_param('id', PARAM_INT); // course

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}

Expand Down
2 changes: 1 addition & 1 deletion mod/hotpot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require_once("lib.php");

$id = required_param('id', PARAM_INT); // course
if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}

Expand Down
2 changes: 1 addition & 1 deletion mod/resource/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$id = required_param( 'id', PARAM_INT ); // course

if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}

Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$id = required_param('id', PARAM_INT); // course id

if (!empty($id)) {
if (! $course = get_record("course", "id", $id)) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("Course ID is incorrect");
}
} else {
Expand Down
Loading

0 comments on commit 579d45b

Please sign in to comment.