mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-80190 core_courseformat: do not render delegated sections in course
This commit is contained in:
parent
3fc907e3d8
commit
97a7958aee
@ -187,7 +187,6 @@ class content implements named_templatable, renderable {
|
||||
$modinfo->get_section_info_by_id($singlesectionid),
|
||||
];
|
||||
}
|
||||
|
||||
return $modinfo->get_section_info_all();
|
||||
return $modinfo->get_listed_section_info_all();
|
||||
}
|
||||
}
|
||||
|
@ -316,12 +316,36 @@ class course_modinfo {
|
||||
|
||||
/**
|
||||
* Gets all sections as array from section number => data about section.
|
||||
*
|
||||
* The method will return all sections of the course, including the ones
|
||||
* delegated to a component.
|
||||
*
|
||||
* @return section_info[] Array of section_info objects organised by section number
|
||||
*/
|
||||
public function get_section_info_all() {
|
||||
return $this->sectioninfobynum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all sections listed in course page as array from section number => data about section.
|
||||
*
|
||||
* The method is similar to get_section_info_all but filtering all sections delegated to components.
|
||||
*
|
||||
* @return section_info[] Array of section_info objects organised by section number
|
||||
*/
|
||||
public function get_listed_section_info_all() {
|
||||
if (empty($this->delegatedsections)) {
|
||||
return $this->sectioninfobynum;
|
||||
}
|
||||
$sections = [];
|
||||
foreach ($this->sectioninfobynum as $section) {
|
||||
if (!$section->is_delegated()) {
|
||||
$sections[$section->section] = $section;
|
||||
}
|
||||
}
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data about specific numbered section.
|
||||
* @param int $sectionnumber Number (not id) of section
|
||||
@ -3491,6 +3515,14 @@ class section_info implements IteratorAggregate {
|
||||
return $this->_delegateinstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this section is a delegate to a component.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_delegated(): bool {
|
||||
return !empty($this->_component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares section data for inclusion in sectioncache cache, removing items
|
||||
* that are set to defaults, and adding availability data if required.
|
||||
|
@ -1039,6 +1039,35 @@ class modinfolib_test extends advanced_testcase {
|
||||
$this->assertTrue($cm->uservisible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_listed_section_info_all method.
|
||||
* @covers \course_modinfo::get_listed_section_info_all
|
||||
* @covers \course_modinfo::get_section_info_all
|
||||
*/
|
||||
public function test_get_listed_section_info_all(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a course with 4 sections.
|
||||
$course = $this->getDataGenerator()->create_course(['numsections' => 3]);
|
||||
|
||||
$listed = get_fast_modinfo($course)->get_section_info_all();
|
||||
$this->assertCount(4, $listed);
|
||||
|
||||
// Generate some delegated sections (not listed).
|
||||
formatactions::section($course)->create_delegated('mod_label', 0);
|
||||
formatactions::section($course)->create_delegated('mod_label', 1);
|
||||
|
||||
$this->assertCount(6, get_fast_modinfo($course)->get_section_info_all());
|
||||
|
||||
$result = get_fast_modinfo($course)->get_listed_section_info_all();
|
||||
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertEquals($listed[0]->id, $result[0]->id);
|
||||
$this->assertEquals($listed[1]->id, $result[1]->id);
|
||||
$this->assertEquals($listed[2]->id, $result[2]->id);
|
||||
$this->assertEquals($listed[3]->id, $result[3]->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test test_get_section_info_by_id method
|
||||
*
|
||||
@ -1525,4 +1554,22 @@ class modinfolib_test extends advanced_testcase {
|
||||
$this->assertEquals('test_component', $sectioninfos[2]->component);
|
||||
$this->assertEquals(1, $sectioninfos[2]->itemid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for section_info is_delegated.
|
||||
* @covers \section_info::is_delegated
|
||||
*/
|
||||
public function test_is_delegated(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
|
||||
|
||||
formatactions::section($course)->create_delegated('mod_label', 0);
|
||||
|
||||
$modinfo = get_fast_modinfo($course->id);
|
||||
$sectioninfos = $modinfo->get_section_info_all();
|
||||
|
||||
$this->assertFalse($sectioninfos[1]->is_delegated());
|
||||
$this->assertTrue($sectioninfos[2]->is_delegated());
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,11 @@ information provided here is intended especially for developers.
|
||||
|
||||
=== 4.4 ===
|
||||
|
||||
* New modinfo methods related to delegated sections (sections controlled by a component):
|
||||
- course_modinfo::get_listed_section_info_all to get only the listed course sections.
|
||||
- course_modinfo::has_delegated_sections to know if a course has delegated sections.
|
||||
- section_info::is_delegated to check if the section is delegated.
|
||||
- section_info::get_component_instance to get the component section delegate integration instance.
|
||||
* Added modalform config object `moduleName` param that can be used to define alternative modal type for the modalform. By default 'core/modal_save_cancel' is used.
|
||||
* Add a new parameter to the debounce (core/utils) function to allow for cancellation.
|
||||
* Add a new method core_user::get_initials to get the initials of a user in a way compatible with internationalisation.
|
||||
|
Loading…
x
Reference in New Issue
Block a user