Skip to content

Commit

Permalink
MDL-81790 report_log: Log report page per activities
Browse files Browse the repository at this point in the history
* When clicking on the More / Logs menu in an activity we
should stay on the activity page and not go on the course
report log
  • Loading branch information
laurentdavid committed Nov 19, 2024
1 parent 269a8a8 commit dd48cca
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 32 deletions.
6 changes: 5 additions & 1 deletion report/log/classes/renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class report_log_renderable implements renderable {
*/
public $grouplist;

/** @var int current coursemodule Id */
public $currentcmid;

/**
* Constructor.
*
Expand All @@ -126,7 +129,7 @@ class report_log_renderable implements renderable {
*/
public function __construct($logreader = "", $course = 0, $userid = 0, $modid = 0, $action = "", $groupid = 0, $edulevel = -1,
$showcourses = false, $showusers = false, $showreport = true, $showselectorform = true, $url = "", $date = 0,
$logformat='showashtml', $page = 0, $perpage = 100, $order = "timecreated ASC", $origin ='') {
$logformat='showashtml', $page = 0, $perpage = 100, $order = "timecreated ASC", $origin ='', int $currentcmid = 0) {

global $PAGE;

Expand Down Expand Up @@ -171,6 +174,7 @@ public function __construct($logreader = "", $course = 0, $userid = 0, $modid =
$this->showselectorform = $showselectorform;
$this->logformat = $logformat;
$this->origin = $origin;
$this->currentcmid = $currentcmid;
}

/**
Expand Down
67 changes: 40 additions & 27 deletions report/log/classes/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,38 @@ public function report_selector_form(report_log_renderable $reportlog) {

$selectedcourseid = empty($reportlog->course) ? 0 : $reportlog->course->id;

// Add course selector.
$sitecontext = context_system::instance();
$courses = $reportlog->get_course_list();
if (!empty($courses) && $reportlog->showcourses) {
echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
echo html_writer::select($courses, "id", $selectedcourseid, null, ['class' => 'me-2 mb-2']);
} else {
$courses = array();
$courses[$selectedcourseid] = get_course_display_name_for_list($reportlog->course) . (($selectedcourseid == SITEID) ?
' (' . get_string('site') . ') ' : '');
echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
echo html_writer::select($courses, "id", $selectedcourseid, false, ['class' => 'me-2 mb-2']);
// Check if user is admin and this came because of limitation on number of courses to show in dropdown.
if (has_capability('report/log:view', $sitecontext)) {
$a = new stdClass();
$a->url = new moodle_url('/report/log/index.php', array('chooselog' => 0,
'group' => $reportlog->get_selected_group(), 'user' => $reportlog->userid,
'id' => $selectedcourseid, 'date' => $reportlog->date, 'modid' => $reportlog->modid,
'showcourses' => 1, 'showusers' => $reportlog->showusers));
$a->url = $a->url->out(false);
print_string('logtoomanycourses', 'moodle', $a);
// Add course selector if current cmid not set.
if (empty($reportlog->currentcmid)) {
$sitecontext = context_system::instance();
$courses = $reportlog->get_course_list();
if (!empty($courses) && $reportlog->showcourses) {
echo html_writer::label(get_string('selectacourse'), 'menuid', false, ['class' => 'accesshide']);
echo html_writer::select($courses, "id", $selectedcourseid, null, ['class' => 'me-2 mb-2']);
} else {
$courses = [];
$courses[$selectedcourseid] =
get_course_display_name_for_list($reportlog->course) . (($selectedcourseid == SITEID) ?
' (' . get_string('site') . ') ' : '');
echo html_writer::label(get_string('selectacourse'), 'menuid', false, ['class' => 'accesshide']);
echo html_writer::select($courses, "id", $selectedcourseid, false, ['class' => 'me-2 mb-2']);
// Check if user is admin and this came because of limitation on number of courses to show in dropdown.
if (has_capability('report/log:view', $sitecontext)) {
$a = new stdClass();
$a->url = new moodle_url('/report/log/index.php', [
'chooselog' => 0,
'group' => $reportlog->get_selected_group(),
'user' => $reportlog->userid,
'id' => $selectedcourseid,
'date' => $reportlog->date,
'modid' => $reportlog->modid,
'showcourses' => 1, 'showusers' => $reportlog->showusers,
]);
$a->url = $a->url->out(false);
print_string('logtoomanycourses', 'moodle', $a);
}
}
} else {
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'id', 'value' => $selectedcourseid]);
}

// Add group selector.
Expand Down Expand Up @@ -160,12 +170,15 @@ public function report_selector_form(report_log_renderable $reportlog) {
echo html_writer::select($dates, "date", $reportlog->date, get_string("alldays"),
['class' => 'me-2 mb-2']);

// Add activity selector.
[$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' => 'me-2 mb-2'], $disabled);

// Add activity selector if cmid is not set.
if (empty($reportlog->currentcmid)) {
[$activities, $disabled] = $reportlog->get_activities_list();
echo html_writer::label(get_string('activities'), 'menumodid', false, ['class' => 'accesshide']);
echo html_writer::select($activities, "modid", $reportlog->modid, get_string("allactivities"),
['class' => 'me-2 mb-2'], $disabled);
} else {
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'cmid', 'value' => $reportlog->currentcmid]);
}
// Add actions selector.
echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide'));
echo html_writer::select($reportlog->get_actions(), 'modaction', $reportlog->action,
Expand Down
19 changes: 16 additions & 3 deletions report/log/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
$user = optional_param('user', 0, PARAM_INT); // User to display.
$date = optional_param('date', 0, PARAM_INT); // Date to display.
$modid = optional_param('modid', 0, PARAM_ALPHANUMEXT); // Module id or 'site_errors'.
$cmid = optional_param('cmid', 0, PARAM_INT); // Course Module ID.
$modaction = optional_param('modaction', '', PARAM_ALPHAEXT); // An action as recorded in the logs.
$page = optional_param('page', '0', PARAM_INT); // Which page to show.
$perpage = optional_param('perpage', '100', PARAM_INT); // How many per page.
Expand Down Expand Up @@ -104,6 +105,14 @@
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_login($course);
$context = context_course::instance($course->id);
if ($cmid) {
$modinfo = get_fast_modinfo($course);
if (!isset($modinfo->cms[$cmid])) {
throw new moodle_exception('invalidmoduleid', '', '', $modid);
}
$context = context_module::instance($cmid);
$PAGE->set_cm($modinfo->cms[$cmid]);
}
} else {
$course = $SITE;
require_login();
Expand Down Expand Up @@ -146,7 +155,7 @@
}

$reportlog = new report_log_renderable($logreader, $course, $user, $modid, $modaction, $group, $edulevel, $showcourses, $showusers,
$chooselog, true, $url, $date, $logformat, $page, $perpage, 'timecreated DESC', $origin);
$chooselog, true, $url, $date, $logformat, $page, $perpage, 'timecreated DESC', $origin, $cmid);
$readers = $reportlog->get_readers();
$output = $PAGE->get_renderer('report_log');

Expand All @@ -162,7 +171,9 @@
echo $output->header();
// Print selector dropdown.
$pluginname = get_string('pluginname', 'report_log');
report_helper::print_report_selector($pluginname);
if (empty($cmid)) {
report_helper::print_report_selector($pluginname);
}
$userinfo = get_string('allparticipants');
$dateinfo = get_string('alldays');

Expand All @@ -186,7 +197,9 @@
echo $output->header();
// Print selector dropdown.
$pluginname = get_string('pluginname', 'report_log');
report_helper::print_report_selector($pluginname);
if (empty($cmid)) {
report_helper::print_report_selector($pluginname);
}
echo $output->heading(get_string('chooselogs') .':', 3);
echo $output->render($reportlog);
}
Expand Down
2 changes: 1 addition & 1 deletion report/log/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function report_log_can_access_user_report($user, $course) {
*/
function report_log_extend_navigation_module($navigation, $cm) {
if (has_capability('report/log:view', context_course::instance($cm->course))) {
$url = new moodle_url('/report/log/index.php', array('chooselog'=>'1','id'=>$cm->course,'modid'=>$cm->id));
$url = new moodle_url('/report/log/index.php', ['chooselog' => '1', 'id' => $cm->course, 'cmid' => $cm->id]);
$navigation->add(get_string('logs'), $url, navigation_node::TYPE_SETTING, null, 'logreport', new pix_icon('i/report', ''));
}
}
Expand Down
42 changes: 42 additions & 0 deletions report/log/tests/behat/activity_report_log.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@report @report_log
Feature: In a activity page, navigate through the More / Logs menu, test for report log page
In order to navigate through report page
As an admin
Go to the activity page, click on More / Logs menu, and check for the report log page

Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "activities" exist:
| activity | name | course | section |
| page | Test page 1 | C1 | 1 |
| page | Test page 2 | C1 | 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 |

@javascript
Scenario: Report selectors should be targeted toward course module
Given I am on the "Test page 1" Activity page logged in as "admin"
When I navigate to "Logs" in current page administration
And I click on "Logs" "link"
Then "menuid" "select" should not exist
And "modid" "select" should not exist
And I should see "All participants" in the "user" "select"
And I should see "All days" in the "date" "select"
And I should see "All sources" in the "origin" "select"
And I should see "All events" in the "edulevel" "select"
And "Page" "link" should exist in current page administration

@javascript
Scenario: Report submission stays in the same course module page
Given I am on the "Test page 1" Activity page logged in as "admin"
When I navigate to "Logs" in current page administration
And I click on "Logs" "link"
And I click on "Get these logs" "button"
Then "Page" "link" should exist in current page administration

0 comments on commit dd48cca

Please sign in to comment.