MDL-36003 events: Added events for viewing grade reports.
authorAdrian Greeve <adrian@moodle.com>
Fri, 13 Jun 2014 08:03:54 +0000 (16:03 +0800)
committerAdrian Greeve <adrian@moodle.com>
Mon, 23 Jun 2014 03:59:35 +0000 (11:59 +0800)
16 files changed:
grade/report/grader/classes/event/report_viewed.php [new file with mode: 0644]
grade/report/grader/index.php
grade/report/grader/lang/en/gradereport_grader.php
grade/report/outcomes/classes/event/report_viewed.php [new file with mode: 0644]
grade/report/outcomes/index.php
grade/report/outcomes/lang/en/gradereport_outcomes.php
grade/report/overview/classes/event/report_viewed.php [new file with mode: 0644]
grade/report/overview/index.php
grade/report/overview/lang/en/gradereport_overview.php
grade/report/user/classes/event/report_viewed.php [new file with mode: 0644]
grade/report/user/index.php
grade/report/user/lang/en/gradereport_user.php
lang/en/grades.php
lib/classes/event/grade_report_viewed.php [new file with mode: 0644]
lib/tests/events_test.php
lib/tests/fixtures/event_fixtures.php

diff --git a/grade/report/grader/classes/event/report_viewed.php b/grade/report/grader/classes/event/report_viewed.php
new file mode 100644 (file)
index 0000000..7d18f3d
--- /dev/null
@@ -0,0 +1,47 @@
+<?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/>.
+
+/**
+ * Grader report viewed event.
+ *
+ * @package    gradereport_grader
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace gradereport_grader\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Grader report viewed event class.
+ *
+ * @package    gradereport_grader
+ * @since      Moodle 2.8
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class report_viewed extends \core\event\grade_report_viewed {
+
+    /**
+     * Returns localised general event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventreportviewed', 'gradereport_grader');
+    }
+}
index e1c2b9f..adaccf6 100644 (file)
@@ -125,6 +125,14 @@ if (!empty($target) && !empty($action) && confirm_sesskey()) {
 
 $reportname = get_string('pluginname', 'gradereport_grader');
 
+$event = \gradereport_grader\event\report_viewed::create(
+    array(
+        'context' => $context,
+        'courseid' => $courseid,
+    )
+);
+$event->trigger();
+
 // Print header
 print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons);
 
index ce3aa73..5507d64 100644 (file)
@@ -28,6 +28,7 @@ $string['ajaxerror'] = 'Error';
 $string['ajaxfailedupdate'] = 'Unable to update [1] for [2]';
 $string['ajaxfieldchanged'] = 'The field you are currently editing has changed, would you like to use the updated value?';
 $string['ajaxchoosescale'] = 'Choose';
+$string['eventreportviewed'] = 'Grader report viewed';
 $string['grader:manage'] = 'Manage the grader report';
 $string['grader:view'] = 'View the grader report';
 $string['pluginname'] = 'Grader report';
diff --git a/grade/report/outcomes/classes/event/report_viewed.php b/grade/report/outcomes/classes/event/report_viewed.php
new file mode 100644 (file)
index 0000000..7f226cd
--- /dev/null
@@ -0,0 +1,47 @@
+<?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/>.
+
+/**
+ * Outcomes report viewed event.
+ *
+ * @package    gradereport_outcomes
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace gradereport_outcomes\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Outcomes report viewed event class.
+ *
+ * @package    gradereport_outcomes
+ * @since      Moodle 2.8
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class report_viewed extends \core\event\grade_report_viewed {
+
+    /**
+     * Returns localised general event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventreportviewed', 'gradereport_outcomes');
+    }
+}
index 73729d8..03f7fd3 100644 (file)
@@ -170,7 +170,13 @@ foreach ($report_info as $outcomeid => $outcomedata) {
     $row++;
 }
 
-
+$event = \gradereport_outcomes\event\report_viewed::create(
+    array(
+        'context' => $context,
+        'courseid' => $courseid,
+    )
+);
+$event->trigger();
 
 $html .= '</table>';
 
index 9cc0633..015403b 100644 (file)
@@ -26,6 +26,7 @@
 $string['addoutcome'] = 'Add an outcome';
 $string['courseoutcomes'] = 'Course outcomes';
 $string['coursespecoutcome'] = 'Course outcomes';
+$string['eventreportviewed'] = 'Outcomes report viewed';
 $string['pluginname'] = 'Outcomes report';
 $string['outcomes:view'] = 'View the outcomes report';
 $string['usedgradeitem'] = 'Number of grade items';
diff --git a/grade/report/overview/classes/event/report_viewed.php b/grade/report/overview/classes/event/report_viewed.php
new file mode 100644 (file)
index 0000000..0702d9f
--- /dev/null
@@ -0,0 +1,60 @@
+<?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/>.
+
+/**
+ * Overview report viewed event.
+ *
+ * @package    gradereport_overview
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace gradereport_overview\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Overview report viewed event class.
+ *
+ * @package    gradereport_overview
+ * @since      Moodle 2.8
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class report_viewed extends \core\event\grade_report_viewed {
+
+    /**
+     * Returns localised general event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventreportviewed', 'gradereport_overview');
+    }
+
+    /**
+     * Custom validation.
+     *
+     * Throw \coding_exception notice in case of any problems.
+     */
+    protected function validate_data() {
+        parent::validate_data();
+
+        if (!isset($this->relateduserid)) {
+            throw new \coding_exception('The \'relateduserid\' value must be set.');
+        }
+    }
+}
index baae232..51f2aa1 100644 (file)
@@ -148,6 +148,15 @@ if (has_capability('moodle/grade:viewall', $systemcontext)) { //Admins will see
     }
 }
 
