MDL-14679 converted some get courses
This commit is contained in:
+24
-28
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
+2
-2
@@ -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) {
|
||||
|
||||
@@ -54,12 +54,12 @@ if ($mform->is_cancelled()){
|
||||
} 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;
|
||||
@@ -67,7 +67,7 @@ if ($mform->is_cancelled()){
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -78,11 +78,11 @@ if ($mform->is_cancelled()){
|
||||
$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) {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
|
||||
if (empty($form)) {
|
||||
$form = $section;
|
||||
} else {
|
||||
$form = stripslashes_safe($form);
|
||||
}
|
||||
|
||||
// !! no db access using data from $form beyond this point !!
|
||||
|
||||
+1
-1
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
$id = required_param('id', PARAM_INT); // Course Module ID
|
||||
|
||||
if (! $course = get_record("course", "id", $id)) {
|
||||
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
print_error("Course ID is incorrect");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user