mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-82146 report_log: Add subsections to activity filter
This commit is contained in:
parent
ec050bbee7
commit
8596d3cd7c
7
.upgradenotes/MDL-82146-2024071006310652.yml
Normal file
7
.upgradenotes/MDL-82146-2024071006310652.yml
Normal 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
|
@ -196,49 +196,100 @@ class report_log_renderable implements renderable {
|
|||||||
* @return array list of activities.
|
* @return array list of activities.
|
||||||
*/
|
*/
|
||||||
public function get_activities_list() {
|
public function get_activities_list() {
|
||||||
$activities = array();
|
$activities = [];
|
||||||
|
$disabled = [];
|
||||||
|
|
||||||
// For site just return site errors option.
|
// For site just return site errors option.
|
||||||
$sitecontext = context_system::instance();
|
$sitecontext = context_system::instance();
|
||||||
if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) {
|
if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) {
|
||||||
$activities["site_errors"] = get_string("siteerrors");
|
$activities["site_errors"] = get_string("siteerrors");
|
||||||
return $activities;
|
return [$activities, $disabled];
|
||||||
}
|
}
|
||||||
|
|
||||||
$modinfo = get_fast_modinfo($this->course);
|
$modinfo = get_fast_modinfo($this->course);
|
||||||
|
$delegatedsections = $modinfo->get_sections_delegated_by_cm();
|
||||||
|
|
||||||
if (!empty($modinfo->cms)) {
|
if (!empty($modinfo->cms)) {
|
||||||
$section = 0;
|
$section = 0;
|
||||||
$thissection = array();
|
$thissection = array();
|
||||||
foreach ($modinfo->cms as $cm) {
|
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 (!$modname = $this->get_activity_name($cm)) {
|
||||||
if (!$cm->uservisible || (!$cm->has_view() && strcmp($cm->modname, 'folder') !== 0)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) {
|
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;
|
$activities[] = $thissection;
|
||||||
$thissection = array();
|
$thissection = array();
|
||||||
}
|
}
|
||||||
$section = $cm->sectionnum;
|
$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);
|
$key = get_section_name($this->course, $cm->sectionnum);
|
||||||
if (!isset($thissection[$key])) {
|
if (!isset($thissection[$key])) {
|
||||||
$thissection[$key] = array();
|
$thissection[$key] = [];
|
||||||
}
|
}
|
||||||
$thissection[$key][$cm->id] = $modname;
|
$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)) {
|
if (!empty($thissection)) {
|
||||||
$activities[] = $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;
|
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.
|
* Helper function to get selected group.
|
||||||
*
|
*
|
||||||
|
@ -161,10 +161,10 @@ class report_log_renderer extends plugin_renderer_base {
|
|||||||
['class' => 'mr-2 mb-2']);
|
['class' => 'mr-2 mb-2']);
|
||||||
|
|
||||||
// Add activity selector.
|
// 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::label(get_string('activities'), 'menumodid', false, array('class' => 'accesshide'));
|
||||||
echo html_writer::select($activities, "modid", $reportlog->modid, get_string("allactivities"),
|
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.
|
// Add actions selector.
|
||||||
echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide'));
|
echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide'));
|
||||||
|
@ -34,3 +34,13 @@
|
|||||||
padding-left: $spacer * 3.5;
|
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;
|
||||||
|
}
|
||||||
|
@ -35080,6 +35080,11 @@ img.userpicture {
|
|||||||
padding-left: 3.5rem;
|
padding-left: 3.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#page-report-log-index #menumodid option:disabled {
|
||||||
|
color: #4b535a;
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
|
||||||
.path-backup .mform {
|
.path-backup .mform {
|
||||||
/* These are long labels with checkboxes on the right. */
|
/* These are long labels with checkboxes on the right. */
|
||||||
}
|
}
|
||||||
|
@ -35080,6 +35080,11 @@ img.userpicture {
|
|||||||
padding-left: 3.5rem;
|
padding-left: 3.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#page-report-log-index #menumodid option:disabled {
|
||||||
|
color: #4b535a;
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
|
||||||
.path-backup .mform {
|
.path-backup .mform {
|
||||||
/* These are long labels with checkboxes on the right. */
|
/* These are long labels with checkboxes on the right. */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user