MDL-71165 course: core_course_update_course external method

This commit is contained in:
Sara Arjona 2021-03-25 08:59:15 +01:00 committed by Andrew Nicols
parent a9b0f4dafe
commit 6347b916bc
12 changed files with 2052 additions and 1 deletions

View file

@ -92,6 +92,12 @@ class course_modinfo {
*/
private $sections;
/**
* Array from section id => section num.
* @var array
*/
private $sectionids;
/**
* Array from int (cm id) => cm_info object
* @var cm_info[]
@ -330,6 +336,24 @@ class course_modinfo {
return $this->sectioninfo[$sectionnumber];
}
/**
* Gets data about specific section ID.
* @param int $sectionid ID (not number) of section
* @param int $strictness Use MUST_EXIST to throw exception if it doesn't
* @return section_info|null Information for numbered section or null if not found
*/
public function get_section_info_by_id(int $sectionid, int $strictness = IGNORE_MISSING): ?section_info {
if (!isset($this->sectionids[$sectionid])) {
if ($strictness === MUST_EXIST) {
throw new moodle_exception('sectionnotexist');
} else {
return null;
}
}
return $this->get_section_info($this->sectionids[$sectionid], $strictness);
}
/**
* Static cache for generated course_modinfo instances
*
@ -469,6 +493,7 @@ class course_modinfo {
// Set initial values
$this->userid = $userid;
$this->sections = array();
$this->sectionids = [];
$this->cms = array();
$this->instances = array();
$this->groups = null;
@ -540,6 +565,7 @@ class course_modinfo {
// Expand section objects
$this->sectioninfo = array();
foreach ($coursemodinfo->sectioncache as $number => $data) {
$this->sectionids[$data->id] = $number;
$this->sectioninfo[$number] = new section_info($data, $number, null, null,
$this, null);
}