Browse Source

Add updated event for per-student reports from view.php, and use it,

moving from internal viewed event to the one Dan integrated at the same
time.
Need to re-look at event validation and possibly-optional params per Dan's
changes to mode param.
nwp90-nwp90-allsessionsreport
Nick Phillips 5 years ago
committed by Dan Marsden
parent
commit
19bb084686
  1. 61
      classes/event/session_report_updated.php
  2. 12
      classes/event/session_report_viewed.php
  3. 2
      classes/structure.php
  4. 1
      lang/en/attendance.php
  5. 15
      renderables.php
  6. 29
      view.php

61
classes/event/session_report_updated.php

@ -0,0 +1,61 @@
<?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/>.
/**
* This file contains an event for when a student's attendance report is viewed.
*
* @package mod_attendance
* @copyright 2014 onwards Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_attendance\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a student's attendance report is updated.
*
* @property-read array $other {
* Extra information about event properties.
*
* string studentid Id of student whose attendances were updated.
* string mode Mode of the report updated.
* }
* @package mod_attendance
* @since Moodle 2.7
* @copyright 2013 onwards Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class session_report_updated extends \mod_attendance\event\session_report_viewed {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
// objecttable and objectid can't be meaningfully specified
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventstudentattendancesessionsupdated', 'mod_attendance');
}
}

12
classes/event/session_report_viewed.php

@ -55,7 +55,7 @@ class session_report_viewed extends \core\event\base {
* @return string * @return string
*/ */
public function get_description() { public function get_description() {
return 'User with id ' . $this->userid . ' viewed attendance sessions for student with id ' . return 'User with id ' . $this->userid . ' ' . $this->action . ' attendance sessions for student with id ' .
$this->relateduserid; $this->relateduserid;
} }
@ -80,6 +80,8 @@ class session_report_viewed extends \core\event\base {
'studentid' => $this->relateduserid, 'studentid' => $this->relateduserid,
'mode' => $mode, 'mode' => $mode,
'view' => $this->other['view'], 'view' => $this->other['view'],
'groupby' => $this->other['groupby'],
'sesscourses' => $this->other['sesscourses'],
'curdate' => $this->other['curdate'])); 'curdate' => $this->other['curdate']));
} }
@ -89,7 +91,7 @@ class session_report_viewed extends \core\event\base {
* @return array of parameters to be passed to legacy add_to_log() function. * @return array of parameters to be passed to legacy add_to_log() function.
*/ */
protected function get_legacy_logdata() { protected function get_legacy_logdata() {
return array($this->courseid, 'attendance', 'student sessions viewed', $this->get_url(), return array($this->courseid, 'attendance', 'student sessions ' . $this->action, $this->get_url(),
'student id ' . $this->relateduserid, $this->contextinstanceid); 'student id ' . $this->relateduserid, $this->contextinstanceid);
} }
@ -119,17 +121,17 @@ class session_report_viewed extends \core\event\base {
*/ */
protected function validate_data() { protected function validate_data() {
if (!isset($this->relateduserid)) { if (!isset($this->relateduserid)) {
throw new \coding_exception('The event mod_attendance\\event\\session_report_viewed must specify relateduserid.'); throw new \coding_exception('The event ' . $this->eventname . ' must specify relateduserid.');
} }
// View params can be left out as defaults will be the same when log event is viewed as when // View params can be left out as defaults will be the same when log event is viewed as when
// it was stored. // it was stored.
// filter params are important, but stored in session so default effectively unknown, // filter params are important, but stored in session so default effectively unknown,
// hence required here. // hence required here.
if (!isset($this->other['view'])) { if (!isset($this->other['view'])) {
throw new \coding_exception('The event mod_attendance\\event\\session_report_viewed must specify view.'); throw new \coding_exception('The event ' . $this->eventname . ' must specify view.');
} }
if (!isset($this->other['curdate'])) { if (!isset($this->other['curdate'])) {
throw new \coding_exception('The event mod_attendance\\event\\session_report_viewed must specify curdate.'); throw new \coding_exception('The event ' . $this->eventname . ' must specify curdate.');
} }
parent::validate_data(); parent::validate_data();
} }

2
classes/structure.php

@ -114,7 +114,7 @@ class mod_attendance_structure {
* @param stdClass $dbrecord Attandance instance data from {attendance} table * @param stdClass $dbrecord Attandance instance data from {attendance} table
* @param stdClass $cm Course module record as returned by {@see get_coursemodule_from_id()} * @param stdClass $cm Course module record as returned by {@see get_coursemodule_from_id()}
* @param stdClass $course Course record from {course} table * @param stdClass $course Course record from {course} table
* @param stdClass $context The context of the workshop instance * @param stdClass $context The context of the attendance instance
* @param stdClass $pageparams * @param stdClass $pageparams
*/ */
public function __construct(stdClass $dbrecord, stdClass $cm, stdClass $course, stdClass $context=null, $pageparams=null) { public function __construct(stdClass $dbrecord, stdClass $cm, stdClass $course, stdClass $context=null, $pageparams=null) {

1
lang/en/attendance.php

@ -236,6 +236,7 @@ $string['eventsessionupdated'] = 'Session updated';
$string['eventstatusadded'] = 'Status added'; $string['eventstatusadded'] = 'Status added';
$string['eventstatusupdated'] = 'Status updated'; $string['eventstatusupdated'] = 'Status updated';
$string['eventstudentattendancesessionsviewed'] = 'Session report viewed'; $string['eventstudentattendancesessionsviewed'] = 'Session report viewed';
$string['eventstudentattendancesessionsupdated'] = 'Session report updated';
$string['eventtaken'] = 'Attendance taken'; $string['eventtaken'] = 'Attendance taken';
$string['eventtakenbystudent'] = 'Attendance taken by student'; $string['eventtakenbystudent'] = 'Attendance taken by student';
$string['export'] = 'Export'; $string['export'] = 'Export';

15
renderables.php

@ -571,8 +571,6 @@ class attendance_user_data implements renderable {
// TODO: WARNING - $formdata is unclean - comes from direct $_POST - ideally needs a rewrite but we do some cleaning below. // TODO: WARNING - $formdata is unclean - comes from direct $_POST - ideally needs a rewrite but we do some cleaning below.
// This whole function could do with a nice clean up. // This whole function could do with a nice clean up.
// XXX - replace this, see below
//$statuses = implode(',', array_keys( (array)$this->get_statuses() ));
$now = time(); $now = time();
$sesslog = array(); $sesslog = array();
$formdata = (array)$formdata; $formdata = (array)$formdata;
@ -671,20 +669,7 @@ class attendance_user_data implements renderable {
} }
} }
} }
// Create url for link in log screen.
$params = $this->pageparams->get_significant_params();
// XXX - TODO
// Waiting for event for viewing user report(s) before creating derived event for editing.
/* $event = \mod_attendance\event\attendance_taken::create(array( */
/* 'objectid' => $this->id, */
/* 'context' => $this->context, */
/* 'other' => $params)); */
/* $event->add_record_snapshot('course_modules', $this->cm); */
/* $event->add_record_snapshot('attendance_sessions', $session); */
/* $event->trigger(); */
} }
} }
/** /**

29
view.php

@ -84,27 +84,38 @@ $filterparams = array(
'enddate' => $userdata->pageparams->enddate 'enddate' => $userdata->pageparams->enddate
); );
$params = array_merge($userdata->pageparams->get_significant_params(), $filterparams); $params = array_merge($userdata->pageparams->get_significant_params(), $filterparams);
$header = new mod_attendance_header($att);
if (empty($userdata->pageparams->studentid)) { if (empty($userdata->pageparams->studentid)) {
$relateduserid = $USER->id; $relateduserid = $USER->id;
} else { } else {
$relateduserid = $userdata->pageparams->studentid; $relateduserid = $userdata->pageparams->studentid;
} }
// Trigger viewed event. if (($formdata = data_submitted()) && confirm_sesskey()) {
$event = \mod_attendance\event\session_report_viewed::create(array( $userdata->take_sessions_from_form_data($formdata);
// Trigger updated event
$event = \mod_attendance\event\session_report_updated::create(array(
'relateduserid' => $relateduserid, 'relateduserid' => $relateduserid,
'context' => $context, 'context' => $context,
'other' => $params)); 'other' => $params));
$event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course_modules', $cm);
$event->trigger(); //$event->add_record_snapshot('user', $);
$event->trigger();
$header = new mod_attendance_header($att);
if (($formdata = data_submitted()) && confirm_sesskey()) {
$userdata->take_sessions_from_form_data($formdata);
redirect($url, get_string('attendancesuccess', 'attendance')); redirect($url, get_string('attendancesuccess', 'attendance'));
} }
else {
// Trigger viewed event
$event = \mod_attendance\event\session_report_viewed::create(array(
'relateduserid' => $relateduserid,
'context' => $context,
'other' => $params));
$event->add_record_snapshot('course_modules', $cm);
$event->trigger();
}
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);

Loading…
Cancel
Save