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
*/
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;
}
@ -80,6 +80,8 @@ class session_report_viewed extends \core\event\base {
'studentid' => $this->relateduserid,
'mode' => $mode,
'view' => $this->other['view'],
'groupby' => $this->other['groupby'],
'sesscourses' => $this->other['sesscourses'],
'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.
*/
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);
}
@ -119,17 +121,17 @@ class session_report_viewed extends \core\event\base {
*/
protected function validate_data() {
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
// it was stored.
// filter params are important, but stored in session so default effectively unknown,
// hence required here.
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'])) {
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();
}

2
classes/structure.php

@ -114,7 +114,7 @@ class mod_attendance_structure {
* @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 $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
*/
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['eventstatusupdated'] = 'Status updated';
$string['eventstudentattendancesessionsviewed'] = 'Session report viewed';
$string['eventstudentattendancesessionsupdated'] = 'Session report updated';
$string['eventtaken'] = 'Attendance taken';
$string['eventtakenbystudent'] = 'Attendance taken by student';
$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.
// 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();
$sesslog = array();
$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
);
$params = array_merge($userdata->pageparams->get_significant_params(), $filterparams);
$header = new mod_attendance_header($att);
if (empty($userdata->pageparams->studentid)) {
$relateduserid = $USER->id;
} else {
$relateduserid = $userdata->pageparams->studentid;
}
// Trigger viewed event.
$event = \mod_attendance\event\session_report_viewed::create(array(
if (($formdata = data_submitted()) && confirm_sesskey()) {
$userdata->take_sessions_from_form_data($formdata);
// Trigger updated event
$event = \mod_attendance\event\session_report_updated::create(array(
'relateduserid' => $relateduserid,
'context' => $context,
'other' => $params));
$event->add_record_snapshot('course_modules', $cm);
$event->trigger();
$header = new mod_attendance_header($att);
if (($formdata = data_submitted()) && confirm_sesskey()) {
$userdata->take_sessions_from_form_data($formdata);
$event->add_record_snapshot('course_modules', $cm);
//$event->add_record_snapshot('user', $);
$event->trigger();
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_heading($course->fullname);

Loading…
Cancel
Save