From 9e25f21164b4335642c33bd7938097179cd33b59 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 16 Jan 2024 09:12:09 +0100 Subject: [PATCH] MDL-80248 course: Deprecate get/set_section_number() The methods core_courseformat\base::set_section_number() and core_courseformat\base:: get_section_number() have been deprecated and replaced by core_courseformat\base::set_sectionnum() and core_courseformat\base::get_sectionnum(). The new methods use the null value when all the sections must be displayed (instead of 0). That way, section 0, can be displayed on a single page too. --- course/externallib.php | 8 +++--- course/format/classes/base.php | 33 +++++++++++++++++++--- course/format/classes/output/local/content.php | 2 +- .../classes/output/local/content/addsection.php | 2 +- .../classes/output/local/content/bulkedittools.php | 2 +- course/format/classes/output/local/content/cm.php | 2 +- .../output/local/content/cm/controlmenu.php | 2 +- .../classes/output/local/content/section.php | 8 +++--- .../output/local/content/section/controlmenu.php | 2 +- .../output/local/content/section/header.php | 2 +- course/format/lib.php | 10 +++---- .../output/courseformat/content/section.php | 2 +- .../courseformat/content/section/controlmenu.php | 2 +- course/format/topics/format.php | 4 +-- course/format/upgrade.txt | 3 ++ course/format/weeks/format.php | 4 +-- 16 files changed, 58 insertions(+), 30 deletions(-) diff --git a/course/externallib.php b/course/externallib.php index f3913df6789..90ac96d7cea 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -3639,8 +3639,8 @@ class core_course_external extends external_api { $coursecontext = context_course::instance($course->id); self::validate_context($modcontext); $format = course_get_format($course); - if ($sectionreturn) { - $format->set_section_number($sectionreturn); + if (!is_null($sectionreturn)) { + $format->set_sectionnum($sectionreturn); } $renderer = $format->get_renderer($PAGE); @@ -3767,8 +3767,8 @@ class core_course_external extends external_api { self::validate_context(context_course::instance($course->id)); $format = course_get_format($course); - if ($sectionreturn) { - $format->set_section_number($sectionreturn); + if (!is_null($sectionreturn)) { + $format->set_sectionnum($sectionreturn); } $renderer = $format->get_renderer($PAGE); diff --git a/course/format/classes/base.php b/course/format/classes/base.php index 556c2b856a6..3a64d6dd912 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -604,9 +604,21 @@ abstract class base { * Some formats has the hability to swith from one section to multiple sections per page. * * @param int $singlesection zero for all sections or a section number + * @deprecated Since 4.4. Use set_sectionnum instead. + * @todo MDL-80116 This will be deleted in Moodle 4.8. */ public function set_section_number(int $singlesection): void { - $this->singlesection = $singlesection; + + debugging( + 'The method core_courseformat\base::set_section_number() has been deprecated, please use set_sectionnum() instead.', + DEBUG_DEVELOPER + ); + + if ($singlesection === 0) { + // Convert zero to null, to guarantee all the sections are displayed. + $singlesection = null; + } + $this->set_sectionnum($singlesection); } /** @@ -652,8 +664,21 @@ abstract class base { * multiple sections. * * @return int zero for all sections or the sectin number + * @deprecated Since 4.4. Use get_sectionnum instead. + * @todo MDL-80116 This will be deleted in Moodle 4.8. */ public function get_section_number(): int { + + debugging( + 'The method core_courseformat\base::get_section_number() has been deprecated, please use get_sectionnum() instead.', + DEBUG_DEVELOPER + ); + + if ($this->singlesection === null) { + // Convert null to zero, to guarantee all the sections are displayed. + return 0; + } + return $this->singlesection; } @@ -847,7 +872,7 @@ abstract class base { ['sesskey' => sesskey(), $nonajaxaction => $cm->id] ); if (!is_null($this->get_sectionid())) { - $nonajaxurl->param('sr', $this->get_section_number()); + $nonajaxurl->param('sr', $this->get_sectionnum()); } return $nonajaxurl; } @@ -1882,8 +1907,8 @@ abstract class base { $section = $modinfo->get_section_info($section->section); } - if ($sr) { - $this->set_section_number($sr); + if (!is_null($sr)) { + $this->set_sectionnum($sr); } switch($action) { diff --git a/course/format/classes/output/local/content.php b/course/format/classes/output/local/content.php index b2986ee3b05..6cad5e8b58f 100644 --- a/course/format/classes/output/local/content.php +++ b/course/format/classes/output/local/content.php @@ -99,7 +99,7 @@ class content implements named_templatable, renderable { // The single section format has extra navigation. if ($this->format->get_sectionid()) { - $singlesectionnum = $this->format->get_section_number(); + $singlesectionnum = $this->format->get_sectionnum(); if (!$PAGE->theme->usescourseindex) { $sectionnavigation = new $this->sectionnavigationclass($format, $singlesectionnum); $data->sectionnavigation = $sectionnavigation->export_for_template($output); diff --git a/course/format/classes/output/local/content/addsection.php b/course/format/classes/output/local/content/addsection.php index 6309a3b5e43..a6df3d9a40e 100644 --- a/course/format/classes/output/local/content/addsection.php +++ b/course/format/classes/output/local/content/addsection.php @@ -153,7 +153,7 @@ class addsection implements named_templatable, renderable { $params = ['courseid' => $course->id, 'insertsection' => 0, 'sesskey' => sesskey()]; - $singlesection = $this->format->get_section_number(); + $singlesection = $this->format->get_sectionnum(); if ($singlesection) { $params['sectionreturn'] = $singlesection; } diff --git a/course/format/classes/output/local/content/bulkedittools.php b/course/format/classes/output/local/content/bulkedittools.php index 43263861500..b3e23da7a8c 100644 --- a/course/format/classes/output/local/content/bulkedittools.php +++ b/course/format/classes/output/local/content/bulkedittools.php @@ -159,7 +159,7 @@ class bulkedittools implements named_templatable, renderable { global $USER; $format = $this->format; $context = $format->get_context(); - $sectionreturn = $format->get_section_number(); + $sectionreturn = $format->get_sectionnum(); $user = $USER; $controls = []; diff --git a/course/format/classes/output/local/content/cm.php b/course/format/classes/output/local/content/cm.php index ab1e9390e6e..03473e53144 100644 --- a/course/format/classes/output/local/content/cm.php +++ b/course/format/classes/output/local/content/cm.php @@ -310,7 +310,7 @@ class cm implements named_templatable, renderable { if (!$this->format->show_editor($editcaps)) { return false; } - $returnsection = $this->format->get_section_number(); + $returnsection = $this->format->get_sectionnum(); // Edit actions. $controlmenu = new $this->controlmenuclass( $this->format, diff --git a/course/format/classes/output/local/content/cm/controlmenu.php b/course/format/classes/output/local/content/cm/controlmenu.php index b5a3a337a1c..01ca4404b00 100644 --- a/course/format/classes/output/local/content/cm/controlmenu.php +++ b/course/format/classes/output/local/content/cm/controlmenu.php @@ -161,7 +161,7 @@ class controlmenu implements named_templatable, renderable { protected function cm_control_items() { $format = $this->format; $mod = $this->mod; - $sectionreturn = $format->get_section_number(); + $sectionreturn = $format->get_sectionnum(); if (!empty($this->displayoptions['disableindentation']) || !$format->uses_indentation()) { $indent = -1; } else { diff --git a/course/format/classes/output/local/content/section.php b/course/format/classes/output/local/content/section.php index c320da8bccb..42853c555cf 100644 --- a/course/format/classes/output/local/content/section.php +++ b/course/format/classes/output/local/content/section.php @@ -142,7 +142,7 @@ class section implements named_templatable, renderable { $data = (object)[ 'num' => $section->section ?? '0', 'id' => $section->id, - 'sectionreturnid' => $format->get_section_number(), + 'sectionreturnid' => $format->get_sectionnum(), 'insertafter' => false, 'summary' => $summary->export_for_template($output), 'highlightedlabel' => $format->get_section_highlighted_name(), @@ -181,7 +181,7 @@ class section implements named_templatable, renderable { $headerdata = $header->export_for_template($output); // When a section is displayed alone the title goes over the section, not inside it. - if ($section->section != 0 && $section->section == $format->get_section_number()) { + if ($section->section != 0 && $section->section == $format->get_sectionnum()) { $data->singleheader = $headerdata; } else { $data->header = $headerdata; @@ -203,7 +203,7 @@ class section implements named_templatable, renderable { $format = $this->format; $showsummary = ($section->section != 0 && - $section->section != $format->get_section_number() && + $section->section != $format->get_sectionnum() && $format->get_course_display() == COURSE_DISPLAY_MULTIPAGE && !$format->show_editor() ); @@ -302,7 +302,7 @@ class section implements named_templatable, renderable { $data->cmcontrols = $output->course_section_add_cm_control( $course, $this->section->section, - $this->format->get_section_number() + $this->format->get_sectionnum() ); } return true; diff --git a/course/format/classes/output/local/content/section/controlmenu.php b/course/format/classes/output/local/content/section/controlmenu.php index d89060f260d..a446a779a8c 100644 --- a/course/format/classes/output/local/content/section/controlmenu.php +++ b/course/format/classes/output/local/content/section/controlmenu.php @@ -124,7 +124,7 @@ class controlmenu implements named_templatable, renderable { $format = $this->format; $section = $this->section; $course = $format->get_course(); - $sectionreturn = !is_null($format->get_sectionid()) ? $format->get_section_number() : null; + $sectionreturn = !is_null($format->get_sectionid()) ? $format->get_sectionnum() : null; $user = $USER; $usecomponents = $format->supports_components(); diff --git a/course/format/classes/output/local/content/section/header.php b/course/format/classes/output/local/content/section/header.php index b3009705e8b..7c938342936 100644 --- a/course/format/classes/output/local/content/section/header.php +++ b/course/format/classes/output/local/content/section/header.php @@ -114,7 +114,7 @@ class header implements named_templatable, renderable { $data->name = get_section_name($course, $section); $data->selecttext = $format->get_format_string('selectsection', $data->name); - if (!$format->get_section_number()) { + if (!$format->get_sectionnum()) { $data->sectionbulk = true; } diff --git a/course/format/lib.php b/course/format/lib.php index e9154c49039..2b0025f2513 100644 --- a/course/format/lib.php +++ b/course/format/lib.php @@ -131,7 +131,7 @@ class format_site extends course_format { * * @return int */ - public function get_section_number(): int { + public function get_sectionnum(): int { return 1; } } @@ -219,8 +219,8 @@ function core_courseformat_output_fragment_cmitem($args): string { } $format = course_get_format($course); - if (!empty($args['sr'])) { - $format->set_section_number($args['sr']); + if (!is_null($args['sr'])) { + $format->set_sectionnum($args['sr']); } $renderer = $format->get_renderer($PAGE); $section = $cm->get_section_info(); @@ -246,8 +246,8 @@ function core_courseformat_output_fragment_section($args): string { } $format = course_get_format($course); - if (!empty($args['sr'])) { - $format->set_section_number($args['sr']); + if (!is_null($args['sr'])) { + $format->set_sectionnum($args['sr']); } $modinfo = $format->get_modinfo(); diff --git a/course/format/topics/classes/output/courseformat/content/section.php b/course/format/topics/classes/output/courseformat/content/section.php index c4a8ac1a23b..ca41d215527 100644 --- a/course/format/topics/classes/output/courseformat/content/section.php +++ b/course/format/topics/classes/output/courseformat/content/section.php @@ -45,7 +45,7 @@ class section extends section_base { $data = parent::export_for_template($output); - if (!$this->format->get_section_number()) { + if (!$this->format->get_sectionnum()) { $addsectionclass = $format->get_output_classname('content\\addsection'); $addsection = new $addsectionclass($format); $data->numsections = $addsection->export_for_template($output); diff --git a/course/format/topics/classes/output/courseformat/content/section/controlmenu.php b/course/format/topics/classes/output/courseformat/content/section/controlmenu.php index d554e84a69e..263247ffc0a 100644 --- a/course/format/topics/classes/output/courseformat/content/section/controlmenu.php +++ b/course/format/topics/classes/output/courseformat/content/section/controlmenu.php @@ -90,7 +90,7 @@ class controlmenu extends controlmenu_base { $format = $this->format; $section = $this->section; $course = $format->get_course(); - $sectionreturn = $format->get_section_number(); + $sectionreturn = $format->get_sectionnum(); if ($sectionreturn) { $url = course_get_url($course, $section->section); diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 03cef340939..9a7f9d55b6b 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -52,8 +52,8 @@ course_create_sections_if_missing($course, 0); $renderer = $PAGE->get_renderer('format_topics'); -if (!empty($displaysection)) { - $format->set_section_number($displaysection); +if (!is_null($displaysection)) { + $format->set_sectionnum($displaysection); } $outputclass = $format->get_output_classname('content'); $widget = new $outputclass($format); diff --git a/course/format/upgrade.txt b/course/format/upgrade.txt index 121afc8c2d3..873c1107812 100644 --- a/course/format/upgrade.txt +++ b/course/format/upgrade.txt @@ -47,6 +47,9 @@ always linked because a new page, section.php, has been created to display any s - course/format/topics/renderer.php - course/format/weeks/renderer.php * New core_courseformat\sectiondelegate class. The class can be extended by plugins to take control of a course section. +* The methods core_courseformat\base::set_section_number() and core_courseformat\base:: get_section_number() have been deprecated +and replaced by core_courseformat\base::set_sectionnum() and core_courseformat\base::get_sectionnum(). The new methods use the null +value when all the sections must be displayed (instead of 0). That way, section 0 (General), can be displayed on a single page too. === 4.3 === * New core_courseformat\output\activitybadge class that can be extended by any module to display content near the activity name. diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index 8a603c880d0..523ccbc638b 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -44,8 +44,8 @@ course_create_sections_if_missing($format->get_course(), 0); $renderer = $PAGE->get_renderer('format_weeks'); -if (!empty($displaysection)) { - $format->set_section_number($displaysection); +if (!is_null($displaysection)) { + $format->set_sectionnum($displaysection); } $outputclass = $format->get_output_classname('content'); -- 2.11.4.GIT