Browse Source

Fixes #214 use correct prefix on attendance functions to avoid clashing with other code.

MOODLE_31_STABLE
Dan Marsden 8 years ago
parent
commit
b484162c72
  1. 14
      classes/calendar_helpers.php
  2. 10
      classes/structure.php
  3. 2
      db/upgrade.php
  4. 2
      db/upgradelib.php
  5. 12
      lib.php
  6. 6
      sessions.php

14
classes/calendar_helpers.php

@ -29,7 +29,7 @@ require_once(dirname(__FILE__).'/../../../calendar/lib.php');
* @param stdClass $session initial sessions to take data from * @param stdClass $session initial sessions to take data from
* @return bool result of calendar event creation * @return bool result of calendar event creation
*/ */
function create_calendar_event(&$session) { function attendance_create_calendar_event(&$session) {
// We don't want to create multiple calendar events for 1 session. // We don't want to create multiple calendar events for 1 session.
if ($session->caleventid) { if ($session->caleventid) {
return $session->caleventid; return $session->caleventid;
@ -64,12 +64,12 @@ function create_calendar_event(&$session) {
* *
* @param array %sessionsids array of sessions ids * @param array %sessionsids array of sessions ids
*/ */
function create_calendar_events($sessionsids) { function attendance_create_calendar_events($sessionsids) {
global $DB; global $DB;
$sessions = $DB->get_recordset_list('attendance_sessions', 'id', $sessionsids); $sessions = $DB->get_recordset_list('attendance_sessions', 'id', $sessionsids);
foreach ($sessions as $session) { foreach ($sessions as $session) {
create_calendar_event($session); attendance_create_calendar_event($session);
if ($session->caleventid) { if ($session->caleventid) {
$DB->update_record('attendance_sessions', $session); $DB->update_record('attendance_sessions', $session);
} }
@ -84,7 +84,7 @@ function create_calendar_events($sessionsids) {
* @param $timestart int start time of the event * @param $timestart int start time of the event
* @return bool result of updating * @return bool result of updating
*/ */
function update_calendar_event($caleventid, $timeduration, $timestart) { function attendance_update_calendar_event($caleventid, $timeduration, $timestart = null) {
$caleventdata = new stdClass(); $caleventdata = new stdClass();
$caleventdata->timeduration = $timeduration; $caleventdata->timeduration = $timeduration;
$caleventdata->timestart = $timestart; $caleventdata->timestart = $timestart;
@ -104,9 +104,9 @@ function update_calendar_event($caleventid, $timeduration, $timestart) {
* @param array %sessionsids array of sessions ids * @param array %sessionsids array of sessions ids
* @return bool result of updating * @return bool result of updating
*/ */
function delete_calendar_events($sessionsids) { function attendance_delete_calendar_events($sessionsids) {
global $DB; global $DB;
$caleventsids = existing_calendar_events_ids($sessionsids); $caleventsids = attendance_existing_calendar_events_ids($sessionsids);
if ($caleventsids) { if ($caleventsids) {
$DB->delete_records_list('event', 'id', $caleventsids); $DB->delete_records_list('event', 'id', $caleventsids);
} }
@ -124,7 +124,7 @@ function delete_calendar_events($sessionsids) {
* @param array $sessionsids of sessions ids * @param array $sessionsids of sessions ids
* @return array | bool array of existing calendar events or false if none found * @return array | bool array of existing calendar events or false if none found
*/ */
function existing_calendar_events_ids($sessionsids) { function attendance_existing_calendar_events_ids($sessionsids) {
global $DB; global $DB;
$caleventsids = array_keys($DB->get_records_list('attendance_sessions', 'id', $sessionsids, '', 'caleventid')); $caleventsids = array_keys($DB->get_records_list('attendance_sessions', 'id', $sessionsids, '', 'caleventid'));
$existingcaleventsids = array_filter($caleventsids); $existingcaleventsids = array_filter($caleventsids);

10
classes/structure.php

@ -361,7 +361,7 @@ class mod_attendance_structure {
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id)); $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
$sess->caleventid = 0; $sess->caleventid = 0;
create_calendar_event($sess); attendance_create_calendar_event($sess);
$infoarray = array(); $infoarray = array();
$infoarray[] = construct_session_full_date_time($sess->sessdate, $sess->duration); $infoarray[] = construct_session_full_date_time($sess->sessdate, $sess->duration);
@ -404,7 +404,7 @@ class mod_attendance_structure {
$sess->timemodified = time(); $sess->timemodified = time();
$DB->update_record('attendance_sessions', $sess); $DB->update_record('attendance_sessions', $sess);
update_calendar_event($sess->caleventid, $sess->duration, $sess->sessdate); attendance_update_calendar_event($sess->caleventid, $sess->duration, $sess->sessdate);
$info = construct_session_full_date_time($sess->sessdate, $sess->duration); $info = construct_session_full_date_time($sess->sessdate, $sess->duration);
$event = \mod_attendance\event\session_updated::create(array( $event = \mod_attendance\event\session_updated::create(array(
@ -900,8 +900,8 @@ class mod_attendance_structure {
public function delete_sessions($sessionsids) { public function delete_sessions($sessionsids) {
global $DB; global $DB;
if (existing_calendar_events_ids($sessionsids)) { if (attendance_existing_calendar_events_ids($sessionsids)) {
delete_calendar_events($sessionsids); attendance_delete_calendar_events($sessionsids);
} }
list($sql, $params) = $DB->get_in_or_equal($sessionsids); list($sql, $params) = $DB->get_in_or_equal($sessionsids);
@ -925,7 +925,7 @@ class mod_attendance_structure {
$sess->timemodified = $now; $sess->timemodified = $now;
$DB->update_record('attendance_sessions', $sess); $DB->update_record('attendance_sessions', $sess);
if ($sess->caleventid) { if ($sess->caleventid) {
update_calendar_event($sess->caleventid, $duration, $sess->sessdate); attendance_update_calendar_event($sess->caleventid, $duration);
} }
$event = \mod_attendance\event\session_duration_updated::create(array( $event = \mod_attendance\event\session_duration_updated::create(array(
'objectid' => $this->id, 'objectid' => $this->id,

2
db/upgrade.php

@ -171,7 +171,7 @@ function xmldb_attendance_upgrade($oldversion=0) {
} }
// Creating events for all existing sessions. // Creating events for all existing sessions.
create_calendar_events(); attendance_upgrade_create_calendar_events();
// Attendance savepoint reached. // Attendance savepoint reached.
upgrade_mod_savepoint(true, 2016052202, 'attendance'); upgrade_mod_savepoint(true, 2016052202, 'attendance');

2
db/upgradelib.php

@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
function create_calendar_events() { function attendance_upgrade_create_calendar_events() {
global $DB; global $DB;
$attendances = $DB->get_records('attendance', null, null, 'id, name, course'); $attendances = $DB->get_records('attendance', null, null, 'id, name, course');

12
lib.php

@ -104,8 +104,8 @@ function attendance_delete_instance($id) {
} }
if ($sessids = array_keys($DB->get_records('attendance_sessions', array('attendanceid' => $id), '', 'id'))) { if ($sessids = array_keys($DB->get_records('attendance_sessions', array('attendanceid' => $id), '', 'id'))) {
if (existing_calendar_events_ids($sessids)) { if (attendance_existing_calendar_events_ids($sessids)) {
delete_calendar_events($sessids); attendance_delete_calendar_events($sessids);
} }
$DB->delete_records_list('attendance_log', 'sessionid', $sessids); $DB->delete_records_list('attendance_log', 'sessionid', $sessids);
$DB->delete_records('attendance_sessions', array('attendanceid' => $id)); $DB->delete_records('attendance_sessions', array('attendanceid' => $id));
@ -124,8 +124,8 @@ function attendance_delete_course($course, $feedback=true) {
$attids = array_keys($DB->get_records('attendance', array('course' => $course->id), '', 'id')); $attids = array_keys($DB->get_records('attendance', array('course' => $course->id), '', 'id'));
$sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id')); $sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'));
if (existing_calendar_events_ids($sessids)) { if (attendance_existing_calendar_events_ids($sessids)) {
delete_calendar_events($sessids); attendance_delete_calendar_events($sessids);
} }
if ($sessids) { if ($sessids) {
$DB->delete_records_list('attendance_log', 'sessionid', $sessids); $DB->delete_records_list('attendance_log', 'sessionid', $sessids);
@ -203,8 +203,8 @@ function attendance_reset_userdata($data) {
if (!empty($data->reset_attendance_sessions)) { if (!empty($data->reset_attendance_sessions)) {
$sessionsids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id')); $sessionsids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'));
if (existing_calendar_events_ids($sessionsids)) { if (attendance_existing_calendar_events_ids($sessionsids)) {
delete_calendar_events($sessionsids); attendance_delete_calendar_events($sessionsids);
} }
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); $DB->delete_records_list('attendance_sessions', 'attendanceid', $attids);

6
sessions.php

@ -143,6 +143,12 @@ switch ($att->pageparams->action) {
$att->delete_sessions($sessionsids); $att->delete_sessions($sessionsids);
attendance_update_users_grade($att); attendance_update_users_grade($att);
redirect($att->url_manage(), get_string('sessiondeleted', 'attendance')); redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} else if ($att->pageparams->action == mod_attendance_sessions_page_params::ACTION_CREATE_CAL_EVENTS) {
attendance_create_calendar_events($sessionsids);
redirect($att->url_manage(), get_string('createcheckcalevents', 'attendance'));
} else if ($att->pageparams->action == mod_attendance_sessions_page_params::ACTION_DELETE_CAL_EVENTS) {
attendance_delete_calendar_events($sessionsids);
redirect($att->url_manage(), get_string('deletecheckcalevents', 'attendance'));
} }
} }
$sessid = optional_param_array('sessid', '', PARAM_SEQUENCE); $sessid = optional_param_array('sessid', '', PARAM_SEQUENCE);

Loading…
Cancel
Save