MDL-82847 report_log: Add subsections to activities log

This commit is contained in:
Amaia Anabitarte 2024-08-30 11:12:16 +02:00
parent 1938c438ea
commit e9c0789e69
2 changed files with 49 additions and 4 deletions

View File

@ -93,6 +93,9 @@ class report_log_renderable implements renderable {
/** @var table_log table log which will be used for rendering logs */
public $tablelog;
/** @var array Index of delegated sections (indexed by component and itemid) */
protected $delegatedbycm;
/**
* @var array group ids
* @deprecated since Moodle 4.4 - please do not use this public property
@ -207,7 +210,9 @@ class report_log_renderable implements renderable {
}
$modinfo = get_fast_modinfo($this->course);
$delegatedsections = $modinfo->get_sections_delegated_by_cm();
if (!$this->delegatedbycm) {
$this->delegatedbycm = $modinfo->get_sections_delegated_by_cm();
}
if (!empty($modinfo->cms)) {
$section = 0;
@ -235,8 +240,8 @@ class report_log_renderable implements renderable {
}
$thissection[$key][$cm->id] = $modname;
// Check if the module is delegating a section.
if (array_key_exists($cm->id, $delegatedsections)) {
$delegated = $delegatedsections[$cm->id];
if (array_key_exists($cm->id, $this->delegatedbycm)) {
$delegated = $this->delegatedbycm[$cm->id];
$modules = (empty($delegated->sequence)) ? [] : explode(',', $delegated->sequence);
$thissection[$key] = $thissection[$key] + $this->get_delegated_section_activities($modinfo, $modules);
$disabled[] = $cm->id;
@ -276,7 +281,9 @@ class report_log_renderable implements renderable {
*/
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)) {
// Activities delegating sections might not have a URL, but should be return a name to be shown.
$tobeshown = (strcmp($cm->modname, 'folder') == 0) || array_key_exists($cm->id, $this->delegatedbycm);
if (!$cm->uservisible || (!$cm->has_view() && !$tobeshown)) {
return '';
}
$modname = strip_tags($cm->get_formatted_name());

View File

@ -0,0 +1,38 @@
@report @report_log @mod_subsection
Feature: Subsection behavior in Log report.
Background:
Given I enable "subsection" "mod" plugin
And the following "courses" exist:
| fullname | shortname | category | numsections | initsections |
| Course 1 | C1 | 0 | 2 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| admin | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | course | idnumber | section |
| subsection | Subsection 1 | C1 | subsection1 | 1 |
| page | Page 1 | C1 | page1 | 3 |
@javascript
Scenario: Visible subsections should be available in the activities selector
Given I log in as "admin"
And I am on "Course 1" course homepage
When I navigate to "Reports" in current page administration
And I click on "Logs" "link"
Then the "Activities" select box should contain "Subsection 1"
And the "Activities" select box should contain "Page 1"
@javascript
Scenario: Hidden subsections should be available in the activities selector
Given I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I hide section "Subsection 1"
When I navigate to "Reports" in current page administration
And I click on "Logs" "link"
Then the "Activities" select box should not contain "Subsection 1"
And the "Activities" select box should not contain "Page 1"