mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-82495-main-cl' of https://github.com/ferranrecio/moodle
This commit is contained in:
commit
9978cbaabb
@ -112,6 +112,119 @@ class coursestructure implements \renderable, \templatable {
|
||||
return $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports course sections, sections delegated by modules and modules data in a hierarchical format.
|
||||
*
|
||||
* @param \renderer_base $output
|
||||
* @return array|\stdClass
|
||||
*/
|
||||
public function export_hierarchy(\renderer_base $output) {
|
||||
|
||||
$sections = [];
|
||||
|
||||
$allsections = $this->modinfo->get_sections();
|
||||
foreach ($allsections as $sectionnum => $sectionmodules) {
|
||||
// Add the section row.
|
||||
$sectioninfo = $this->modinfo->get_section_info($sectionnum);
|
||||
|
||||
// Don't show subsections here. We are showing them in the corresponding module.
|
||||
if ($sectioninfo->is_delegated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$sectioninfo->uservisible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$section = $this->export_section_data($output, $sectioninfo, false);
|
||||
if (empty($sectioninfo) || empty($sectioninfo->sequence)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$activities = $this->export_hierarchy_section_activities_data($output, $sectioninfo, $allsections);
|
||||
if (!empty($activities)) {
|
||||
$section['activities'] = $activities;
|
||||
}
|
||||
|
||||
$sections[] = $section;
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports activities data for a section in a hierarchical format.
|
||||
* @param \renderer_base $output
|
||||
* @param \section_info $sectioninfo
|
||||
* @param array $allsections
|
||||
* @return array
|
||||
*/
|
||||
private function export_hierarchy_section_activities_data(
|
||||
\renderer_base $output,
|
||||
\section_info $sectioninfo,
|
||||
array $allsections
|
||||
): array {
|
||||
$allsections = $this->modinfo->get_sections();
|
||||
|
||||
$sectionmodules = explode(",", $sectioninfo->sequence);
|
||||
$activities = [];
|
||||
|
||||
// Add section modules and possibly subsections.
|
||||
foreach ($sectionmodules as $cmid) {
|
||||
$activity = $this->export_hierarchy_activity_data($output, $this->modinfo->cms[$cmid], $allsections);
|
||||
if (!empty($activity)) {
|
||||
$activities[] = $activity;
|
||||
}
|
||||
}
|
||||
return $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports activity data for a section in a hierarchical format.
|
||||
* @param \renderer_base $output
|
||||
* @param \cm_info $cm
|
||||
* @param array $allsections
|
||||
* @return array|null
|
||||
*/
|
||||
private function export_hierarchy_activity_data(
|
||||
\renderer_base $output,
|
||||
\cm_info $cm,
|
||||
array $allsections
|
||||
): ?array {
|
||||
$delegatedsections = $this->modinfo->get_sections_delegated_by_cm();
|
||||
|
||||
// Subsections has a special export.
|
||||
if (array_key_exists($cm->id, $delegatedsections)) {
|
||||
$subsectioninfo = $delegatedsections[$cm->id];
|
||||
// Only non-empty are listed in allsections. We don't show empty sections.
|
||||
if (!array_key_exists($subsectioninfo->sectionnum, $allsections)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$subsection = $this->export_section_data($output, $subsectioninfo, true);
|
||||
if (empty($subsection)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show activities inside the section.
|
||||
$subsectionmodules = $allsections[$subsectioninfo->sectionnum];
|
||||
$subactivities = [];
|
||||
foreach ($subsectionmodules as $subsectioncmid) {
|
||||
$cm = $this->modinfo->cms[$subsectioncmid];
|
||||
$activity = $this->export_activity_data($output, $cm, true);
|
||||
if (!empty($activity)) {
|
||||
$subactivities[] = $activity;
|
||||
}
|
||||
}
|
||||
if (!empty($subactivities)) {
|
||||
$subsection['activities'] = $subactivities;
|
||||
}
|
||||
return $subsection;
|
||||
}
|
||||
|
||||
return $this->export_activity_data($output, $cm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the headers for report table.
|
||||
*
|
||||
@ -122,7 +235,6 @@ class coursestructure implements \renderable, \templatable {
|
||||
return [get_string('activity')];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exports the data for a single section.
|
||||
*
|
||||
|
123
report/outline/classes/output/hierarchicalactivities.php
Normal file
123
report/outline/classes/output/hierarchicalactivities.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace report_outline\output;
|
||||
|
||||
use core_report\output\coursestructure;
|
||||
use course_modinfo;
|
||||
|
||||
/**
|
||||
* Activities list page in a hierarchical format.
|
||||
*
|
||||
* @package report_outline
|
||||
* @copyright 2024 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class hierarchicalactivities extends coursestructure {
|
||||
|
||||
/**
|
||||
* Exports the data for a single activity.
|
||||
*
|
||||
* @param \renderer_base $output
|
||||
* @param \cm_info $cm
|
||||
* @param bool $indelegated Whether the activity is part of a delegated section or not.
|
||||
* @return array
|
||||
*/
|
||||
public function export_activity_data(\renderer_base $output, \cm_info $cm, bool $indelegated = false): array {
|
||||
if (!$cm->has_view()) {
|
||||
return [];
|
||||
}
|
||||
if (!$cm->uservisible) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'isactivity' => true,
|
||||
'isdelegated' => false,
|
||||
'indelegated' => $indelegated,
|
||||
'visible' => $cm->visible,
|
||||
'id' => $cm->id,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print activity data.
|
||||
*
|
||||
* @param \renderer_base $output
|
||||
* @param string $mode
|
||||
* @param \cm_info $mod
|
||||
* @param \stdClass $user
|
||||
* @param \stdClass $course
|
||||
*/
|
||||
public function print_activity(
|
||||
\renderer_base $output,
|
||||
string $mode,
|
||||
\cm_info $mod,
|
||||
\stdClass $user,
|
||||
\stdClass $course,
|
||||
): void {
|
||||
global $CFG, $DB;
|
||||
|
||||
$instance = $DB->get_record($mod->modname, ['id' => $mod->instance]);
|
||||
$libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
|
||||
|
||||
if (!file_exists($libfile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once($libfile);
|
||||
|
||||
switch ($mode) {
|
||||
case "outline":
|
||||
$useroutline = $mod->modname . "_user_outline";
|
||||
if (function_exists($useroutline)) {
|
||||
$toprint = $useroutline($course, $user, $mod, $instance);
|
||||
} else {
|
||||
$toprint = report_outline_user_outline($user->id, $mod->id, $mod->modname, $mod->instance);
|
||||
}
|
||||
if (!$toprint) {
|
||||
$toprint = (object) ['info' => '-'];
|
||||
}
|
||||
report_outline_print_row($mod, $instance, $toprint);
|
||||
break;
|
||||
case "complete":
|
||||
$usercomplete = $mod->modname . "_user_complete";
|
||||
$image = $output->pix_icon('monologo', $mod->modfullname, 'mod_' . $mod->modname, ['class' => 'icon']);
|
||||
echo "<h4 class=\"h6\">$image $mod->modfullname: " .
|
||||
"<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">" .
|
||||
format_string($instance->name, true) . "</a></h4>";
|
||||
|
||||
ob_start();
|
||||
|
||||
echo "<ul>";
|
||||
if (function_exists($usercomplete)) {
|
||||
$usercomplete($course, $user, $mod, $instance);
|
||||
} else {
|
||||
echo report_outline_user_complete($user->id, $mod->id, $mod->modname, $mod->instance);
|
||||
}
|
||||
echo "</ul>";
|
||||
|
||||
$toprint = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (str_replace(' ', '', $toprint) != '<ul></ul>') {
|
||||
echo $toprint;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +1,8 @@
|
||||
#page-report-outline-user .section .content {
|
||||
margin-left: 30px;
|
||||
margin-right: 30px;
|
||||
#page-report-outline-user table tr td {
|
||||
padding: 10px 3px;
|
||||
min-width: 20px;
|
||||
}
|
||||
|
||||
#page-report-outline-user .section h2 {
|
||||
margin-top: 0;
|
||||
#page-report-outline-user .subsection .icon {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
#page-report-outline-user .section {
|
||||
margin-left: 30px;
|
||||
margin-right: 30px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#page-report-outline-user .section {
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@ Feature: View an outline report
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
| fullname | shortname | format | numsections |
|
||||
| Course 1 | C1 | topics | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
@ -88,3 +88,29 @@ Feature: View an outline report
|
||||
And I click on "Activity report" "link"
|
||||
Then I should see "-" in the "Forum name" "table_row"
|
||||
And I should see "-" in the "Book name" "table_row"
|
||||
|
||||
Scenario: The outline report can represent courses with subsections
|
||||
Given I enable "subsection" "mod" plugin
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | section | visible | assignsubmission_onlinetext_enabled | assignsubmission_file_enabled |
|
||||
| assign | Activity1 | C1 | 1 | 1 | 1 | 0 |
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | section | visible |
|
||||
| subsection | Subsection1 | C1 | 1 | 1 |
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | section | visible | assignsubmission_onlinetext_enabled | assignsubmission_file_enabled |
|
||||
| assign | Subactivity1.1 | C1 | 2 | 1 | 1 | 0 |
|
||||
| assign | Subactivity1.2 | C1 | 2 | 0 | 1 | 0 |
|
||||
| assign | Activity2 | C1 | 1 | 1 | 1 | 0 |
|
||||
When I am on the "Course 1" course page logged in as teacher1
|
||||
And I navigate to "Reports" in current page administration
|
||||
And I click on "Activity report" "link"
|
||||
Then "Subactivity1.1" "table_row" should appear after "Activity1" "table_row"
|
||||
And "Subactivity1.2" "table_row" should appear after "Subactivity1.1" "table_row"
|
||||
And "Activity2" "table_row" should appear after "Subactivity1.2" "table_row"
|
||||
And I navigate to "Participants" in current page administration
|
||||
And I click on "Student 1" "link"
|
||||
And I click on "Outline report" "link"
|
||||
And "Subactivity1.1" "table_row" should appear after "Activity1" "table_row"
|
||||
And I should not see "Subactivity1.2" in the "page-content" "region"
|
||||
And "Activity2" "table_row" should appear after "Subactivity1.1" "table_row"
|
||||
|
@ -23,6 +23,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use report_outline\output\hierarchicalactivities;
|
||||
|
||||
require('../../config.php');
|
||||
require_once($CFG->dirroot.'/report/outline/locallib.php');
|
||||
require_once($CFG->dirroot.'/report/outline/lib.php');
|
||||
@ -107,84 +109,78 @@ if ($courseid != SITEID) {
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($course, $user->id);
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
$itemsprinted = false;
|
||||
|
||||
$coursestructure = new hierarchicalactivities($modinfo);
|
||||
$sections = $coursestructure->export_hierarchy($OUTPUT);
|
||||
|
||||
foreach ($sections as $i => $section) {
|
||||
if (!$section['visible']) {
|
||||
continue;
|
||||
}
|
||||
$section = (object) $section;
|
||||
$itemsprinted = true;
|
||||
echo '<div class="section p-3 my-4">';
|
||||
echo '<h2 class="h4">';
|
||||
echo $section->text;
|
||||
echo "</h2>";
|
||||
|
||||
if ($section->uservisible) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
|
||||
// Check the section has modules/resources, if not there is nothing to display.
|
||||
if (!empty($modinfo->sections[$i])) {
|
||||
$itemsprinted = true;
|
||||
echo '<div class="section">';
|
||||
echo '<h2>';
|
||||
echo get_section_name($course, $section);
|
||||
echo "</h2>";
|
||||
echo '<div class="content">';
|
||||
|
||||
echo '<div class="content">';
|
||||
if ($mode == "outline") {
|
||||
echo "<table>";
|
||||
}
|
||||
|
||||
if ($mode == "outline") {
|
||||
echo "<table cellpadding=\"4\" cellspacing=\"0\">";
|
||||
}
|
||||
|
||||
foreach ($modinfo->sections[$i] as $cmid) {
|
||||
$mod = $modinfo->cms[$cmid];
|
||||
|
||||
if (empty($mod->uservisible)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance));
|
||||
$libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
|
||||
|
||||
if (file_exists($libfile)) {
|
||||
require_once($libfile);
|
||||
|
||||
switch ($mode) {
|
||||
case "outline":
|
||||
$user_outline = $mod->modname."_user_outline";
|
||||
if (function_exists($user_outline)) {
|
||||
$output = $user_outline($course, $user, $mod, $instance);
|
||||
} else {
|
||||
$output = report_outline_user_outline($user->id, $cmid, $mod->modname, $instance->id);
|
||||
}
|
||||
report_outline_print_row($mod, $instance, $output);
|
||||
break;
|
||||
case "complete":
|
||||
$user_complete = $mod->modname."_user_complete";
|
||||
$image = $OUTPUT->pix_icon('monologo', $mod->modfullname, 'mod_'.$mod->modname, array('class'=>'icon'));
|
||||
echo "<h4>$image $mod->modfullname: ".
|
||||
"<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
|
||||
format_string($instance->name,true)."</a></h4>";
|
||||
|
||||
ob_start();
|
||||
|
||||
echo "<ul>";
|
||||
if (function_exists($user_complete)) {
|
||||
$user_complete($course, $user, $mod, $instance);
|
||||
} else {
|
||||
echo report_outline_user_complete($user->id, $cmid, $mod->modname, $instance->id);
|
||||
}
|
||||
echo "</ul>";
|
||||
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (str_replace(' ', '', $output) != '<ul></ul>') {
|
||||
echo $output;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == "outline") {
|
||||
echo "</table>";
|
||||
}
|
||||
echo '</div>'; // content
|
||||
echo '</div>'; // section
|
||||
}
|
||||
foreach ($section->activities as $cm) {
|
||||
if (!$cm['visible']) {
|
||||
continue;
|
||||
}
|
||||
$cm = (object) $cm;
|
||||
if ($cm->isdelegated) {
|
||||
// Print subsection box.
|
||||
if ($mode == "outline") {
|
||||
echo "</table>";
|
||||
}
|
||||
echo '<div class="section subsection p-3 my-2">';
|
||||
echo '<h3 class="font-lg">';
|
||||
echo $cm->text;
|
||||
echo "</h3>";
|
||||
|
||||
echo '<div class="content">';
|
||||
|
||||
if ($mode == "outline") {
|
||||
echo "<table>";
|
||||
}
|
||||
|
||||
foreach ($cm->activities as $subcm) {
|
||||
if (!$subcm['visible']) {
|
||||
continue;
|
||||
}
|
||||
$subcm = (object) $subcm;
|
||||
$mod = $modinfo->cms[$subcm->id];
|
||||
$coursestructure->print_activity($OUTPUT, $mode, $mod, $user, $course);
|
||||
}
|
||||
if ($mode == "outline") {
|
||||
echo "</table>";
|
||||
}
|
||||
echo "</div>"; // Content.
|
||||
echo "</div>"; // Subsection.
|
||||
if ($mode == "outline") {
|
||||
echo "<table>";
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$mod = $modinfo->cms[$cm->id];
|
||||
$coursestructure->print_activity($OUTPUT, $mode, $mod, $user, $course);
|
||||
}
|
||||
|
||||
if ($mode == "outline") {
|
||||
echo "</table>";
|
||||
}
|
||||
echo '</div>'; // Content.
|
||||
echo '</div>'; // Section.
|
||||
}
|
||||
|
||||
if (!$itemsprinted) {
|
||||
|
@ -35,6 +35,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
#page-report-outline-user .section {
|
||||
border: $border-width solid $border-color;
|
||||
@include border-radius($activity-border-radius);
|
||||
}
|
||||
|
||||
#page-report-outline-user .font-lg {
|
||||
font-size: $font-size-base * 1.1;
|
||||
}
|
||||
|
||||
#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.
|
||||
|
@ -35170,6 +35170,15 @@ img.userpicture {
|
||||
padding-left: 3.5rem;
|
||||
}
|
||||
|
||||
#page-report-outline-user .section {
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
#page-report-outline-user .font-lg {
|
||||
font-size: 1.03125rem;
|
||||
}
|
||||
|
||||
#page-report-log-index #menumodid option:disabled {
|
||||
color: #4b535a;
|
||||
font-weight: bolder;
|
||||
|
@ -35170,6 +35170,15 @@ img.userpicture {
|
||||
padding-left: 3.5rem;
|
||||
}
|
||||
|
||||
#page-report-outline-user .section {
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
#page-report-outline-user .font-lg {
|
||||
font-size: 1.03125rem;
|
||||
}
|
||||
|
||||
#page-report-log-index #menumodid option:disabled {
|
||||
color: #4b535a;
|
||||
font-weight: bolder;
|
||||
|
Loading…
x
Reference in New Issue
Block a user