mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'w17_MDL-45219_m27_addtolog' of git://github.com/skodak/moodle
This commit is contained in:
commit
3ebfb87878
83
admin/tool/capability/classes/event/report_viewed.php
Normal file
83
admin/tool/capability/classes/event/report_viewed.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event for when capability report is viewed.
|
||||
*
|
||||
* @package tool_capability
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_capability\event;
|
||||
|
||||
/**
|
||||
* Event triggered, when capability report is viewed.
|
||||
*
|
||||
* @package tool_capability
|
||||
* @since Moodle 2.7
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class report_viewed extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventreportviewed', 'tool_capability');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id " . $this->userid . " viewed capability overview report";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array(SITEID, 'admin', 'tool capability', 'tool/capability/index.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/admin/tool/capability/index.php');
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ if ($data = $form->get_data()) {
|
||||
}
|
||||
}
|
||||
|
||||
add_to_log(SITEID, "admin", "tool capability", "tool/capability/index.php", count($capabilities));
|
||||
\tool_capability\event\report_viewed::create()->trigger();
|
||||
|
||||
$renderer = $PAGE->get_renderer('tool_capability');
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
$string['capabilitylabel'] = 'Capability:';
|
||||
$string['capabilityreport'] = 'Capability overview';
|
||||
$string['eventreportviewed'] = 'Report viewed';
|
||||
$string['forroles'] = 'For roles {$a}';
|
||||
$string['getreport'] = 'Get the overview';
|
||||
$string['changeoverrides'] = 'Change overrides in this context';
|
||||
|
65
admin/tool/capability/tests/events_test.php
Normal file
65
admin/tool/capability/tests/events_test.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Tests for capability overview events.
|
||||
*
|
||||
* @package tool_capability
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class for capability overview events.
|
||||
*
|
||||
* @package tool_capability
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class tool_capability_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Setup testcase.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->setAdminUser();
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the report viewed event.
|
||||
*/
|
||||
public function test_report_viewed() {
|
||||
$event = \tool_capability\event\report_viewed::create();
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
$this->assertInstanceOf('\tool_capability\event\report_viewed', $event);
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
$expected = array(SITEID, "admin", "tool capability", "tool/capability/index.php");
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$url = new moodle_url('/admin/tool/capability/index.php');
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$event->get_name();
|
||||
}
|
||||
}
|
@ -37,11 +37,10 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
}
|
||||
|
||||
require_login($course);
|
||||
|
||||
add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", $course->id);
|
||||
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
\core\event\recent_activity_viewed::create(array('context' => $context))->trigger();
|
||||
|
||||
$lastlogin = time() - COURSE_MAX_RECENT_PERIOD;
|
||||
if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) {
|
||||
if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) {
|
||||
|
@ -741,6 +741,7 @@ $string['eventcourseuserreportviewed'] = 'Course user report viewed';
|
||||
$string['eventcourseviewed'] = 'Course viewed';
|
||||
$string['eventemailfailed'] = 'Email failed to send';
|
||||
$string['eventname'] = 'Event name';
|
||||
$string['eventrecentactivityviewed'] = 'Recent activity viewed';
|
||||
$string['eventunknownlogged'] = 'Unknown event';
|
||||
$string['eventusercreated'] = 'User created';
|
||||
$string['eventuserdeleted'] = 'User deleted';
|
||||
|
95
lib/classes/event/recent_activity_viewed.php
Normal file
95
lib/classes/event/recent_activity_viewed.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event for recent activity page.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core\event;
|
||||
|
||||
/**
|
||||
* Event for recent activity page.
|
||||
*
|
||||
* @package core
|
||||
* @since Moodle 2.7
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class recent_activity_viewed extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventrecentactivityviewed', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id " . $this->userid . " viewed recent activity report in course " . $this->courseid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, "course", "recent", "recent.php?id=$this->courseid", $this->courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/course/recent.php', array('id' => $this->courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
|
||||
if ($this->contextlevel != CONTEXT_COURSE) {
|
||||
throw new \coding_exception('recent_activity_viewed event expects only course contexts.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -262,4 +262,29 @@ class core_events_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('\core\event\course_viewed', $restored);
|
||||
$this->assertNull($restored->get_url());
|
||||
}
|
||||
|
||||
public function test_recent_capability_viewed() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
$event = \core\event\recent_activity_viewed::create(array('context' => $context));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
$this->assertInstanceOf('\core\event\recent_activity_viewed', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$expected = array($course->id, "course", "recent", "recent.php?id=$course->id", $course->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$url = new moodle_url('/course/recent.php', array('id' => $course->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$event->get_name();
|
||||
}
|
||||
}
|
||||
|
@ -1,121 +1,8 @@
|
||||
<?php
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
require_course_login($course);
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
|
||||
add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "");
|
||||
|
||||
$strassignments = get_string("modulenameplural", "assignment");
|
||||
$strassignment = get_string("modulename", "assignment");
|
||||
$strassignmenttype = get_string("assignmenttype", "assignment");
|
||||
$strname = get_string("name");
|
||||
$strduedate = get_string("duedate", "assignment");
|
||||
$strsubmitted = get_string("submitted", "assignment");
|
||||
$strgrade = get_string("grade");
|
||||
|
||||
|
||||
$PAGE->set_url('/mod/assignment/index.php', array('id'=>$course->id));
|
||||
$PAGE->navbar->add($strassignments);
|
||||
$PAGE->set_title($strassignments);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (!$cms = get_coursemodules_in_course('assignment', $course->id, 'cm.idnumber, m.assignmenttype, m.timedue')) {
|
||||
notice(get_string('noassignments', 'assignment'), "../../course/view.php?id=$course->id");
|
||||
die;
|
||||
}
|
||||
|
||||
$usesections = course_format_uses_sections($course->format);
|
||||
|
||||
$timenow = time();
|
||||
|
||||
$table = new html_table();
|
||||
|
||||
if ($usesections) {
|
||||
$strsectionname = get_string('sectionname', 'format_'.$course->format);
|
||||
$table->head = array ($strsectionname, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
|
||||
} else {
|
||||
$table->head = array ($strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
|
||||
}
|
||||
|
||||
$currentsection = "";
|
||||
|
||||
$types = assignment_types();
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
foreach ($modinfo->instances['assignment'] as $cm) {
|
||||
if (!$cm->uservisible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$assignmenttype = $cms[$cm->id]->assignmenttype;
|
||||
|
||||
//Show dimmed if the mod is hidden
|
||||
$class = $cm->visible ? '' : 'class="dimmed"';
|
||||
|
||||
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
|
||||
|
||||
$printsection = "";
|
||||
if ($usesections) {
|
||||
if ($cm->sectionnum !== $currentsection) {
|
||||
if ($cm->sectionnum) {
|
||||
$printsection = get_section_name($course, $cm->sectionnum);
|
||||
}
|
||||
if ($currentsection !== "") {
|
||||
$table->data[] = 'hr';
|
||||
}
|
||||
$currentsection = $cm->sectionnum;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignmenttype.'/assignment.class.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignmenttype.'/assignment.class.php');
|
||||
$assignmentclass = 'assignment_'.$assignmenttype;
|
||||
$assignmentinstance = new $assignmentclass($cm->id, NULL, $cm, $course);
|
||||
|
||||
$submitted = $assignmentinstance->submittedlink(true);
|
||||
|
||||
$grading_info = grade_get_grades($course->id, 'mod', 'assignment', $cm->instance, $USER->id);
|
||||
if (isset($grading_info->items[0]) && !$grading_info->items[0]->grades[$USER->id]->hidden ) {
|
||||
$grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
|
||||
}
|
||||
else {
|
||||
$grade = '-';
|
||||
}
|
||||
|
||||
$type = $types[$assignmenttype];
|
||||
|
||||
// if type has an 'all.php' defined, make this a link
|
||||
$pathtoall = "{$CFG->dirroot}/mod/assignment/type/{$assignmenttype}/all.php";
|
||||
if (file_exists($pathtoall)) {
|
||||
$type = "<a href=\"{$CFG->wwwroot}/mod/assignment/type/{$assignmenttype}/".
|
||||
"all.php?id={$course->id}\">$type</a>";
|
||||
}
|
||||
|
||||
$due = !empty($cms[$cm->id]->timedue) ? userdate($cms[$cm->id]->timedue) : '-';
|
||||
|
||||
if ($usesections) {
|
||||
$table->data[] = array ($printsection, $link, $type, $due, $submitted, $grade);
|
||||
} else {
|
||||
$table->data[] = array ($link, $type, $due, $submitted, $grade);
|
||||
}
|
||||
}
|
||||
|
||||
echo "<br />";
|
||||
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
// Rest in peace old assignment!
|
||||
redirect(new moodle_url('/mod/assign/index.php', array('id' => $id)));
|
||||
|
44
mod/chat/classes/event/course_module_viewed.php
Normal file
44
mod/chat/classes/event/course_module_viewed.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Chat main page viewed event.
|
||||
*
|
||||
* @package mod_chat
|
||||
* @since Moodle 2.7
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_chat\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Chat main page viewed event.
|
||||
*
|
||||
* @package mod_chat
|
||||
* @since Moodle 2.7
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_module_viewed extends \core\event\course_module_viewed {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'chat';
|
||||
}
|
||||
}
|
@ -161,4 +161,27 @@ class mod_chat_events_testcase extends advanced_testcase {
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
|
||||
public function test_course_module_viewed() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id));
|
||||
$cm = get_coursemodule_from_instance('chat', $chat->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
$params = array(
|
||||
'objectid' => $chat->id,
|
||||
'context' => $context
|
||||
);
|
||||
$event = \mod_chat\event\course_module_viewed::create($params);
|
||||
$event->add_record_snapshot('chat', $chat);
|
||||
$event->trigger();
|
||||
|
||||
$expected = array($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$url = new moodle_url('/mod/chat/view.php', array('id' => $cm->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$event->get_name();
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,15 @@ if (isguestuser()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
|
||||
// Log this request - the problem here is that the view page
|
||||
// does not display the chat content which is actually in a new window.
|
||||
$params = array(
|
||||
'objectid' => $chat->id,
|
||||
'context' => $context
|
||||
);
|
||||
$event = \mod_chat\event\course_module_viewed::create($params);
|
||||
$event->add_record_snapshot('chat', $chat);
|
||||
$event->trigger();
|
||||
|
||||
$strenterchat = get_string('enterchat', 'chat');
|
||||
$stridle = get_string('idle', 'chat');
|
||||
|
100
report/questioninstances/classes/event/report_viewed.php
Normal file
100
report/questioninstances/classes/event/report_viewed.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event for when capability report is viewed.
|
||||
*
|
||||
* @package report_questioninstances
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace report_questioninstances\event;
|
||||
|
||||
/**
|
||||
* Event triggered, when capability report is viewed.
|
||||
*
|
||||
* @property-read array $other Extra information about the event.
|
||||
* -string requestedqtype: Requested report type.
|
||||
*
|
||||
* @package report_questioninstances
|
||||
* @since Moodle 2.7
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class report_viewed extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventreportviewed', 'report_questioninstances');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id " . $this->userid . " viewed question instances report";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$requestedqtype = $this->other['requestedqtype'];
|
||||
return array(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/report/questioninstances/index.php', array('qtype' => $this->other['requestedqtype']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->data['other']['requestedqtype'])) {
|
||||
throw new \coding_exception('requestedqtype must be set in other array.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ admin_externalpage_setup('reportquestioninstances', '', null, '', array('pagelay
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Log.
|
||||
add_to_log(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
|
||||
\report_questioninstances\event\report_viewed::create(array('other' => array('requestedqtype' => $requestedqtype)))->trigger();
|
||||
|
||||
// Prepare the list of capabilities to choose from
|
||||
$qtypes = question_bank::get_all_qtypes();
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
$string['editquestionshere'] = 'Edit questions in this context';
|
||||
$string['eventreportviewed'] = 'Report viewed';
|
||||
$string['getreport'] = 'Get the report';
|
||||
$string['hiddenquestions'] = 'Hidden';
|
||||
$string['intro'] = 'This report lists all the contexts in the system where there are questions of a particular type.';
|
||||
|
66
report/questioninstances/tests/events_test.php
Normal file
66
report/questioninstances/tests/events_test.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Tests for question instances events.
|
||||
*
|
||||
* @package report_questioninstances
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class for question instances events.
|
||||
*
|
||||
* @package report_questioninstances
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class report_questioninstances_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Setup testcase.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->setAdminUser();
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the report viewed event.
|
||||
*/
|
||||
public function test_report_viewed() {
|
||||
$requestedqtype = 'all';
|
||||
$event = \report_questioninstances\event\report_viewed::create(array('other' => array('requestedqtype' => $requestedqtype)));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
$this->assertInstanceOf('\report_questioninstances\event\report_viewed', $event);
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
$expected = array(SITEID, "admin", "report questioninstances", "report/questioninstances/index.php?qtype=$requestedqtype", $requestedqtype);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$url = new moodle_url('/report/questioninstances/index.php', array('qtype' => $requestedqtype));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$event->get_name();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user