MDL-82146 report_log: Add subsections to activity filter

This commit is contained in:
Amaia Anabitarte 2024-07-05 10:14:51 +02:00
parent ec050bbee7
commit 8596d3cd7c
6 changed files with 92 additions and 14 deletions

View File

@ -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

View File

@ -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 = '&nbsp;&nbsp;&nbsp;&nbsp;';
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.
*

View File

@ -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'));

View File

@ -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;
}

View File

@ -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. */
}

View File

@ -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. */
}