Browse Source

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

MOODLE_32_STABLE
Dan Marsden 8 years ago
parent
commit
fb85d3c5bc
  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. 4
      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
* @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.
if ($session->caleventid) {
return $session->caleventid;
@ -64,12 +64,12 @@ function create_calendar_event(&$session) {
*
* @param array %sessionsids array of sessions ids
*/
function create_calendar_events($sessionsids) {
function attendance_create_calendar_events($sessionsids) {
global $DB;
$sessions = $DB->get_recordset_list('attendance_sessions', 'id', $sessionsids);
foreach ($sessions as $session) {
create_calendar_event($session);
attendance_create_calendar_event($session);
if ($session->caleventid) {
$DB->update_record('attendance_sessions', $session);
}
@ -84,7 +84,7 @@ function create_calendar_events($sessionsids) {
* @param $timestart int start time of the event
* @return bool result of updating
*/
function update_calendar_event($caleventid, $timeduration, $timestart = null) {
function attendance_update_calendar_event($caleventid, $timeduration, $timestart = null) {
$caleventdata = new stdClass();
$caleventdata->timeduration = $timeduration;
$caleventdata->timestart = $timestart;
@ -104,9 +104,9 @@ function update_calendar_event($caleventid, $timeduration, $timestart = null) {
* @param array %sessionsids array of sessions ids
* @return bool result of updating
*/
function delete_calendar_events($sessionsids) {
function attendance_delete_calendar_events($sessionsids) {
global $DB;
$caleventsids = existing_calendar_events_ids($sessionsids);
$caleventsids = attendance_existing_calendar_events_ids($sessionsids);
if ($caleventsids) {
$DB->delete_records_list('event', 'id', $caleventsids);
}
@ -124,7 +124,7 @@ function delete_calendar_events($sessionsids) {
* @param array $sessionsids of sessions ids
* @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;
$caleventsids = array_keys($DB->get_records_list('attendance_sessions', 'id', $sessionsids, '', 'caleventid'));
$existingcaleventsids = array_filter($caleventsids);

10
classes/structure.php

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

2
db/upgrade.php

@ -171,7 +171,7 @@ function xmldb_attendance_upgrade($oldversion=0) {
}
// Creating events for all existing sessions.
create_calendar_events();
attendance_upgrade_create_calendar_events();
// Attendance savepoint reached.
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
*/
function create_calendar_events() {
function attendance_upgrade_create_calendar_events() {
global $DB;
$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 (existing_calendar_events_ids($sessids)) {
delete_calendar_events($sessids);
if (attendance_existing_calendar_events_ids($sessids)) {
attendance_delete_calendar_events($sessids);
}
$DB->delete_records_list('attendance_log', 'sessionid', $sessids);
$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'));
$sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'));
if (existing_calendar_events_ids($sessids)) {
delete_calendar_events($sessids);
if (attendance_existing_calendar_events_ids($sessids)) {
attendance_delete_calendar_events($sessids);
}
if ($sessids) {
$DB->delete_records_list('attendance_log', 'sessionid', $sessids);
@ -203,8 +203,8 @@ function attendance_reset_userdata($data) {
if (!empty($data->reset_attendance_sessions)) {
$sessionsids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'));
if (existing_calendar_events_ids($sessionsids)) {
delete_calendar_events($sessionsids);
if (attendance_existing_calendar_events_ids($sessionsids)) {
attendance_delete_calendar_events($sessionsids);
}
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids);

4
sessions.php

@ -145,10 +145,10 @@ switch ($att->pageparams->action) {
attendance_update_users_grade($att);
redirect($att->url_manage(), get_string('sessiondeleted', 'attendance'));
} else if ($att->pageparams->action == mod_attendance_sessions_page_params::ACTION_CREATE_CAL_EVENTS) {
create_calendar_events($sessionsids);
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) {
delete_calendar_events($sessionsids);
attendance_delete_calendar_events($sessionsids);
redirect($att->url_manage(), get_string('deletecheckcalevents', 'attendance'));
}
}

Loading…
Cancel
Save