mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-14679 converted some course related code
This commit is contained in:
parent
579d45b434
commit
e4907498da
3 changed files with 19 additions and 17 deletions
|
@ -54,7 +54,7 @@
|
|||
|
||||
print_heading(get_string('childcourses'));
|
||||
|
||||
if (!$frm = data_submitted()) {
|
||||
if (!$frm = data_submitted(false)) {
|
||||
$note = get_string("importmetacoursenote");
|
||||
print_simple_box($note, "center", "50%");
|
||||
|
||||
|
|
|
@ -49,9 +49,9 @@
|
|||
|
||||
/// Print form for creating new categories
|
||||
|
||||
$countcategories = count_records('course_categories');
|
||||
$countcategories = $DB->count_records('course_categories');
|
||||
|
||||
if ($countcategories > 1 || ($countcategories == 1 && count_records('course') > 200)) {
|
||||
if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) {
|
||||
$strcourses = get_string('courses');
|
||||
$strcategories = get_string('categories');
|
||||
|
||||
|
@ -99,7 +99,7 @@
|
|||
if (!empty($delete) and confirm_sesskey()) {
|
||||
require_once('delete_category_form.php');
|
||||
|
||||
if (!$deletecat = get_record('course_categories', 'id', $delete)) {
|
||||
if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) {
|
||||
error('Incorrect category id', 'index.php');
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,9 @@
|
|||
/// Create a default category if necessary
|
||||
if (!$categories = get_categories()) { /// No category yet!
|
||||
// Try and make one
|
||||
unset($tempcat);
|
||||
$tempcat = new object();
|
||||
$tempcat->name = get_string('miscellaneous');
|
||||
if (!$tempcat->id = insert_record('course_categories', $tempcat)) {
|
||||
if (!$tempcat->id = $DB->insert_record('course_categories', $tempcat)) {
|
||||
print_error('cannotsetupcategory');
|
||||
}
|
||||
$tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id);
|
||||
|
@ -164,9 +164,9 @@
|
|||
/// Move a category to a new parent if required
|
||||
|
||||
if (!empty($move) and ($moveto>=0) and confirm_sesskey()) {
|
||||
if ($tempcat = get_record('course_categories', 'id', $move)) {
|
||||
if ($tempcat = $DB->get_record('course_categories', array('id'=>$move))) {
|
||||
if ($tempcat->parent != $moveto) {
|
||||
$newp = get_record('course_categories', 'id', $moveto);
|
||||
$newp = $DB->get_record('course_categories', array('id'=>$moveto));
|
||||
if (! move_category($tempcat, $newp)) {
|
||||
notify('Could not update that category!');
|
||||
}
|
||||
|
@ -178,17 +178,17 @@
|
|||
/// Hide or show a category
|
||||
if ((!empty($hide) or !empty($show)) and confirm_sesskey()) {
|
||||
if (!empty($hide)) {
|
||||
$tempcat = get_record('course_categories', 'id', $hide);
|
||||
$tempcat = $DB->get_record('course_categories', array('id'=>$hide));
|
||||
$visible = 0;
|
||||
} else {
|
||||
$tempcat = get_record('course_categories', 'id', $show);
|
||||
$tempcat = $DB->get_record('course_categories', array('id'=>$show));
|
||||
$visible = 1;
|
||||
}
|
||||
if ($tempcat) {
|
||||
if (! set_field('course_categories', 'visible', $visible, 'id', $tempcat->id)) {
|
||||
if (!$DB->set_field('course_categories', 'visible', $visible, array('id'=>$tempcat->id))) {
|
||||
notify('Could not update that category!');
|
||||
}
|
||||
if (! set_field('course', 'visible', $visible, 'category', $tempcat->id)) {
|
||||
if (!$DB->set_field('course', 'visible', $visible, array('category'=>$tempcat->id))) {
|
||||
notify('Could not hide/show any courses in this category !');
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@
|
|||
$movecategory = NULL;
|
||||
|
||||
if (!empty($moveup)) {
|
||||
if ($movecategory = get_record('course_categories', 'id', $moveup)) {
|
||||
if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) {
|
||||
$categories = get_categories($movecategory->parent);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
|
@ -216,7 +216,7 @@
|
|||
}
|
||||
}
|
||||
if (!empty($movedown)) {
|
||||
if ($movecategory = get_record('course_categories', 'id', $movedown)) {
|
||||
if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) {
|
||||
$categories = get_categories($movecategory->parent);
|
||||
|
||||
$choosenext = false;
|
||||
|
@ -241,7 +241,7 @@
|
|||
} else if ($category->id == $movecategory->id) {
|
||||
$category = $swapcategory;
|
||||
}
|
||||
if (! set_field('course_categories', 'sortorder', $count, 'id', $category->id)) {
|
||||
if (!$DB->set_field('course_categories', 'sortorder', $count, array('id'=>$category->id))) {
|
||||
notify('Could not update that category!');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,16 +8,18 @@
|
|||
$id = optional_param('id', false, PARAM_INT); // Course id
|
||||
$name = optional_param('name', false, PARAM_RAW); // Course short name
|
||||
|
||||
$name = stripslashes($name); // TODO: remove soon
|
||||
|
||||
if (!$id and !$name) {
|
||||
print_error("unspecifycourseid");
|
||||
}
|
||||
|
||||
if ($name) {
|
||||
if (! $course = get_record("course", "shortname", $name) ) {
|
||||
if (!$course = $DB->get_record("course", array("shortname"=>$name))) {
|
||||
print_error("invalidshortname");
|
||||
}
|
||||
} else {
|
||||
if (! $course = get_record("course", "id", $id) ) {
|
||||
if (!$course = get_record("course", array("id"=>$id))) {
|
||||
print_error("invalidcourseid");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue