From 8596d3cd7c9ffa64a9e678287ce614e8a96c9931 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Fri, 5 Jul 2024 10:14:51 +0200 Subject: [PATCH] MDL-82146 report_log: Add subsections to activity filter --- .upgradenotes/MDL-82146-2024071006310652.yml | 7 ++ report/log/classes/renderable.php | 75 ++++++++++++++++---- report/log/classes/renderer.php | 4 +- theme/boost/scss/moodle/reports.scss | 10 +++ theme/boost/style/moodle.css | 5 ++ theme/classic/style/moodle.css | 5 ++ 6 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 .upgradenotes/MDL-82146-2024071006310652.yml diff --git a/.upgradenotes/MDL-82146-2024071006310652.yml b/.upgradenotes/MDL-82146-2024071006310652.yml new file mode 100644 index 00000000000..1f6ad98bcab --- /dev/null +++ b/.upgradenotes/MDL-82146-2024071006310652.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-82146 +notes: + report_log: + - message: >- + get_activities_list() function returns also an array of disabled + elements, apart from the array of activities. + type: improved diff --git a/report/log/classes/renderable.php b/report/log/classes/renderable.php index 34ce7dfb60f..a8a1e51490f 100644 --- a/report/log/classes/renderable.php +++ b/report/log/classes/renderable.php @@ -196,49 +196,100 @@ class report_log_renderable implements renderable { * @return array list of activities. */ public function get_activities_list() { - $activities = array(); + $activities = []; + $disabled = []; // For site just return site errors option. $sitecontext = context_system::instance(); if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) { $activities["site_errors"] = get_string("siteerrors"); - return $activities; + return [$activities, $disabled]; } $modinfo = get_fast_modinfo($this->course); + $delegatedsections = $modinfo->get_sections_delegated_by_cm(); + if (!empty($modinfo->cms)) { $section = 0; $thissection = array(); foreach ($modinfo->cms as $cm) { - // Exclude activities that aren't visible or have no view link (e.g. label). Account for folders displayed inline. - if (!$cm->uservisible || (!$cm->has_view() && strcmp($cm->modname, 'folder') !== 0)) { + if (!$modname = $this->get_activity_name($cm)) { continue; } + if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) { + $sectioninfo = $modinfo->get_section_info($cm->sectionnum); + + // Don't show subsections here. We are showing them in the corresponding module. + if ($sectioninfo->is_delegated()) { + continue; + } + $activities[] = $thissection; $thissection = array(); } $section = $cm->sectionnum; - $modname = strip_tags($cm->get_formatted_name()); - if (core_text::strlen($modname) > 55) { - $modname = core_text::substr($modname, 0, 50)."..."; - } - if (!$cm->visible) { - $modname = "(".$modname.")"; - } $key = get_section_name($this->course, $cm->sectionnum); if (!isset($thissection[$key])) { - $thissection[$key] = array(); + $thissection[$key] = []; } $thissection[$key][$cm->id] = $modname; + // Check if the module is delegating a section. + if (array_key_exists($cm->id, $delegatedsections)) { + $delegated = $delegatedsections[$cm->id]; + $modules = (empty($delegated->sequence)) ? [] : explode(',', $delegated->sequence); + $thissection[$key] = $thissection[$key] + $this->get_delegated_section_activities($modinfo, $modules); + $disabled[] = $cm->id; + } } if (!empty($thissection)) { $activities[] = $thissection; } } + return [$activities, $disabled]; + } + + /** + * Helper function to return list of activities in a delegated section. + * + * @param course_modinfo $modinfo + * @param array $cms List of cm ids in the section. + * @return array list of activities. + */ + protected function get_delegated_section_activities(course_modinfo $modinfo, array $cmids): array { + $activities = []; + $indenter = '    '; + foreach ($cmids as $cmid) { + $cm = $modinfo->cms[$cmid]; + if ($modname = $this->get_activity_name($cm)) { + $activities[$cmid] = $indenter.$modname; + } + } return $activities; } + /** + * Helper function to return the name to show in the dropdown. + * + * @param cm_info $cm + * @return string The name. + */ + private function get_activity_name(cm_info $cm): string { + // Exclude activities that aren't visible or have no view link (e.g. label). Account for folders displayed inline. + if (!$cm->uservisible || (!$cm->has_view() && strcmp($cm->modname, 'folder') !== 0)) { + return ''; + } + $modname = strip_tags($cm->get_formatted_name()); + if (core_text::strlen($modname) > 55) { + $modname = core_text::substr($modname, 0, 50)."..."; + } + if (!$cm->visible) { + $modname = "(".$modname.")"; + } + + return $modname; + } + /** * Helper function to get selected group. * diff --git a/report/log/classes/renderer.php b/report/log/classes/renderer.php index 4029e2e3899..e6ca1829a79 100644 --- a/report/log/classes/renderer.php +++ b/report/log/classes/renderer.php @@ -161,10 +161,10 @@ class report_log_renderer extends plugin_renderer_base { ['class' => 'mr-2 mb-2']); // Add activity selector. - $activities = $reportlog->get_activities_list(); + [$activities, $disabled] = $reportlog->get_activities_list(); echo html_writer::label(get_string('activities'), 'menumodid', false, array('class' => 'accesshide')); echo html_writer::select($activities, "modid", $reportlog->modid, get_string("allactivities"), - ['class' => 'mr-2 mb-2']); + ['class' => 'mr-2 mb-2'], $disabled); // Add actions selector. echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide')); diff --git a/theme/boost/scss/moodle/reports.scss b/theme/boost/scss/moodle/reports.scss index cad9c3e8014..df71720ccee 100644 --- a/theme/boost/scss/moodle/reports.scss +++ b/theme/boost/scss/moodle/reports.scss @@ -34,3 +34,13 @@ padding-left: $spacer * 3.5; } } + +#page-report-log-index #menumodid option:disabled { + // Browsers do not consider the color of a disabled option + // if it is the same as the non-disabled options. + // Since we are using disabled elements to create a sense of hierarchy, + // we intentionally use a slightly different color for them. + // We do this because HTML still does not allow nested optgroups in select elements. + color: lighten($custom-select-color, 1%); + font-weight: bolder; +} diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index bba582f17a0..342844fe630 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -35080,6 +35080,11 @@ img.userpicture { padding-left: 3.5rem; } +#page-report-log-index #menumodid option:disabled { + color: #4b535a; + font-weight: bolder; +} + .path-backup .mform { /* These are long labels with checkboxes on the right. */ } diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index abf1af20e4a..0022617f6cd 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -35080,6 +35080,11 @@ img.userpicture { padding-left: 3.5rem; } +#page-report-log-index #menumodid option:disabled { + color: #4b535a; + font-weight: bolder; +} + .path-backup .mform { /* These are long labels with checkboxes on the right. */ }