. /** * Helper functions to keep upgrade.php clean. * * @package mod_attendance * @copyright 2016 Vyacheslav Strelkov * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function attendance_upgrade_create_calendar_events() { global $DB; $attendances = $DB->get_records('attendance', null, null, 'id, name, course'); foreach ($attendances as $att) { $sessionsdata = $DB->get_records('attendance_sessions', array('attendanceid' => $att->id), null, 'id, groupid, sessdate, duration, description, descriptionformat'); foreach ($sessionsdata as $session) { $calevent = new stdClass(); $calevent->name = $att->name; $calevent->courseid = $att->course; $calevent->groupid = $session->groupid; $calevent->instance = $att->id; $calevent->timestart = $session->sessdate; $calevent->timeduration = $session->duration; $calevent->eventtype = 'attendance'; $calevent->timemodified = time(); $calevent->modulename = 'attendance'; $calevent->description = $session->description; $calevent->format = $session->descriptionformat; $caleventid = $DB->insert_record('event', $calevent); $DB->set_field('attendance_sessions', 'caleventid', $caleventid, array('id' => $session->id)); } } }