Merge branch 'MDL-45229-master' of git://github.com/FMCorz/moodle

This commit is contained in:
Sam Hemelryk 2014-04-29 08:40:16 +12:00
commit 48dba530c6
3 changed files with 36 additions and 1 deletions

View File

@ -1205,6 +1205,17 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
$resourcestotoggle = array();
if ($section = $DB->get_record("course_sections", array("course"=>$courseid, "section"=>$sectionnumber))) {
$DB->set_field("course_sections", "visible", "$visibility", array("id"=>$section->id));
$event = \core\event\course_section_updated::create(array(
'context' => context_course::instance($courseid),
'objectid' => $section->id,
'other' => array(
'sectionnum' => $sectionnumber
)
));
$event->add_record_snapshot('course_sections', $section);
$event->trigger();
if (!empty($section->sequence)) {
$modules = explode(",", $section->sequence);
foreach ($modules as $moduleid) {

View File

@ -988,6 +988,8 @@ class core_course_courselib_testcase extends advanced_testcase {
// Create course.
$course = $this->getDataGenerator()->create_course(array('numsections' => 3), array('createsections' => true));
$sink = $this->redirectEvents();
// Testing an empty section.
$sectionnumber = 1;
set_section_visible($course->id, $sectionnumber, 0);
@ -997,6 +999,11 @@ class core_course_courselib_testcase extends advanced_testcase {
$section_info = get_fast_modinfo($course->id)->get_section_info($sectionnumber);
$this->assertEquals($section_info->visible, 1);
// Checking that an event was fired.
$events = $sink->get_events();
$this->assertInstanceOf('\core\event\course_section_updated', $events[0]);
$sink->close();
// Testing a section with visible modules.
$sectionnumber = 2;
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
@ -1785,7 +1792,10 @@ class core_course_courselib_testcase extends advanced_testcase {
array(
'objectid' => $section->id,
'courseid' => $course->id,
'context' => context_course::instance($course->id)
'context' => context_course::instance($course->id),
'other' => array(
'sectionnum' => $section->section
)
)
);
$event->add_record_snapshot('course_sections', $section);
@ -1802,6 +1812,7 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals($section->id, $event->objectid);
$this->assertEquals($course->id, $event->courseid);
$this->assertEquals($coursecontext->id, $event->contextid);
$this->assertEquals($section->section, $event->other['sectionnum']);
$expecteddesc = 'Course ' . $event->courseid . ' section ' . $event->other['sectionnum'] . ' updated by user ' . $event->userid;
$this->assertEquals($expecteddesc, $event->get_description());
$url = new moodle_url('/course/editsection.php', array('id' => $event->objectid));

View File

@ -89,4 +89,17 @@ class course_section_updated extends base {
$sectiondata = $this->get_record_snapshot('course_sections', $this->objectid);
return array($this->courseid, 'course', 'editsection', 'editsection.php?id=' . $this->objectid, $sectiondata->section);
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['sectionnum'])) {
throw new \coding_exception('The sectionnum must be set in $other');
}
}
}