mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
Merge branch 'wip-MDL-41508-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
34ac96bf6d
2 changed files with 57 additions and 33 deletions
|
@ -2046,40 +2046,43 @@ function move_courses($courseids, $categoryid) {
|
|||
$newparent = context_coursecat::instance($category->id);
|
||||
$i = 1;
|
||||
|
||||
foreach ($courseids as $courseid) {
|
||||
if ($dbcourse = $DB->get_record('course', array('id' => $courseid))) {
|
||||
$course = new stdClass();
|
||||
$course->id = $courseid;
|
||||
$course->category = $category->id;
|
||||
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
|
||||
if ($category->visible == 0) {
|
||||
// Hide the course when moving into hidden category, do not update the visibleold flag - we want to get
|
||||
// to previous state if somebody unhides the category.
|
||||
$course->visible = 0;
|
||||
}
|
||||
|
||||
$DB->update_record('course', $course);
|
||||
|
||||
// Store the context.
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
// Update the course object we are passing to the event.
|
||||
$dbcourse->category = $course->category;
|
||||
$dbcourse->sortorder = $course->sortorder;
|
||||
|
||||
// Trigger a course updated event.
|
||||
$event = \core\event\course_updated::create(array(
|
||||
'objectid' => $course->id,
|
||||
'context' => $context,
|
||||
'other' => array('shortname' => $dbcourse->shortname,
|
||||
'fullname' => $dbcourse->fullname)
|
||||
));
|
||||
$event->add_record_snapshot('course', $dbcourse);
|
||||
$event->set_legacy_logdata(array($course->id, 'course', 'move', 'edit.php?id=' . $course->id, $course->id));
|
||||
$event->trigger();
|
||||
|
||||
$context->update_moved($newparent);
|
||||
list($where, $params) = $DB->get_in_or_equal($courseids);
|
||||
$dbcourses = $DB->get_records_select('course', 'id ' . $where, $params);
|
||||
foreach ($dbcourses as $dbcourse) {
|
||||
$course = new stdClass();
|
||||
$course->id = $dbcourse->id;
|
||||
$course->category = $category->id;
|
||||
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
|
||||
if ($category->visible == 0) {
|
||||
// Hide the course when moving into hidden category, do not update the visibleold flag - we want to get
|
||||
// to previous state if somebody unhides the category.
|
||||
$course->visible = 0;
|
||||
}
|
||||
|
||||
$DB->update_record('course', $course);
|
||||
|
||||
// Store the context.
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
// Update the course object we are passing to the event.
|
||||
$dbcourse->category = $course->category;
|
||||
$dbcourse->sortorder = $course->sortorder;
|
||||
if (isset($course->visible)) {
|
||||
$dbcourse->visible = $course->visible;
|
||||
}
|
||||
|
||||
// Trigger a course updated event.
|
||||
$event = \core\event\course_updated::create(array(
|
||||
'objectid' => $course->id,
|
||||
'context' => $context,
|
||||
'other' => array('shortname' => $dbcourse->shortname,
|
||||
'fullname' => $dbcourse->fullname)
|
||||
));
|
||||
$event->add_record_snapshot('course', $dbcourse);
|
||||
$event->set_legacy_logdata(array($course->id, 'course', 'move', 'edit.php?id=' . $course->id, $course->id));
|
||||
$event->trigger();
|
||||
|
||||
$context->update_moved($newparent);
|
||||
}
|
||||
fix_course_sortorder();
|
||||
cache_helper::purge_by_event('changesincourse');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue