From 13814364c88acd45acc709cec8f516282afcf875 Mon Sep 17 00:00:00 2001 From: James C <5689414+james-cnz@users.noreply.github.com> Date: Sat, 27 Sep 2025 14:01:11 +1200 Subject: [PATCH] Code style --- .../restore_format_onetopic_plugin.class.php | 9 +- changenumsections.php | 10 +- classes/courseformat/stateactions.php | 1 - classes/footer.php | 2 - classes/header.php | 65 +++++----- classes/local/clilib.php | 4 - classes/local/formelement_background.php | 11 +- classes/local/formelement_tabstyles.php | 12 +- .../hooks/output/before_http_headers.php | 1 - classes/output/courseformat/content.php | 11 +- .../output/courseformat/content/section.php | 1 - .../courseformat/content/section/cmlist.php | 10 +- .../content/section/controlmenu.php | 4 +- .../courseformat/content/section/summary.php | 30 +++-- .../content/sectionnavigation.php | 1 - .../courseformat/content/sectionselector.php | 1 - classes/output/renderer.php | 7 +- classes/singletab.php | 12 +- classes/tabs.php | 4 - classes/tabstyles.php | 10 +- cli.php | 5 +- format.php | 4 +- lang/en/deprecated.txt | 2 +- lib.php | 114 ++++++++++-------- migratestyles.php | 3 - settings.php | 111 +++++++++++------ styles.php | 19 ++- 27 files changed, 246 insertions(+), 218 deletions(-) diff --git a/backup/moodle2/restore_format_onetopic_plugin.class.php b/backup/moodle2/restore_format_onetopic_plugin.class.php index 3cc63a5..a469af1 100644 --- a/backup/moodle2/restore_format_onetopic_plugin.class.php +++ b/backup/moodle2/restore_format_onetopic_plugin.class.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot. '/course/format/topics/backup/moodle2/restore_format_topics_plugin.class.php'); +require_once($CFG->dirroot . '/course/format/topics/backup/moodle2/restore_format_topics_plugin.class.php'); /** * Specialised restore for format_onetopic @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_format_onetopic_plugin extends restore_format_topics_plugin { - /** * Executed after course restore is complete * @@ -69,8 +68,10 @@ public function after_restore_course() { if ($this->step->get_task()->get_setting_value($key . '_included')) { $sectionnum = (int)$section->title; if ($sectionnum > $numsections && $sectionnum > $this->originalnumsections) { - $DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?", - [$this->step->get_task()->get_courseid(), $sectionnum]); + $DB->execute( + "UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?", + [$this->step->get_task()->get_courseid(), $sectionnum] + ); } } } diff --git a/changenumsections.php b/changenumsections.php index 6021845..a4dea17 100644 --- a/changenumsections.php +++ b/changenumsections.php @@ -87,14 +87,13 @@ if (!$returnurl) { $returnurl = course_get_url($course); } - } else if (course_get_format($course)->uses_sections() && $insertsection !== null) { if ($insertsection) { // Inserting sections at any position except in the very end requires capability to move sections. require_capability('moodle/course:movesections', context_course::instance($course->id)); } $sections = []; - for ($i = 0; $i < max($numsections, 1); $i ++) { + for ($i = 0; $i < max($numsections, 1); $i++) { $section = course_create_section($course, $insertsection); $sections[] = $section; @@ -104,8 +103,11 @@ } } if (!$returnurl) { - $returnurl = course_get_url($course, $sections[0]->section, - ($sectionreturn !== null) ? ['sr' => $sectionreturn] : []); + $returnurl = course_get_url( + $course, + $sections[0]->section, + ($sectionreturn !== null) ? ['sr' => $sectionreturn] : [] + ); } } diff --git a/classes/courseformat/stateactions.php b/classes/courseformat/stateactions.php index a30e444..b374645 100644 --- a/classes/courseformat/stateactions.php +++ b/classes/courseformat/stateactions.php @@ -26,5 +26,4 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class stateactions extends stateactions_format_topics { - } diff --git a/classes/footer.php b/classes/footer.php index 902a0d1..bcb6347 100644 --- a/classes/footer.php +++ b/classes/footer.php @@ -36,7 +36,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class footer implements \renderable, \templatable { - /** * @var \format_onetopic */ @@ -72,5 +71,4 @@ public function export_for_template(\renderer_base $output) { return $data; } - } diff --git a/classes/header.php b/classes/header.php index 3c5ed71..0fa96ea 100644 --- a/classes/header.php +++ b/classes/header.php @@ -36,7 +36,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class header implements \renderable, \templatable { - /** * @var \format_onetopic */ @@ -73,8 +72,10 @@ public function export_for_template(\renderer_base $output) { $secondtabslist = null; $tabscssstyles = ''; $activetab = null; - if ($course->tabsview != \format_onetopic::TABSVIEW_COURSEINDEX && - ($format->show_editor() || !$course->hidetabsbar)) { + if ( + $course->tabsview != \format_onetopic::TABSVIEW_COURSEINDEX && + ($format->show_editor() || !$course->hidetabsbar) + ) { $tabs = $this->get_tabs($format->get_modinfo(), $output); $tabslist = $tabs->get_list(); $secondtabslist = $tabs->get_secondlist($firstsection ? $currentsection - 1 : $currentsection); @@ -165,7 +166,6 @@ public function export_for_template(\renderer_base $output) { // General section if non-empty and course_display is multiple. if ($course->realcoursedisplay == COURSE_DISPLAY_MULTIPAGE) { - // Load the section 0 and export data for template. $modinfo = $format->get_modinfo(); $section0 = $modinfo->get_section_info(0); @@ -174,7 +174,6 @@ public function export_for_template(\renderer_base $output) { $sectionoutput = new \format_onetopic\output\renderer($PAGE, null); $initialsection = $section->export_for_template($sectionoutput); - } $data->initialsection = $initialsection; @@ -255,14 +254,13 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for $title = $sectionname; if (!$thissection->visible || !$thissection->available) { - $title .= ': '. get_string('hiddenfromstudents'); + $title .= ': ' . get_string('hiddenfromstudents'); } $tabicons = []; $customstyles = ''; $level = 0; if (is_array($formatoptions)) { - if ($enablecustomstyles) { if (!empty($formatoptions['fontcolor'])) { $customstyles .= 'color: ' . $formatoptions['fontcolor'] . '; '; @@ -278,7 +276,6 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for $tabstyles = !empty($formatoptions['tabstyles']) ? @json_decode($formatoptions['tabstyles']) : null; if (is_object($tabstyles)) { - $orderedtabs = new \stdClass(); foreach ($precedence as $type) { if (property_exists($tabstyles, $type)) { @@ -291,37 +288,36 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for $cssid = '#onetabid-' . $thissection->id . ''; $withunits = ['font-size', 'line-height', 'margin', 'padding', 'border-width', 'border-radius']; foreach ($orderedtabs as $type => $styles) { - $important = false; switch ($type) { case 'active': $onecss .= '#tabs-tree-start .nav-item' . $cssid . ' a.nav-link.active'; $important = true; - break; + break; case 'parent': $onecss .= '#tabs-tree-start .nav-item.haschilds' . $cssid . ' a.nav-link'; - break; + break; case 'highlighted': $onecss .= '#tabs-tree-start .nav-item.marker' . $cssid . ' a.nav-link'; $important = true; - break; + break; case 'disabled': $onecss .= '#tabs-tree-start .nav-item.disabled' . $cssid . ' a.nav-link'; $important = true; - break; + break; case 'hover': $onecss .= '#tabs-tree-start .nav-item' . $cssid . ' a.nav-link:hover,'; $onecss .= '#tabs-tree-start .onetopic-tab-body' . $cssparentid . ' .nav-item.subtopic a.nav-link:hover'; - break; + break; case 'childs': $onecss .= '#tabs-tree-start .onetopic-tab-body' . $cssparentid . ' .nav-item.subtopic a.nav-link'; - break; + break; case 'childindex': $onecss .= '#tabs-tree-start .onetopic-tab-body' . $cssparentid . ' .nav-tabs' . ' .nav-item.subtopic.tab_initial a.nav-link'; - break; + break; default: $onecss .= '#tabs-tree-start .nav-item' . $cssid . ' a.nav-link,'; $onecss .= '#tabs-tree-start .onetopic-tab-body' . $cssparentid . ' a.nav-link'; @@ -332,10 +328,8 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for // Check if exist units for some rules. foreach ($styles as $key => $value) { - // Check if the key start with the units prefix. if (strpos($key, 'unit-') === 0) { - // Remove the prefix. $ownerkey = str_replace('unit-', '', $key); $units[$ownerkey] = $value; @@ -347,7 +341,6 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for } foreach ($styles as $key => $value) { - // If exist a unit for the rule, apply it. if (isset($units[$key])) { $value = $value . $units[$key]; @@ -369,7 +362,6 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for // Clean the CSS for html tags. $csstabstyles .= preg_replace('/<[^>]*>/', '', $onecss); } - } if (isset($formatoptions['level']) && $localsection > $firstsection) { @@ -408,8 +400,15 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for } } - $newtab = new \format_onetopic\singletab($localsection, $sectionname, $url, $title, - $availablemessage, $customstyles, $specialclass); + $newtab = new \format_onetopic\singletab( + $localsection, + $sectionname, + $url, + $title, + $availablemessage, + $customstyles, + $specialclass + ); $newtab->active = !$inactivetab; $newtab->id = $thissection->id; $newtab->cssstyles = $csstabstyles; @@ -420,21 +419,21 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for } if (is_array($formatoptions) && isset($formatoptions['level'])) { - if ($formatoptions['level'] == 0 || $parenttab == null) { $tabs->add($newtab); $parenttab = $newtab; } else { - if (!$parenttab->has_childs()) { $specialclasstmp = str_replace('tab_level_0', 'tab_level_1', $parenttab->specialclass); - $indextab = new \format_onetopic\singletab($parenttab->section, - $parenttab->content, - $parenttab->link, - $parenttab->title, - $parenttab->availablemessage, - (empty($parenttab->cssstyles) ? $parenttab->customstyles : ''), - $specialclasstmp); + $indextab = new \format_onetopic\singletab( + $parenttab->section, + $parenttab->content, + $parenttab->link, + $parenttab->title, + $parenttab->availablemessage, + (empty($parenttab->cssstyles) ? $parenttab->customstyles : ''), + $specialclasstmp + ); $prevsectionindex = $localsection - 1; do { @@ -477,12 +476,10 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for } if ($this->format->show_editor()) { - $maxsections = $this->format->get_max_sections(); // Only can add sections if it does not exceed the maximum amount. if (count($sections) < $maxsections) { - $straddsection = get_string('increasesections', 'format_onetopic'); $icon = $output->pix_icon('t/switch_plus', s($straddsection)); $insertposition = $displaysection + 1; @@ -516,11 +513,9 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for $url = new \moodle_url('/course/format/onetopic/changenumsections.php', $paramstotabs); $newtab = new \format_onetopic\singletab('add', $icon, $url, s($straddsection)); $tabs->add($newtab); - } } return $tabs; } - } diff --git a/classes/local/clilib.php b/classes/local/clilib.php index 8b2c366..653276e 100644 --- a/classes/local/clilib.php +++ b/classes/local/clilib.php @@ -24,7 +24,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class clilib { - /** * List styles that need to be migrated. * @@ -65,7 +64,6 @@ public static function mstyles_list($limit = 100) { $k = 0; foreach ($rs as $record) { - if (isset($stylesnew[$record->sectionid])) { // This section already has new styles, skip it. continue; @@ -76,7 +74,6 @@ public static function mstyles_list($limit = 100) { "Style: {$record->stylename}, Value: {$record->stylevalue}\n"; } $rs->close(); - } /** @@ -138,7 +135,6 @@ public static function mstyles_migrate($limit = 100) { $k = 0; foreach ($sections as $sectionid => $section) { - if (CLI_VERBOSE) { echo "Migrating style for Course ID: {$section->courseid}, Section ID: {$sectionid}\n"; } diff --git a/classes/local/formelement_background.php b/classes/local/formelement_background.php index b3cb215..6c74c7c 100644 --- a/classes/local/formelement_background.php +++ b/classes/local/formelement_background.php @@ -80,10 +80,11 @@ public function to_html() { $loadedcounter++; $colorpickerid = 'colorpicker' . $loadedcounter; - $cp = new \admin_setting_configcolourpicker($colorpickerid, - get_string('colorpicker', 'format_onetopic'), - get_string('colorpicker_help', 'format_onetopic'), - '', + $cp = new \admin_setting_configcolourpicker( + $colorpickerid, + get_string('colorpicker', 'format_onetopic'), + get_string('colorpicker_help', 'format_onetopic'), + '', ); $html = parent::toHtml(); @@ -104,7 +105,6 @@ public function to_html() { $PAGE->requires->js_call_amd('format_onetopic/onetopicbackground', 'init', [$this->getAttribute('id')]); return $html; - } /** @@ -148,5 +148,4 @@ public function validateSubmitValue($value) { return; } - } diff --git a/classes/local/formelement_tabstyles.php b/classes/local/formelement_tabstyles.php index c6c3fd8..eaceaec 100644 --- a/classes/local/formelement_tabstyles.php +++ b/classes/local/formelement_tabstyles.php @@ -36,7 +36,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class format_onetopic_tabstyles_form_element extends MoodleQuickForm_textarea { - /** * Constructor * @@ -134,9 +133,12 @@ public function to_html() { $tabslist = $tabs->get_list(); $secondtabslist = $tabs->get_secondlist(); - $cp = new \admin_setting_configcolourpicker('colorpicker', - get_string('colorpicker', 'format_onetopic'), - get_string('colorpicker_help', 'format_onetopic'), ''); + $cp = new \admin_setting_configcolourpicker( + 'colorpicker', + get_string('colorpicker', 'format_onetopic'), + get_string('colorpicker_help', 'format_onetopic'), + '' + ); $csssizeoptions = range(0, 100); $csssizeoptions[0] = ''; @@ -184,7 +186,6 @@ public function to_html() { $PAGE->requires->js_call_amd('format_onetopic/tabstyles', 'init'); return $element; - } /** @@ -223,5 +224,4 @@ public function validateSubmitValue($value) { return; } - } diff --git a/classes/local/hooks/output/before_http_headers.php b/classes/local/hooks/output/before_http_headers.php index 6fe0885..ca4cf75 100644 --- a/classes/local/hooks/output/before_http_headers.php +++ b/classes/local/hooks/output/before_http_headers.php @@ -24,7 +24,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class before_http_headers { - /** * Moodle native lib/navigationlib.php calls this hook allowing us to override UI. * diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index a8a734e..cfeca8a 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class content extends content_base { - /** * @var bool Topic format has add section after each topic. * @@ -82,16 +81,16 @@ public function export_for_template(\renderer_base $output) { // The current section format has extra navigation. if ($currentsection || $currentsection === 0) { - $usessectionsnavigation = isset($course->usessectionsnavigation) ? $course->usessectionsnavigation : null; if (empty($usessectionsnavigation)) { $usessectionsnavigation = get_config('format_onetopic', 'defaultsectionsnavigation'); } if ($usessectionsnavigation != \format_onetopic::SECTIONSNAVIGATION_NOT) { - if ($usessectionsnavigation != \format_onetopic::SECTIONSNAVIGATION_SUPPORT || - !$PAGE->theme->usescourseindex) { - + if ( + $usessectionsnavigation != \format_onetopic::SECTIONSNAVIGATION_SUPPORT || + !$PAGE->theme->usescourseindex + ) { $sectionnavigation = new $this->sectionnavigationclass($format, $currentsection); // Not show navigation in top section if is not both. @@ -107,7 +106,6 @@ public function export_for_template(\renderer_base $output) { } } } - } $data->singlesection = array_shift($data->sections); @@ -194,5 +192,4 @@ protected function get_sections_to_display(course_modinfo $modinfo): array { return $sections; } - } diff --git a/classes/output/courseformat/content/section.php b/classes/output/courseformat/content/section.php index 65c8f5e..6fc9785 100644 --- a/classes/output/courseformat/content/section.php +++ b/classes/output/courseformat/content/section.php @@ -36,7 +36,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class section extends section_base { - /** @var course_format the course format */ protected $format; diff --git a/classes/output/courseformat/content/section/cmlist.php b/classes/output/courseformat/content/section/cmlist.php index 24e3104..b82e1c7 100644 --- a/classes/output/courseformat/content/section/cmlist.php +++ b/classes/output/courseformat/content/section/cmlist.php @@ -41,7 +41,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cmlist extends cmlist_base { - /** * Export this data so it can be used as the context for a mustache template. * @@ -83,10 +82,11 @@ public function export_for_template(\renderer_base $output): stdClass { } foreach ($modinfo->sections[$section->section] as $modnumber) { - - if (!$format->show_editor() && - $course->templatetopic == \format_onetopic::TEMPLATETOPIC_LIST && - in_array($modnumber, $format->tplcmsused)) { + if ( + !$format->show_editor() && + $course->templatetopic == \format_onetopic::TEMPLATETOPIC_LIST && + in_array($modnumber, $format->tplcmsused) + ) { continue; } diff --git a/classes/output/courseformat/content/section/controlmenu.php b/classes/output/courseformat/content/section/controlmenu.php index b7ab51e..c7fa744 100644 --- a/classes/output/courseformat/content/section/controlmenu.php +++ b/classes/output/courseformat/content/section/controlmenu.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class controlmenu extends controlmenu_format_topics { - /** @var course_format the course format class */ protected $format; @@ -120,7 +119,8 @@ public function section_control_items() { // Create the permalink according to the Onetopic format. if (array_key_exists("permalink", $parentcontrols)) { - $sectionlink = new url('/course/view.php', + $sectionlink = new url( + '/course/view.php', [ 'id' => $course->id, 'sectionid' => $section->id, diff --git a/classes/output/courseformat/content/section/summary.php b/classes/output/courseformat/content/section/summary.php index 5ad0625..b61717e 100644 --- a/classes/output/courseformat/content/section/summary.php +++ b/classes/output/courseformat/content/section/summary.php @@ -40,7 +40,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class summary extends summary_base { - use courseformat_named_templatable; /** @var course_format the course format class */ @@ -106,8 +105,14 @@ public function format_summary_text(): string { $summarytext = $this->replace_resources($section); } - $summarytext = file_rewrite_pluginfile_urls($summarytext, 'pluginfile.php', - $context->id, 'course', 'section', $section->id); + $summarytext = file_rewrite_pluginfile_urls( + $summarytext, + 'pluginfile.php', + $context->id, + 'course', + 'section', + $section->id + ); $options = new stdClass(); $options->noclean = true; @@ -161,7 +166,6 @@ private function replace_resources(section_info $section) { $completioninfo = new \completion_info($course); foreach ($sectionmods as $modnumber) { - if (empty($modinfo->cms[$modnumber])) { continue; } @@ -191,9 +195,11 @@ private function replace_resources(section_info $section) { false; $cmdata->showinlinehelp = false; - if ($cmdata->hascompletion - || (isset($cmdata->hasdates) && $cmdata->hasdates) - || $hasavailability) { + if ( + $cmdata->hascompletion + || (isset($cmdata->hasdates) && $cmdata->hasdates) + || $hasavailability + ) { $cmdata->showinlinehelp = true; } @@ -206,8 +212,10 @@ private function replace_resources(section_info $section) { $template = 'format_onetopic/courseformat/content/cminline'; if ($completioninfo->is_enabled($mod) !== COMPLETION_TRACKING_NONE) { - $completion = $DB->get_record('course_modules_completion', - ['coursemoduleid' => $mod->id, 'userid' => $USER->id, 'completionstate' => 1]); + $completion = $DB->get_record( + 'course_modules_completion', + ['coursemoduleid' => $mod->id, 'userid' => $USER->id, 'completionstate' => 1] + ); $template = 'format_onetopic/courseformat/content/cminlinecompletion'; @@ -225,7 +233,6 @@ private function replace_resources(section_info $section) { $cmdata->completedclass = $completedclass; $cmdata->showcompletionconditions = $showcompletionconditions; - } $renderer = $this->format->get_renderer($PAGE); @@ -247,12 +254,10 @@ private function replace_resources(section_info $section) { } $summary = $newsummary; - } } return $summary; - } /** @@ -270,7 +275,6 @@ public function replace_tag_in_expresion($match) { $text = strip_tags($term); if (strpos($text, ':') > -1) { - $pattern = '/([^:])+:/i'; $text = preg_replace($pattern, '', $text); diff --git a/classes/output/courseformat/content/sectionnavigation.php b/classes/output/courseformat/content/sectionnavigation.php index 2b67729..9f668f2 100644 --- a/classes/output/courseformat/content/sectionnavigation.php +++ b/classes/output/courseformat/content/sectionnavigation.php @@ -40,7 +40,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class sectionnavigation extends sectionnavigation_base { - /** @var stdClass the calculated data to prevent calculations when rendered several times */ protected $data = null; diff --git a/classes/output/courseformat/content/sectionselector.php b/classes/output/courseformat/content/sectionselector.php index 126ca24..d466e86 100644 --- a/classes/output/courseformat/content/sectionselector.php +++ b/classes/output/courseformat/content/sectionselector.php @@ -40,7 +40,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class sectionselector extends sectionselector_base { - /** * Export this data so it can be used as the context for a mustache template. * diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 46a53b9..f05d1aa 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -27,7 +27,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class renderer extends section_renderer { - /** * Constructor method, calls the parent constructor. * @@ -69,8 +68,10 @@ public function render(\renderable $widget) { $specialrenderers = '/^(?' . $corepath . '|' . $pluginpath . ')\/(?