mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
Merge branch 'MDL-41123-master' of git://github.com/ankitagarwal/moodle
This commit is contained in:
commit
3c72b71191
88
report/completion/classes/event/report_viewed.php
Normal file
88
report/completion/classes/event/report_viewed.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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 completion report is viewed.
|
||||
*
|
||||
* @package report_completion
|
||||
* @copyright 2014 onwards Ankit Agarwal<ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace report_completion\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Event triggered, when completion report is viewed.
|
||||
*
|
||||
* @package report_completion
|
||||
* @copyright 2014 onwards Ankit Agarwal<ankit.agrr@gmail.com>
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventreportviewed', 'report_completion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id " . $this->userid . " viewed completion report for course with id " . $this->courseid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/report/completion/index.php', array('course' => $this->courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* custom validations.
|
||||
*
|
||||
* @throws \coding_exception when validation fails.
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
if ($this->contextlevel != CONTEXT_COURSE) {
|
||||
throw new \coding_exception('Context passed must be course context.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
98
report/completion/classes/event/user_report_viewed.php
Normal file
98
report/completion/classes/event/user_report_viewed.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?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 user log report is viewed.
|
||||
*
|
||||
* @package report_completion
|
||||
* @copyright 2014 onwards Ankit Agarwal<ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace report_completion\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Event triggered, when user log report is viewed.
|
||||
*
|
||||
* @package report_completion
|
||||
* @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class user_report_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('eventuserreportviewed', 'report_completion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'The user with id ' . $this->userid . ' viewed user log report for user with id ' . $this->relateduserid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
$url = 'report/completion/user.php?id=' . $this->relateduserid . '&course=' . $this->courseid;
|
||||
return array($this->courseid, 'course', 'report completion', $url, $this->courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/report/completion/user.php', array('course' => $this->courseid, 'id' => $this->relateduserid));
|
||||
}
|
||||
|
||||
/**
|
||||
* custom validations.
|
||||
*
|
||||
* @throws \coding_exception when validation fails.
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
if ($this->contextlevel != CONTEXT_COURSE) {
|
||||
throw new \coding_exception('Context passed must be course context.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -746,3 +746,7 @@ print '<li><a href="'.$excelurl->out().'">'.get_string('excelcsvdownload','compl
|
||||
print '</ul>';
|
||||
|
||||
echo $OUTPUT->footer($course);
|
||||
|
||||
// Trigger a report viewed event.
|
||||
$event = \report_completion\event\report_viewed::create(array('context' => $context));
|
||||
$event->trigger();
|
||||
|
@ -32,3 +32,5 @@ $string['page-report-completion-x'] = 'Any completion report';
|
||||
$string['page-report-completion-index'] = 'Course completion report';
|
||||
$string['page-report-completion-user'] = 'User course completion report';
|
||||
$string['pluginname'] = 'Course completion';
|
||||
$string['eventreportviewed'] = 'Completion report viewed';
|
||||
$string['eventuserreportviewed'] = 'Completion user report viewed';
|
||||
|
99
report/completion/tests/events_test.php
Normal file
99
report/completion/tests/events_test.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?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 report completion events.
|
||||
*
|
||||
* @package report_completion
|
||||
* @copyright 2014 onwards Ankit Agarwal<ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class report_completion_events_testcase
|
||||
*
|
||||
* Class for tests related to completion report events.
|
||||
*
|
||||
* @package report_completion
|
||||
* @copyright 2014 onwards Ankit Agarwal<ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class report_completion_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Setup testcase.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->setAdminUser();
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the report viewed event.
|
||||
*
|
||||
* It's not possible to use the moodle API to simulate the viewing of log report, so here we
|
||||
* simply create the event and trigger it.
|
||||
*/
|
||||
public function test_report_viewed() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
// Trigger event for completion report viewed.
|
||||
$event = \report_completion\event\report_viewed::create(array('context' => $context));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
$this->assertInstanceOf('\report_completion\event\report_viewed', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/report/completion/index.php', array('course' => $course->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user report viewed event.
|
||||
*
|
||||
* It's not possible to use the moodle API to simulate the viewing of log report, so here we
|
||||
* simply create the event and trigger it.
|
||||
*/
|
||||
public function test_user_report_viewed() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
// Trigger event for completion report viewed.
|
||||
$event = \report_completion\event\user_report_viewed::create(array('context' => $context, 'relateduserid' => 3));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
$this->assertInstanceOf('\report_completion\event\user_report_viewed', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$this->assertEquals(3, $event->relateduserid);
|
||||
$this->assertEquals(new moodle_url('/report/completion/user.php', array('id' => 3, 'course' => $course->id)),
|
||||
$event->get_url());
|
||||
$expected = array($course->id, 'course', 'report completion', "report/completion/user.php?id=3&course=$course->id",
|
||||
$course->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
}
|
@ -50,8 +50,6 @@ if (!report_completion_can_access_user_report($user, $course, true)) {
|
||||
error('Can not access user completion report');
|
||||
}
|
||||
|
||||
add_to_log($course->id, 'course', 'report completion', "report/completion/user.php?id=$user->id&course=$course->id", $course->id);
|
||||
|
||||
$stractivityreport = get_string('activityreport');
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
@ -301,3 +299,6 @@ foreach ($courses as $type => $infos) {
|
||||
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
// Trigger a user report viewed event.
|
||||
$event = \report_completion\event\user_report_viewed::create(array('context' => $coursecontext, 'relateduserid' => $userid));
|
||||
$event->trigger();
|
||||
|
Loading…
x
Reference in New Issue
Block a user