+$event = \gradereport_overview\event\report_viewed::create(
+    array(
+        'context' => $context,
+        'courseid' => $courseid,
+        'relateduserid' => $userid,
+    )
+);
+$event->trigger();
+
 echo $OUTPUT->footer();
 
 
index 7829783..fd6fb8c 100644 (file)
@@ -22,5 +22,6 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+$string['eventreportviewed'] = 'Overview report viewed';
 $string['pluginname'] = 'Overview report';
 $string['overview:view'] = 'View the overview report';
diff --git a/grade/report/user/classes/event/report_viewed.php b/grade/report/user/classes/event/report_viewed.php
new file mode 100644 (file)
index 0000000..93d9c00
--- /dev/null
@@ -0,0 +1,60 @@
+<?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/>.
+
+/**
+ * User report viewed event.
+ *
+ * @package    gradereport_user
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace gradereport_user\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * User report viewed event class.
+ *
+ * @package    gradereport_user
+ * @since      Moodle 2.8
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class report_viewed extends \core\event\grade_report_viewed {
+
+    /**
+     * Returns localised general event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventreportviewed', 'gradereport_user');
+    }
+
+    /**
+     * Custom validation.
+     *
+     * Throw \coding_exception notice in case of any problems.
+     */
+    protected function validate_data() {
+        parent::validate_data();
+
+        if (!isset($this->relateduserid)) {
+            throw new \coding_exception('The \'relateduserid\' value must be set.');
+        }
+    }
+}
index 587233b..3e8e3fd 100644 (file)
@@ -164,4 +164,13 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
     }
 }
 
+$event = \gradereport_user\event\report_viewed::create(
+    array(
+        'context' => $context,
+        'courseid' => $courseid,
+        'relateduserid' => $userid,
+    )
+);
+$event->trigger();
+
 echo $OUTPUT->footer();
index 73c2474..56f6c1a 100644 (file)
@@ -22,6 +22,7 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+$string['eventreportviewed'] = 'User grade report viewed';
 $string['pluginname'] = 'User report';
 $string['user:view'] = 'View your own grade report';
 $string['tablesummary'] = 'The table is arranged as a list of graded items including categories of graded items. When items are in a category they will be indicated as such.';
index 9ea00eb..e1c76b3 100644 (file)
@@ -186,6 +186,7 @@ $string['errorupdatinggradecategoryaggregateoutcomes'] = 'Error updating the "In
 $string['errorupdatinggradecategoryaggregatesubcats'] = 'Error updating the "Aggregate including subcategories" setting of grade category ID {$a->id}';
 $string['errorupdatinggradecategoryaggregation'] = 'Error updating the aggregation type of grade category ID {$a->id}';
 $string['errorupdatinggradeitemaggregationcoef'] = 'Error updating the aggregation coefficient (weight or extra credit) of grade item ID {$a->id}';
