diff --git a/report/log/classes/renderable.php b/report/log/classes/renderable.php index 738b5e94b4e46..20fa7b7dbc3e5 100644 --- a/report/log/classes/renderable.php +++ b/report/log/classes/renderable.php @@ -103,6 +103,9 @@ class report_log_renderable implements renderable { */ public $grouplist; + /** @var int current coursemodule Id */ + public $currentcmid; + /** * Constructor. * @@ -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; @@ -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; } /** diff --git a/report/log/classes/renderer.php b/report/log/classes/renderer.php index b8ff1aea17345..5d48428f811ca 100644 --- a/report/log/classes/renderer.php +++ b/report/log/classes/renderer.php @@ -95,28 +95,33 @@ 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, 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); + } } + } else { + echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $selectedcourseid)); } // Add group selector. @@ -160,12 +165,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, array('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', array('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, diff --git a/report/log/index.php b/report/log/index.php index 41519990296c3..59967148e4ecd 100644 --- a/report/log/index.php +++ b/report/log/index.php @@ -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. @@ -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(); @@ -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'); @@ -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'); @@ -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); } diff --git a/report/log/lib.php b/report/log/lib.php index 1c6dcf6966b56..4409ebfb2e147 100644 --- a/report/log/lib.php +++ b/report/log/lib.php @@ -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', array('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', '')); } }