mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-45229 event: Trigger event when section visibility changes
This commit is contained in:
parent
be9fb21191
commit
1f6988bb3b
@ -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) {
|
||||
|
@ -962,6 +962,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);
|
||||
@ -971,6 +973,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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user