Merge branch 'MDL-75594-master' of https://github.com/sh-csg/moodle
This commit is contained in:
+15
-1
@@ -71,8 +71,22 @@ if (!empty($add)) {
|
||||
$section = required_param('section', PARAM_INT);
|
||||
$type = optional_param('type', '', PARAM_ALPHA);
|
||||
$returntomod = optional_param('return', 0, PARAM_BOOL);
|
||||
$beforemod = optional_param('beforemod', 0, PARAM_INT);
|
||||
|
||||
redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod&sr=$sectionreturn");
|
||||
redirect(
|
||||
new moodle_url(
|
||||
'/course/modedit.php',
|
||||
[
|
||||
'add' => $add,
|
||||
'type' => $type,
|
||||
'course' => $id,
|
||||
'section' => $section,
|
||||
'return' => $returntomod,
|
||||
'sr' => $sectionreturn,
|
||||
'beforemod' => $beforemod,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
} else if (!empty($update)) {
|
||||
$cm = get_coursemodule_from_id('', $update, 0, true, MUST_EXIST);
|
||||
|
||||
@@ -36,6 +36,7 @@ $update = optional_param('update', 0, PARAM_INT);
|
||||
$return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true
|
||||
$type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
|
||||
$sectionreturn = optional_param('sr', null, PARAM_INT);
|
||||
$beforemod = optional_param('beforemod', 0, PARAM_INT);
|
||||
|
||||
$url = new moodle_url('/course/modedit.php');
|
||||
$url->param('sr', $sectionreturn);
|
||||
@@ -73,6 +74,7 @@ if (!empty($add)) {
|
||||
$data->return = 0;
|
||||
$data->sr = $sectionreturn;
|
||||
$data->add = $add;
|
||||
$data->beforemod = $beforemod;
|
||||
if (!empty($type)) { //TODO: hopefully will be removed in 2.0
|
||||
$data->type = $type;
|
||||
}
|
||||
|
||||
+4
-1
@@ -116,6 +116,9 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
||||
} else {
|
||||
$newcm->showdescription = 0;
|
||||
}
|
||||
if (empty($moduleinfo->beforemod)) {
|
||||
$moduleinfo->beforemod = null;
|
||||
}
|
||||
|
||||
// From this point we make database changes, so start transaction.
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
@@ -177,7 +180,7 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
||||
|
||||
// Course_modules and course_sections each contain a reference to each other.
|
||||
// So we have to update one of them twice.
|
||||
$sectionid = course_add_cm_to_section($course, $moduleinfo->coursemodule, $moduleinfo->section);
|
||||
$sectionid = course_add_cm_to_section($course, $moduleinfo->coursemodule, $moduleinfo->section, $moduleinfo->beforemod);
|
||||
|
||||
// Trigger event based on the action we did.
|
||||
// Api create_from_cm expects modname and id property, and we don't want to modify $moduleinfo since we are returning it.
|
||||
|
||||
@@ -197,7 +197,6 @@ abstract class moodleform_mod extends moodleform {
|
||||
return $this->_features;
|
||||
}
|
||||
|
||||
|
||||
protected function init_features() {
|
||||
global $CFG;
|
||||
|
||||
@@ -1062,6 +1061,9 @@ abstract class moodleform_mod extends moodleform {
|
||||
|
||||
$mform->addElement('hidden', 'sr', 0);
|
||||
$mform->setType('sr', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'beforemod', 0);
|
||||
$mform->setType('beforemod', PARAM_INT);
|
||||
}
|
||||
|
||||
public function standard_grading_coursemodule_elements() {
|
||||
|
||||
@@ -160,4 +160,76 @@ class modlib_test extends \advanced_testcase {
|
||||
$this->expectException('required_capability_exception');
|
||||
get_moduleinfo_data($assigncm, $course);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add_moduleinfo (only beforemod parameter for now).
|
||||
*
|
||||
* @covers \add_moduleinfo
|
||||
*/
|
||||
public function test_add_moduleinfo() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$this->setAdminUser();
|
||||
$course = self::getDataGenerator()->create_course();
|
||||
$labelmodule = $DB->get_record('modules', ['name' => 'label'], '*', MUST_EXIST);
|
||||
$sectionnumber = 1;
|
||||
$modules = [];
|
||||
$moduleinfo = [];
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$modules[$i] = self::getDataGenerator()->create_module('label', ['course' => $course->id, 'section' => $sectionnumber]);
|
||||
$modulescm[$i] = get_coursemodule_from_id('label', $modules[$i]->cmid);
|
||||
}
|
||||
|
||||
$modules[4] = self::getDataGenerator()->create_module('label', ['course' => $course->id, 'section' => $sectionnumber + 1]);
|
||||
$modulescm[4] = get_coursemodule_from_id('label', $modules[4]->cmid);
|
||||
|
||||
// The beforemod attribute is not set, should be null afterwards.
|
||||
list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $labelmodule->name, $sectionnumber);
|
||||
$moduleinfo[0] = add_moduleinfo($data, $course);
|
||||
$this->assertEquals(null, $moduleinfo[0]->beforemod);
|
||||
|
||||
// Insert before the first module.
|
||||
list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $labelmodule->name, $sectionnumber);
|
||||
$data->beforemod = $modulescm[0]->id;
|
||||
$moduleinfo[1] = add_moduleinfo($data, $course);
|
||||
$this->assertEquals($modulescm[0]->id, $moduleinfo[1]->beforemod);
|
||||
|
||||
// Insert between the two last modules.
|
||||
list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $labelmodule->name, $sectionnumber);
|
||||
$data->beforemod = $modulescm[3]->id;
|
||||
$moduleinfo[2] = add_moduleinfo($data, $course);
|
||||
$this->assertEquals($modulescm[3]->id, $moduleinfo[2]->beforemod);
|
||||
|
||||
// Insert before a not existing module.
|
||||
course_delete_module($modulescm[2]->id);
|
||||
|
||||
list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $labelmodule->name, $sectionnumber);
|
||||
$data->beforemod = $modulescm[2]->id;
|
||||
$moduleinfo[3] = add_moduleinfo($data, $course);
|
||||
$this->assertEquals($modulescm[2]->id, $moduleinfo[3]->beforemod);
|
||||
|
||||
// Insert before a module that is in another section.
|
||||
list($module, $context, $cw, $cm, $data) = prepare_new_moduleinfo_data($course, $labelmodule->name, $sectionnumber);
|
||||
$data->beforemod = $modulescm[4]->id;
|
||||
$moduleinfo[4] = add_moduleinfo($data, $course);
|
||||
$this->assertEquals($modulescm[4]->id, $moduleinfo[4]->beforemod);
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
$expectedorder = [
|
||||
$moduleinfo[1]->coursemodule,
|
||||
$modulescm[0]->id,
|
||||
$modulescm[1]->id,
|
||||
$moduleinfo[2]->coursemodule,
|
||||
$modulescm[3]->id,
|
||||
$moduleinfo[0]->coursemodule,
|
||||
$moduleinfo[3]->coursemodule,
|
||||
$moduleinfo[4]->coursemodule,
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedorder, $modinfo->get_sections()[$sectionnumber]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
This files describes API changes in /course/*,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 4.2 ===
|
||||
* course/mod.php now accepts parameter beforemod for adding course modules. It contains the course module id
|
||||
of an existing course module. The new module is inserted before this module.
|
||||
|
||||
=== 4.1 ===
|
||||
* The function course_modchooser() has been finally deprecated and can not be used anymore. Please use
|
||||
course_activitychooser() instead.
|
||||
|
||||
Reference in New Issue
Block a user