Skip to content

Commit

Permalink
Merge branch 'MDL-82845-main' of https://github.com/ferranrecio/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Sep 19, 2024
2 parents 2aa7790 + 37ce4e8 commit e4e8bc8
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 98 deletions.
8 changes: 8 additions & 0 deletions .upgradenotes/MDL-82845-2024091708245574.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
issueNumber: MDL-82845
notes:
core:
- message: >-
The section_info class now includes a new method called
get_sequence_cm_infos that retrieves all cm_info instances associated
with the course section.
type: improved
7 changes: 7 additions & 0 deletions .upgradenotes/MDL-82845-2024091710272206.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
issueNumber: MDL-82845
notes:
core:
- message: >-
The global_navigation::load_section_activities method is now deprecated
and replaced by global_navigation::load_section_activities_navigation.
type: deprecated
2 changes: 1 addition & 1 deletion course/format/classes/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ public function ajax_section_move() {
* of the view script, it is not enough to change just this function. Do not forget
* to add proper redirection.
*
* @param int|stdClass $section Section object from database or just field course_sections.section
* @param int|stdClass|section_info $section Section object from database or just field course_sections.section
* if null the course view page is returned
* @param array $options options for view URL. At the moment core uses:
* 'navigation' (bool) if true and section not empty, the function returns section page; otherwise, it returns course page.
Expand Down
24 changes: 24 additions & 0 deletions lib/modinfolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3226,6 +3226,9 @@ class section_info implements IteratorAggregate {
*/
private ?sectiondelegate $_delegateinstance = null;

/** @var cm_info[]|null Section cm_info activities, null when it is not loaded yet. */
private array|null $_sequencecminfos = null;

/**
* @var bool|null $_isorphan True if the section is orphan for some reason.
*/
Expand Down Expand Up @@ -3625,6 +3628,27 @@ private function get_sequence() {
}
}

/**
* Returns the course modules in this section.
*
* @return cm_info[]
*/
public function get_sequence_cm_infos(): array {
if ($this->_sequencecminfos !== null) {
return $this->_sequencecminfos;
}
$sequence = $this->modinfo->sections[$this->_sectionnum] ?? [];
$cms = $this->modinfo->get_cms();
$result = [];
foreach ($sequence as $cmid) {
if (isset($cms[$cmid])) {
$result[] = $cms[$cmid];
}
}
$this->_sequencecminfos = $result;
return $result;
}

/**
* Returns course ID - from course_sections table
*
Expand Down
Loading

0 comments on commit e4e8bc8

Please sign in to comment.