MDL-80248 course: Display only content for the General section

This commit is contained in:
Sara Arjona
2024-01-19 12:03:36 +01:00
parent 810554ee83
commit e6f75b59a3
37 changed files with 366 additions and 105 deletions
+79 -4
View File
@@ -37,7 +37,6 @@ use moodle_exception;
use coding_exception;
use moodle_url;
use lang_string;
use completion_info;
use core_external\external_api;
use stdClass;
use cache;
@@ -78,8 +77,10 @@ abstract class base {
protected $course = false;
/** @var array caches format options, please use course_format::get_format_options() */
protected $formatoptions = array();
/** @var int the section number in single section format, zero for multiple section formats. */
protected $singlesection = 0;
/** @var int|null the section number in single section format, null for multiple section formats. */
protected $singlesection = null;
/** @var int|null the sectionid when a single section is selected, null when multiple sections are displayed. */
protected $singlesectionid = null;
/** @var course_modinfo the current course modinfo, please use course_format::get_modinfo() */
private $modinfo = null;
/** @var array cached instances */
@@ -560,6 +561,43 @@ abstract class base {
return get_string('highlighted');
}
/**
* Set if the current format instance will show multiple sections or an individual one.
*
* Some formats has the hability to swith from one section to multiple sections per page.
*
* @param int|null $sectionid null for all sections or a sectionid.
*/
public function set_sectionid(?int $sectionid): void {
if ($sectionid === null) {
$this->singlesection = null;
$this->singlesectionid = null;
return;
}
$modinfo = get_fast_modinfo($this->courseid);
$sectioninfo = $modinfo->get_section_info_by_id($sectionid);
if ($sectioninfo === null) {
throw new coding_exception('Invalid sectionid: '. $sectionid);
}
$this->singlesection = $sectioninfo->section;
$this->singlesectionid = $sectionid;
}
/**
* Get if the current format instance will show multiple sections or an individual one.
*
* Some formats has the hability to swith from one section to multiple sections per page,
* output components will use this method to know if the current display is a single or
* multiple sections.
*
* @return int|null null for all sections or the sectionid.
*/
public function get_sectionid(): ?int {
return $this->singlesectionid;
}
/**
* Set if the current format instance will show multiple sections or an individual one.
*
@@ -571,6 +609,41 @@ abstract class base {
$this->singlesection = $singlesection;
}
/**
* Set the current section number to display.
* Some formats has the hability to swith from one section to multiple sections per page.
*
* @since Moodle 4.4
* @param int|null $sectionnum null for all sections or a sectionid.
*/
public function set_sectionnum(?int $sectionnum): void {
if ($sectionnum === null) {
$this->singlesection = null;
$this->singlesectionid = null;
return;
}
$modinfo = get_fast_modinfo($this->courseid);
$sectioninfo = $modinfo->get_section_info($sectionnum);
if ($sectioninfo === null) {
throw new coding_exception('Invalid sectionnum: '. $sectionnum);
}
$this->singlesection = $sectionnum;
$this->singlesectionid = $sectioninfo->id;
}
/**
* Get the current section number to display.
* Some formats has the hability to swith from one section to multiple sections per page.
*
* @since Moodle 4.4
* @return int|null the current section number or null when there is no single section.
*/
public function get_sectionnum(): ?int {
return $this->singlesection;
}
/**
* Set if the current format instance will show multiple sections or an individual one.
*
@@ -773,7 +846,9 @@ abstract class base {
'/course/mod.php',
['sesskey' => sesskey(), $nonajaxaction => $cm->id]
);
$nonajaxurl->param('sr', $this->get_section_number());
if (!is_null($this->get_sectionid())) {
$nonajaxurl->param('sr', $this->get_section_number());
}
return $nonajaxurl;
}