+$string['eventgradeviewed'] = 'Grades were viewed in the gradebook';
 $string['eventusergraded'] = 'User grade edited in gradebook';
 $string['excluded'] = 'Excluded';
 $string['excluded_help'] = 'If ticked, the grade will not be included in any aggregation.';
diff --git a/lib/classes/event/grade_report_viewed.php b/lib/classes/event/grade_report_viewed.php
new file mode 100644 (file)
index 0000000..5356a50
--- /dev/null
@@ -0,0 +1,89 @@
+<?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/>.
+
+/**
+ * Grade report viewed event.
+ *
+ * @package    core
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Grade report viewed event class.
+ *
+ * @package    core
+ * @since      Moodle 2.8
+ * @copyright  2014 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class grade_report_viewed extends base {
+
+    /** string $reporttype The report type being viewed. */
+    protected $reporttype;
+
+    /**
+     * Initialise the event data.
+     */
+    protected function init() {
+        $reporttype = explode('\\', $this->eventname);
+        $shorttype = explode('_', $reporttype[1]);
+        $this->reporttype = $shorttype[1];
+
+        $this->data['crud'] = 'r';
+        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
+    }
+
+    /**
+     * Returns localised general event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventgradeviewed', 'grades');
+    }
+
+    /**
+     * Returns non-localised description of what happened.
+     *
+     * @return string
+     */
+    public function get_description() {
+        return "The user with id '$this->userid' viewed the $this->reporttype report in the gradebook.";
+    }
+
+    /**
+     * Returns relevant URL.
+     * @return \moodle_url
+     */
+    public function get_url() {
+        $url = '/grade/report/' . $this->reporttype . '/index.php';
+        return new \moodle_url($url, array('id' => $this->courseid));
+    }
+
+    /**
+     * Custom validation.
+     *
+     * To be overwritten by child classes.
+     */
+    protected function validate_data() {
+        parent::validate_data();
+    }
+}
index 06fbdb6..baaa9e2 100644 (file)
@@ -25,6 +25,8 @@
 
 defined('MOODLE_INTERNAL') || die();
 
+require_once(__DIR__.'/fixtures/event_fixtures.php');
+
 class core_events_testcase extends advanced_testcase {
 
     /**
@@ -338,4 +340,35 @@ class core_events_testcase extends advanced_testcase {
         $this->assertEventLegacyLogData($expected, $event);
         $this->assertEventContextNotUsed($event);
     }
+
+    /**
+     * There is no API associated with this event, so we will just test standard features.
+     */
+    public function test_grade_viewed() {
+        $this->resetAfterTest();
+        $this->setAdminUser();
+
+        $user = $this->getDataGenerator()->create_user();
+        $course = $this->getDataGenerator()->create_course();
+        $coursecontext = context_course::instance($course->id);
+
+        $event = \core_tests\event\grade_report_viewed::create(
+            array(
+                'context' => $coursecontext,
+                'courseid' => $course->id,
+                'userid' => $user->id,
+            )
+        );
+
+        // Trigger and capture the event.
+        $sink = $this->redirectEvents();
+        $event->trigger();
+        $events = $sink->get_events();
+        $event = reset($events);
+
+        $this->assertInstanceOf('\core\event\grade_report_viewed', $event);
+        $this->assertEquals($event->courseid, $course->id);
+        $this->assertEquals($event->userid, $user->id);
+        $this->assertEventContextNotUsed($event);
+    }
 }
index 58cf2ab..e13c2d8 100644 (file)
@@ -250,6 +250,12 @@ class course_module_viewed extends \core\event\course_module_viewed {
 class course_module_viewed_noinit extends \core\event\course_module_viewed {
 }
 
+/**
+ * Event for testing core\event\grade_report_viewed.
+ */
+class grade_report_viewed extends \core\event\grade_report_viewed {
+}
+
 /**
  * Event to test context used in event functions
  */