mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-57497 core_calendar: added new calendar event class
Moved calendar_event class to new location using replaceclasses.php Part of MDL-55611 epic.
This commit is contained in:
parent
e9dfeec94e
commit
e057f279e4
25 changed files with 901 additions and 877 deletions
813
calendar/classes/event.php
Normal file
813
calendar/classes/event.php
Normal file
|
@ -0,0 +1,813 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Contains the class for the calendar events.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
/**
|
||||
* The class for the calendar events.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class event {
|
||||
|
||||
/** @var array An object containing the event properties can be accessed via the magic __get/set methods */
|
||||
protected $properties = null;
|
||||
|
||||
/** @var string The converted event discription with file paths resolved.
|
||||
* This gets populated when someone requests description for the first time */
|
||||
protected $_description = null;
|
||||
|
||||
/** @var array The options to use with this description editor */
|
||||
protected $editoroptions = array(
|
||||
'subdirs' => false,
|
||||
'forcehttps' => false,
|
||||
'maxfiles' => -1,
|
||||
'maxbytes' => null,
|
||||
'trusttext' => false);
|
||||
|
||||
/** @var object The context to use with the description editor */
|
||||
protected $editorcontext = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new event and optionally populates its properties with the data provided.
|
||||
*
|
||||
* @param \stdClass $data Optional. An object containing the properties to for
|
||||
* an event
|
||||
*/
|
||||
public function __construct($data = null) {
|
||||
global $CFG, $USER;
|
||||
|
||||
// First convert to object if it is not already (should either be object or assoc array).
|
||||
if (!is_object($data)) {
|
||||
$data = (object) $data;
|
||||
}
|
||||
|
||||
$this->editoroptions['maxbytes'] = $CFG->maxbytes;
|
||||
|
||||
$data->eventrepeats = 0;
|
||||
|
||||
if (empty($data->id)) {
|
||||
$data->id = null;
|
||||
}
|
||||
|
||||
if (!empty($data->subscriptionid)) {
|
||||
$data->subscription = calendar_get_subscription($data->subscriptionid);
|
||||
}
|
||||
|
||||
// Default to a user event.
|
||||
if (empty($data->eventtype)) {
|
||||
$data->eventtype = 'user';
|
||||
}
|
||||
|
||||
// Default to the current user.
|
||||
if (empty($data->userid)) {
|
||||
$data->userid = $USER->id;
|
||||
}
|
||||
|
||||
if (!empty($data->timeduration) && is_array($data->timeduration)) {
|
||||
$data->timeduration = make_timestamp(
|
||||
$data->timeduration['year'], $data->timeduration['month'], $data->timeduration['day'],
|
||||
$data->timeduration['hour'], $data->timeduration['minute']) - $data->timestart;
|
||||
}
|
||||
|
||||
if (!empty($data->description) && is_array($data->description)) {
|
||||
$data->format = $data->description['format'];
|
||||
$data->description = $data->description['text'];
|
||||
} else if (empty($data->description)) {
|
||||
$data->description = '';
|
||||
$data->format = editors_get_preferred_format();
|
||||
}
|
||||
|
||||
// Ensure form is defaulted correctly.
|
||||
if (empty($data->format)) {
|
||||
$data->format = editors_get_preferred_format();
|
||||
}
|
||||
|
||||
$this->properties = $data;
|
||||
|
||||
if (empty($data->context)) {
|
||||
$this->properties->context = $this->calculate_context();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic set method.
|
||||
*
|
||||
* Attempts to call a set_$key method if one exists otherwise falls back
|
||||
* to simply set the property.
|
||||
*
|
||||
* @param string $key property name
|
||||
* @param mixed $value value of the property
|
||||
*/
|
||||
public function __set($key, $value) {
|
||||
if (method_exists($this, 'set_'.$key)) {
|
||||
$this->{'set_'.$key}($value);
|
||||
}
|
||||
$this->properties->{$key} = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic get method.
|
||||
*
|
||||
* Attempts to call a get_$key method to return the property and ralls over
|
||||
* to return the raw property.
|
||||
*
|
||||
* @param string $key property name
|
||||
* @return mixed property value
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public function __get($key) {
|
||||
if (method_exists($this, 'get_'.$key)) {
|
||||
return $this->{'get_'.$key}();
|
||||
}
|
||||
if (!isset($this->properties->{$key})) {
|
||||
throw new \coding_exception('Undefined property requested');
|
||||
}
|
||||
return $this->properties->{$key};
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic isset method.
|
||||
*
|
||||
* PHP needs an isset magic method if you use the get magic method and
|
||||
* still want empty calls to work.
|
||||
*
|
||||
* @param string $key $key property name
|
||||
* @return bool|mixed property value, false if property is not exist
|
||||
*/
|
||||
public function __isset($key) {
|
||||
return !empty($this->properties->{$key});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the context value needed for an event.
|
||||
*
|
||||
* Event's type can be determine by the available value store in $data
|
||||
* It is important to check for the existence of course/courseid to determine
|
||||
* the course event.
|
||||
* Default value is set to CONTEXT_USER
|
||||
*
|
||||
* @return \stdClass The context object.
|
||||
*/
|
||||
protected function calculate_context() {
|
||||
global $USER, $DB;
|
||||
|
||||
$context = null;
|
||||
if (isset($this->properties->courseid) && $this->properties->courseid > 0) {
|
||||
$context = \context_course::instance($this->properties->courseid);
|
||||
} else if (isset($this->properties->course) && $this->properties->course > 0) {
|
||||
$context = \context_course::instance($this->properties->course);
|
||||
} else if (isset($this->properties->groupid) && $this->properties->groupid > 0) {
|
||||
$group = $DB->get_record('groups', array('id' => $this->properties->groupid));
|
||||
$context = \context_course::instance($group->courseid);
|
||||
} else if (isset($this->properties->userid) && $this->properties->userid > 0
|
||||
&& $this->properties->userid == $USER->id) {
|
||||
$context = \context_user::instance($this->properties->userid);
|
||||
} else if (isset($this->properties->userid) && $this->properties->userid > 0
|
||||
&& $this->properties->userid != $USER->id &&
|
||||
isset($this->properties->instance) && $this->properties->instance > 0) {
|
||||
$cm = get_coursemodule_from_instance($this->properties->modulename, $this->properties->instance, 0,
|
||||
false, MUST_EXIST);
|
||||
$context = \context_course::instance($cm->course);
|
||||
} else {
|
||||
$context = \context_user::instance($this->properties->userid);
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of editoroptions for this event.
|
||||
*
|
||||
* @return array event editor options
|
||||
*/
|
||||
protected function get_editoroptions() {
|
||||
return $this->editoroptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event description: Called by __get
|
||||
* Please use $blah = $event->description;
|
||||
*
|
||||
* @return string event description
|
||||
*/
|
||||
protected function get_description() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
if ($this->_description === null) {
|
||||
// Check if we have already resolved the context for this event.
|
||||
if ($this->editorcontext === null) {
|
||||
// Switch on the event type to decide upon the appropriate context to use for this event.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
|
||||
&& $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
|
||||
return clean_text($this->properties->description, $this->properties->format);
|
||||
}
|
||||
}
|
||||
|
||||
// Work out the item id for the editor, if this is a repeated event
|
||||
// then the files will be associated with the original.
|
||||
if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
$itemid = $this->properties->repeatid;
|
||||
} else {
|
||||
$itemid = $this->properties->id;
|
||||
}
|
||||
|
||||
// Convert file paths in the description so that things display correctly.
|
||||
$this->_description = file_rewrite_pluginfile_urls($this->properties->description, 'pluginfile.php',
|
||||
$this->editorcontext->id, 'calendar', 'event_description', $itemid);
|
||||
// Clean the text so no nasties get through.
|
||||
$this->_description = clean_text($this->_description, $this->properties->format);
|
||||
}
|
||||
|
||||
// Finally return the description.
|
||||
return $this->_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of repeat events there are in this events series.
|
||||
*
|
||||
* @return int number of event repeated
|
||||
*/
|
||||
public function count_repeats() {
|
||||
global $DB;
|
||||
if (!empty($this->properties->repeatid)) {
|
||||
$this->properties->eventrepeats = $DB->count_records('event',
|
||||
array('repeatid' => $this->properties->repeatid));
|
||||
// We don't want to count ourselves.
|
||||
$this->properties->eventrepeats--;
|
||||
}
|
||||
return $this->properties->eventrepeats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or create an event within the database
|
||||
*
|
||||
* Pass in a object containing the event properties and this function will
|
||||
* insert it into the database and deal with any associated files
|
||||
*
|
||||
* @see self::create()
|
||||
* @see self::update()
|
||||
*
|
||||
* @param \stdClass $data object of event
|
||||
* @param bool $checkcapability if moodle should check calendar managing capability or not
|
||||
* @return bool event updated
|
||||
*/
|
||||
public function update($data, $checkcapability=true) {
|
||||
global $DB, $USER;
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->properties->$key = $value;
|
||||
}
|
||||
|
||||
$this->properties->timemodified = time();
|
||||
$usingeditor = (!empty($this->properties->description) && is_array($this->properties->description));
|
||||
|
||||
// Prepare event data.
|
||||
$eventargs = array(
|
||||
'context' => $this->properties->context,
|
||||
'objectid' => $this->properties->id,
|
||||
'other' => array(
|
||||
'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
|
||||
'timestart' => $this->properties->timestart,
|
||||
'name' => $this->properties->name
|
||||
)
|
||||
);
|
||||
|
||||
if (empty($this->properties->id) || $this->properties->id < 1) {
|
||||
|
||||
if ($checkcapability) {
|
||||
if (!calendar_add_event_allowed($this->properties)) {
|
||||
print_error('nopermissiontoupdatecalendar');
|
||||
}
|
||||
}
|
||||
|
||||
if ($usingeditor) {
|
||||
switch ($this->properties->eventtype) {
|
||||
case 'user':
|
||||
$this->properties->courseid = 0;
|
||||
$this->properties->course = 0;
|
||||
$this->properties->groupid = 0;
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
case 'site':
|
||||
$this->properties->courseid = SITEID;
|
||||
$this->properties->course = SITEID;
|
||||
$this->properties->groupid = 0;
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
case 'course':
|
||||
$this->properties->groupid = 0;
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
case 'group':
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
default:
|
||||
// We should NEVER get here, but just incase we do lets fail gracefully.
|
||||
$usingeditor = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// If we are actually using the editor, we recalculate the context because some default values
|
||||
// were set when calculate_context() was called from the constructor.
|
||||
if ($usingeditor) {
|
||||
$this->properties->context = $this->calculate_context();
|
||||
$this->editorcontext = $this->properties->context;
|
||||
}
|
||||
|
||||
$editor = $this->properties->description;
|
||||
$this->properties->format = $this->properties->description['format'];
|
||||
$this->properties->description = $this->properties->description['text'];
|
||||
}
|
||||
|
||||
// Insert the event into the database.
|
||||
$this->properties->id = $DB->insert_record('event', $this->properties);
|
||||
|
||||
if ($usingeditor) {
|
||||
$this->properties->description = file_save_draft_area_files(
|
||||
$editor['itemid'],
|
||||
$this->editorcontext->id,
|
||||
'calendar',
|
||||
'event_description',
|
||||
$this->properties->id,
|
||||
$this->editoroptions,
|
||||
$editor['text'],
|
||||
$this->editoroptions['forcehttps']);
|
||||
$DB->set_field('event', 'description', $this->properties->description,
|
||||
array('id' => $this->properties->id));
|
||||
}
|
||||
|
||||
// Log the event entry.
|
||||
$eventargs['objectid'] = $this->properties->id;
|
||||
$eventargs['context'] = $this->properties->context;
|
||||
$event = \core\event\calendar_event_created::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
$repeatedids = array();
|
||||
|
||||
if (!empty($this->properties->repeat)) {
|
||||
$this->properties->repeatid = $this->properties->id;
|
||||
$DB->set_field('event', 'repeatid', $this->properties->repeatid, array('id' => $this->properties->id));
|
||||
|
||||
$eventcopy = clone($this->properties);
|
||||
unset($eventcopy->id);
|
||||
|
||||
$timestart = new \DateTime('@' . $eventcopy->timestart);
|
||||
$timestart->setTimezone(\core_date::get_user_timezone_object());
|
||||
|
||||
for ($i = 1; $i < $eventcopy->repeats; $i++) {
|
||||
|
||||
$timestart->add(new \DateInterval('P7D'));
|
||||
$eventcopy->timestart = $timestart->getTimestamp();
|
||||
|
||||
// Get the event id for the log record.
|
||||
$eventcopyid = $DB->insert_record('event', $eventcopy);
|
||||
|
||||
// If the context has been set delete all associated files.
|
||||
if ($usingeditor) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description',
|
||||
$this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$fs->create_file_from_storedfile(array('itemid' => $eventcopyid), $file);
|
||||
}
|
||||
}
|
||||
|
||||
$repeatedids[] = $eventcopyid;
|
||||
|
||||
// Trigger an event.
|
||||
$eventargs['objectid'] = $eventcopyid;
|
||||
$eventargs['other']['timestart'] = $eventcopy->timestart;
|
||||
$event = \core\event\calendar_event_created::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
// Hook for tracking added events.
|
||||
self::calendar_event_hook('add_event', array($this->properties, $repeatedids));
|
||||
return true;
|
||||
} else {
|
||||
|
||||
if ($checkcapability) {
|
||||
if (!calendar_edit_event_allowed($this->properties)) {
|
||||
print_error('nopermissiontoupdatecalendar');
|
||||
}
|
||||
}
|
||||
|
||||
if ($usingeditor) {
|
||||
if ($this->editorcontext !== null) {
|
||||
$this->properties->description = file_save_draft_area_files(
|
||||
$this->properties->description['itemid'],
|
||||
$this->editorcontext->id,
|
||||
'calendar',
|
||||
'event_description',
|
||||
$this->properties->id,
|
||||
$this->editoroptions,
|
||||
$this->properties->description['text'],
|
||||
$this->editoroptions['forcehttps']);
|
||||
} else {
|
||||
$this->properties->format = $this->properties->description['format'];
|
||||
$this->properties->description = $this->properties->description['text'];
|
||||
}
|
||||
}
|
||||
|
||||
$event = $DB->get_record('event', array('id' => $this->properties->id));
|
||||
|
||||
$updaterepeated = (!empty($this->properties->repeatid) && !empty($this->properties->repeateditall));
|
||||
|
||||
if ($updaterepeated) {
|
||||
// Update all.
|
||||
if ($this->properties->timestart != $event->timestart) {
|
||||
$timestartoffset = $this->properties->timestart - $event->timestart;
|
||||
$sql = "UPDATE {event}
|
||||
SET name = ?,
|
||||
description = ?,
|
||||
timestart = timestart + ?,
|
||||
timeduration = ?,
|
||||
timemodified = ?
|
||||
WHERE repeatid = ?";
|
||||
$params = array($this->properties->name, $this->properties->description, $timestartoffset,
|
||||
$this->properties->timeduration, time(), $event->repeatid);
|
||||
} else {
|
||||
$sql = "UPDATE {event} SET name = ?, description = ?, timeduration = ?, timemodified = ? WHERE repeatid = ?";
|
||||
$params = array($this->properties->name, $this->properties->description,
|
||||
$this->properties->timeduration, time(), $event->repeatid);
|
||||
}
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Trigger an update event for each of the calendar event.
|
||||
$events = $DB->get_records('event', array('repeatid' => $event->repeatid), '', 'id,timestart');
|
||||
foreach ($events as $event) {
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
} else {
|
||||
$DB->update_record('event', $this->properties);
|
||||
$event = self::load($this->properties->id);
|
||||
$this->properties = $event->properties();
|
||||
|
||||
// Trigger an update event.
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
// Hook for tracking event updates.
|
||||
self::calendar_event_hook('update_event', array($this->properties, $updaterepeated));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an event and if selected an repeated events in the same series
|
||||
*
|
||||
* This function deletes an event, any associated events if $deleterepeated=true,
|
||||
* and cleans up any files associated with the events.
|
||||
*
|
||||
* @see self::delete()
|
||||
*
|
||||
* @param bool $deleterepeated delete event repeatedly
|
||||
* @return bool succession of deleting event
|
||||
*/
|
||||
public function delete($deleterepeated = false) {
|
||||
global $DB;
|
||||
|
||||
// If $this->properties->id is not set then something is wrong.
|
||||
if (empty($this->properties->id)) {
|
||||
debugging('Attempting to delete an event before it has been loaded', DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
$calevent = $DB->get_record('event', array('id' => $this->properties->id), '*', MUST_EXIST);
|
||||
// Delete the event.
|
||||
$DB->delete_records('event', array('id' => $this->properties->id));
|
||||
|
||||
// Trigger an event for the delete action.
|
||||
$eventargs = array(
|
||||
'context' => $this->properties->context,
|
||||
'objectid' => $this->properties->id,
|
||||
'other' => array(
|
||||
'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
|
||||
'timestart' => $this->properties->timestart,
|
||||
'name' => $this->properties->name
|
||||
));
|
||||
$event = \core\event\calendar_event_deleted::create($eventargs);
|
||||
$event->add_record_snapshot('event', $calevent);
|
||||
$event->trigger();
|
||||
|
||||
// If we are deleting parent of a repeated event series, promote the next event in the series as parent.
|
||||
if (($this->properties->id == $this->properties->repeatid) && !$deleterepeated) {
|
||||
$newparent = $DB->get_field_sql("SELECT id from {event} where repeatid = ? order by id ASC",
|
||||
array($this->properties->id), IGNORE_MULTIPLE);
|
||||
if (!empty($newparent)) {
|
||||
$DB->execute("UPDATE {event} SET repeatid = ? WHERE repeatid = ?",
|
||||
array($newparent, $this->properties->id));
|
||||
// Get all records where the repeatid is the same as the event being removed.
|
||||
$events = $DB->get_records('event', array('repeatid' => $newparent));
|
||||
// For each of the returned events trigger the event_update hook and an update event.
|
||||
foreach ($events as $event) {
|
||||
// Trigger an event for the update.
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
self::calendar_event_hook('update_event', array($event, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the editor context hasn't already been set then set it now.
|
||||
if ($this->editorcontext === null) {
|
||||
$this->editorcontext = $this->properties->context;
|
||||
}
|
||||
|
||||
// If the context has been set delete all associated files.
|
||||
if ($this->editorcontext !== null) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the event deleted hook.
|
||||
self::calendar_event_hook('delete_event', array($this->properties->id, $deleterepeated));
|
||||
|
||||
// If we need to delete repeated events then we will fetch them all and delete one by one.
|
||||
if ($deleterepeated && !empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
// Get all records where the repeatid is the same as the event being removed.
|
||||
$events = $DB->get_records('event', array('repeatid' => $this->properties->repeatid));
|
||||
// For each of the returned events populate an event object and call delete.
|
||||
// make sure the arg passed is false as we are already deleting all repeats.
|
||||
foreach ($events as $event) {
|
||||
$event = new event($event);
|
||||
$event->delete(false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all event properties.
|
||||
*
|
||||
* This function returns all of the events properties as an object and optionally
|
||||
* can prepare an editor for the description field at the same time. This is
|
||||
* designed to work when the properties are going to be used to set the default
|
||||
* values of a moodle forms form.
|
||||
*
|
||||
* @param bool $prepareeditor If set to true a editor is prepared for use with
|
||||
* the mforms editor element. (for description)
|
||||
* @return \stdClass Object containing event properties
|
||||
*/
|
||||
public function properties($prepareeditor = false) {
|
||||
global $DB;
|
||||
|
||||
// First take a copy of the properties. We don't want to actually change the
|
||||
// properties or we'd forever be converting back and forwards between an
|
||||
// editor formatted description and not.
|
||||
$properties = clone($this->properties);
|
||||
// Clean the description here.
|
||||
$properties->description = clean_text($properties->description, $properties->format);
|
||||
|
||||
// If set to true we need to prepare the properties for use with an editor
|
||||
// and prepare the file area.
|
||||
if ($prepareeditor) {
|
||||
|
||||
// We may or may not have a property id. If we do then we need to work
|
||||
// out the context so we can copy the existing files to the draft area.
|
||||
if (!empty($properties->id)) {
|
||||
|
||||
if ($properties->eventtype === 'site') {
|
||||
// Site context.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
} else if ($properties->eventtype === 'user') {
|
||||
// User context.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
} else if ($properties->eventtype === 'group' || $properties->eventtype === 'course') {
|
||||
// First check the course is valid.
|
||||
$course = $DB->get_record('course', array('id' => $properties->courseid));
|
||||
if (!$course) {
|
||||
print_error('invalidcourse');
|
||||
}
|
||||
// Course context.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
// We have a course and are within the course context so we had
|
||||
// better use the courses max bytes value.
|
||||
$this->editoroptions['maxbytes'] = $course->maxbytes;
|
||||
} else {
|
||||
// If we get here we have a custom event type as used by some
|
||||
// modules. In this case the event will have been added by
|
||||
// code and we won't need the editor.
|
||||
$this->editoroptions['maxbytes'] = 0;
|
||||
$this->editoroptions['maxfiles'] = 0;
|
||||
}
|
||||
|
||||
if (empty($this->editorcontext) || empty($this->editorcontext->id)) {
|
||||
$contextid = false;
|
||||
} else {
|
||||
// Get the context id that is what we really want.
|
||||
$contextid = $this->editorcontext->id;
|
||||
}
|
||||
} else {
|
||||
|
||||
// If we get here then this is a new event in which case we don't need a
|
||||
// context as there is no existing files to copy to the draft area.
|
||||
$contextid = null;
|
||||
}
|
||||
|
||||
// If the contextid === false we don't support files so no preparing
|
||||
// a draft area.
|
||||
if ($contextid !== false) {
|
||||
// Just encase it has already been submitted.
|
||||
$draftiddescription = file_get_submitted_draft_itemid('description');
|
||||
// Prepare the draft area, this copies existing files to the draft area as well.
|
||||
$properties->description = file_prepare_draft_area($draftiddescription, $contextid, 'calendar',
|
||||
'event_description', $properties->id, $this->editoroptions, $properties->description);
|
||||
} else {
|
||||
$draftiddescription = 0;
|
||||
}
|
||||
|
||||
// Structure the description field as the editor requires.
|
||||
$properties->description = array('text' => $properties->description, 'format' => $properties->format,
|
||||
'itemid' => $draftiddescription);
|
||||
}
|
||||
|
||||
// Finally return the properties.
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the visibility of an event
|
||||
*
|
||||
* @param null|bool $force If it is left null the events visibility is flipped,
|
||||
* If it is false the event is made hidden, if it is true it
|
||||
* is made visible.
|
||||
* @return bool if event is successfully updated, toggle will be visible
|
||||
*/
|
||||
public function toggle_visibility($force = null) {
|
||||
global $DB;
|
||||
|
||||
// Set visible to the default if it is not already set.
|
||||
if (empty($this->properties->visible)) {
|
||||
$this->properties->visible = 1;
|
||||
}
|
||||
|
||||
if ($force === true || ($force !== false && $this->properties->visible == 0)) {
|
||||
// Make this event visible.
|
||||
$this->properties->visible = 1;
|
||||
// Fire the hook.
|
||||
self::calendar_event_hook('show_event', array($this->properties));
|
||||
} else {
|
||||
// Make this event hidden.
|
||||
$this->properties->visible = 0;
|
||||
// Fire the hook.
|
||||
self::calendar_event_hook('hide_event', array($this->properties));
|
||||
}
|
||||
|
||||
// Update the database to reflect this change.
|
||||
return $DB->set_field('event', 'visible', $this->properties->visible, array('id' => $this->properties->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to call the hook for the specified action should a calendar type
|
||||
* by set $CFG->calendar, and the appopriate function defined
|
||||
*
|
||||
* @param string $action One of `update_event`, `add_event`, `delete_event`, `show_event`, `hide_event`
|
||||
* @param array $args The args to pass to the hook, usually the event is the first element
|
||||
* @return bool attempts to call event hook
|
||||
*/
|
||||
public static function calendar_event_hook($action, array $args) {
|
||||
global $CFG;
|
||||
static $extcalendarinc;
|
||||
if ($extcalendarinc === null) {
|
||||
if (!empty($CFG->calendar)) {
|
||||
if (is_readable($CFG->dirroot .'/calendar/'. $CFG->calendar .'/lib.php')) {
|
||||
include_once($CFG->dirroot .'/calendar/'. $CFG->calendar .'/lib.php');
|
||||
$extcalendarinc = true;
|
||||
} else {
|
||||
debugging("Calendar lib file missing or not readable at /calendar/{$CFG->calendar}/lib.php.",
|
||||
DEBUG_DEVELOPER);
|
||||
$extcalendarinc = false;
|
||||
}
|
||||
} else {
|
||||
$extcalendarinc = false;
|
||||
}
|
||||
}
|
||||
if ($extcalendarinc === false) {
|
||||
return false;
|
||||
}
|
||||
$hook = $CFG->calendar .'_'.$action;
|
||||
if (function_exists($hook)) {
|
||||
call_user_func_array($hook, $args);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event object when provided with an event id.
|
||||
*
|
||||
* This function makes use of MUST_EXIST, if the event id passed in is invalid
|
||||
* it will result in an exception being thrown.
|
||||
*
|
||||
* @param int|object $param event object or event id
|
||||
* @return event
|
||||
*/
|
||||
public static function load($param) {
|
||||
global $DB;
|
||||
if (is_object($param)) {
|
||||
$event = new event($param);
|
||||
} else {
|
||||
$event = $DB->get_record('event', array('id' => (int)$param), '*', MUST_EXIST);
|
||||
$event = new event($event);
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new event and returns an event object
|
||||
*
|
||||
* @param \stdClass|array $properties An object containing event properties
|
||||
* @param bool $checkcapability Check caps or not
|
||||
* @throws \coding_exception
|
||||
*
|
||||
* @return event|bool The event object or false if it failed
|
||||
*/
|
||||
public static function create($properties, $checkcapability = true) {
|
||||
if (is_array($properties)) {
|
||||
$properties = (object)$properties;
|
||||
}
|
||||
if (!is_object($properties)) {
|
||||
throw new \coding_exception('When creating an event properties should be either an object or an assoc array');
|
||||
}
|
||||
$event = new event($properties);
|
||||
if ($event->update($properties, $checkcapability)) {
|
||||
return $event;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the text using the external API.
|
||||
*
|
||||
* This function should we used when text formatting is required in external functions.
|
||||
*
|
||||
* @return array an array containing the text formatted and the text format
|
||||
*/
|
||||
public function format_external_text() {
|
||||
|
||||
if ($this->editorcontext === null) {
|
||||
// Switch on the event type to decide upon the appropriate context to use for this event.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
|
||||
if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
|
||||
&& $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
|
||||
// We don't have a context here, do a normal format_text.
|
||||
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Work out the item id for the editor, if this is a repeated event then the files will be associated with the original.
|
||||
if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
$itemid = $this->properties->repeatid;
|
||||
} else {
|
||||
$itemid = $this->properties->id;
|
||||
}
|
||||
|
||||
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id,
|
||||
'calendar', 'event_description', $itemid);
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
namespace core_calendar;
|
||||
|
||||
use calendar_event;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use moodle_exception;
|
||||
|
@ -224,7 +223,7 @@ class rrule_manager {
|
|||
/**
|
||||
* Create events for specified rrule.
|
||||
*
|
||||
* @param calendar_event $passedevent Properties of event to create.
|
||||
* @param event $passedevent Properties of event to create.
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public function create_events($passedevent) {
|
||||
|
@ -246,7 +245,7 @@ class rrule_manager {
|
|||
|
||||
// Adjust the parent event's timestart, if necessary.
|
||||
if (count($eventtimes) > 0 && !in_array($eventrec->timestart, $eventtimes)) {
|
||||
$calevent = new calendar_event($eventrec);
|
||||
$calevent = new event($eventrec);
|
||||
$updatedata = (object)['timestart' => $eventtimes[0], 'repeatid' => $eventrec->id];
|
||||
$calevent->update($updatedata, false);
|
||||
$eventrec->timestart = $calevent->timestart;
|
||||
|
@ -720,7 +719,7 @@ class rrule_manager {
|
|||
$cloneevent->repeatid = $event->id;
|
||||
$cloneevent->timestart = $time;
|
||||
unset($cloneevent->id);
|
||||
calendar_event::create($cloneevent, false);
|
||||
event::create($cloneevent, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ if(!$site = get_site()) {
|
|||
redirect(new moodle_url('/admin/index.php'));
|
||||
}
|
||||
|
||||
$event = calendar_event::load($eventid);
|
||||
$event = \core_calendar\event::load($eventid);
|
||||
|
||||
/**
|
||||
* We are going to be picky here, and require that any event types other than
|
||||
|
|
|
@ -113,7 +113,7 @@ $calendar->prepare_for_view($course, $courses);
|
|||
$formoptions = new stdClass;
|
||||
if ($eventid !== 0) {
|
||||
$title = get_string('editevent', 'calendar');
|
||||
$event = calendar_event::load($eventid);
|
||||
$event = \core_calendar\event::load($eventid);
|
||||
if (!calendar_edit_event_allowed($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ if ($eventid !== 0) {
|
|||
}
|
||||
}
|
||||
$event->timestart = $time;
|
||||
$event = new calendar_event($event);
|
||||
$event = new \core_calendar\event($event);
|
||||
if (!calendar_add_event_allowed($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class core_calendar_external extends external_api {
|
|||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['events'] as $event) {
|
||||
$eventobj = calendar_event::load($event['eventid']);
|
||||
$eventobj = \core_calendar\event::load($event['eventid']);
|
||||
|
||||
// Let's check if the user is allowed to delete an event.
|
||||
if (!calendar_edit_event_allowed($eventobj)) {
|
||||
|
@ -242,7 +242,7 @@ class core_calendar_external extends external_api {
|
|||
foreach ($eventlist as $eventid => $eventobj) {
|
||||
$event = (array) $eventobj;
|
||||
// Description formatting.
|
||||
$calendareventobj = new calendar_event($event);
|
||||
$calendareventobj = new \core_calendar\event($event);
|
||||
list($event['description'], $event['format']) = $calendareventobj->format_external_text();
|
||||
|
||||
if ($hassystemcap) {
|
||||
|
@ -255,7 +255,7 @@ class core_calendar_external extends external_api {
|
|||
}
|
||||
} else {
|
||||
// Can the user actually see this event?
|
||||
$eventobj = calendar_event::load($eventobj);
|
||||
$eventobj = \core_calendar\event::load($eventobj);
|
||||
if (($eventobj->courseid == $SITE->id) ||
|
||||
(!empty($eventobj->groupid) && in_array($eventobj->groupid, $groups)) ||
|
||||
(!empty($eventobj->courseid) && in_array($eventobj->courseid, $courses)) ||
|
||||
|
@ -370,7 +370,7 @@ class core_calendar_external extends external_api {
|
|||
$event['repeat'] = 0;
|
||||
}
|
||||
|
||||
$eventobj = new calendar_event($event);
|
||||
$eventobj = new \core_calendar\event($event);
|
||||
|
||||
// Let's check if the user is allowed to delete an event.
|
||||
if (!calendar_add_event_allowed($eventobj)) {
|
||||
|
|
798
calendar/lib.php
798
calendar/lib.php
|
@ -366,7 +366,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
|
|||
if (!isset($events[$eventid])) {
|
||||
continue;
|
||||
}
|
||||
$event = new calendar_event($events[$eventid]);
|
||||
$event = new \core_calendar\event($events[$eventid]);
|
||||
$popupalt = '';
|
||||
$component = 'moodle';
|
||||
if (!empty($event->modulename)) {
|
||||
|
@ -1653,7 +1653,7 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
|
|||
/**
|
||||
* Return the capability for editing calendar event
|
||||
*
|
||||
* @param calendar_event $event event object
|
||||
* @param \core_calendar\event $event event object
|
||||
* @return bool capability to edit event
|
||||
*/
|
||||
function calendar_edit_event_allowed($event) {
|
||||
|
@ -1763,7 +1763,7 @@ function calendar_preferences_button(stdClass $course) {
|
|||
/**
|
||||
* Get event format time
|
||||
*
|
||||
* @param calendar_event $event event object
|
||||
* @param \core_calendar\event $event event object
|
||||
* @param int $now current time in gmt
|
||||
* @param array $linkparams list of params for event link
|
||||
* @param bool $usecommonwords the words as formatted date/time.
|
||||
|
@ -2038,796 +2038,6 @@ function calendar_add_event_allowed($event) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage calendar events
|
||||
*
|
||||
* This class provides the required functionality in order to manage calendar events.
|
||||
* It was introduced as part of Moodle 2.0 and was created in order to provide a
|
||||
* better framework for dealing with calendar events in particular regard to file
|
||||
* handling through the new file API
|
||||
*
|
||||
* @package core_calendar
|
||||
* @category calendar
|
||||
* @copyright 2009 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @property int $id The id within the event table
|
||||
* @property string $name The name of the event
|
||||
* @property string $description The description of the event
|
||||
* @property int $format The format of the description FORMAT_?
|
||||
* @property int $courseid The course the event is associated with (0 if none)
|
||||
* @property int $groupid The group the event is associated with (0 if none)
|
||||
* @property int $userid The user the event is associated with (0 if none)
|
||||
* @property int $repeatid If this is a repeated event this will be set to the
|
||||
* id of the original
|
||||
* @property string $modulename If added by a module this will be the module name
|
||||
* @property int $instance If added by a module this will be the module instance
|
||||
* @property string $eventtype The event type
|
||||
* @property int $timestart The start time as a timestamp
|
||||
* @property int $timeduration The duration of the event in seconds
|
||||
* @property int $visible 1 if the event is visible
|
||||
* @property int $uuid ?
|
||||
* @property int $sequence ?
|
||||
* @property int $timemodified The time last modified as a timestamp
|
||||
*/
|
||||
class calendar_event {
|
||||
|
||||
/** @var array An object containing the event properties can be accessed via the magic __get/set methods */
|
||||
protected $properties = null;
|
||||
|
||||
/**
|
||||
* @var string The converted event discription with file paths resolved. This gets populated when someone requests description for the first time */
|
||||
protected $_description = null;
|
||||
|
||||
/** @var array The options to use with this description editor */
|
||||
protected $editoroptions = array(
|
||||
'subdirs'=>false,
|
||||
'forcehttps'=>false,
|
||||
'maxfiles'=>-1,
|
||||
'maxbytes'=>null,
|
||||
'trusttext'=>false);
|
||||
|
||||
/** @var object The context to use with the description editor */
|
||||
protected $editorcontext = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new event and optionally populates its properties with the
|
||||
* data provided
|
||||
*
|
||||
* @param stdClass $data Optional. An object containing the properties to for
|
||||
* an event
|
||||
*/
|
||||
public function __construct($data=null) {
|
||||
global $CFG, $USER;
|
||||
|
||||
// First convert to object if it is not already (should either be object or assoc array)
|
||||
if (!is_object($data)) {
|
||||
$data = (object)$data;
|
||||
}
|
||||
|
||||
$this->editoroptions['maxbytes'] = $CFG->maxbytes;
|
||||
|
||||
$data->eventrepeats = 0;
|
||||
|
||||
if (empty($data->id)) {
|
||||
$data->id = null;
|
||||
}
|
||||
|
||||
if (!empty($data->subscriptionid)) {
|
||||
$data->subscription = calendar_get_subscription($data->subscriptionid);
|
||||
}
|
||||
|
||||
// Default to a user event
|
||||
if (empty($data->eventtype)) {
|
||||
$data->eventtype = 'user';
|
||||
}
|
||||
|
||||
// Default to the current user
|
||||
if (empty($data->userid)) {
|
||||
$data->userid = $USER->id;
|
||||
}
|
||||
|
||||
if (!empty($data->timeduration) && is_array($data->timeduration)) {
|
||||
$data->timeduration = make_timestamp($data->timeduration['year'], $data->timeduration['month'], $data->timeduration['day'], $data->timeduration['hour'], $data->timeduration['minute']) - $data->timestart;
|
||||
}
|
||||
if (!empty($data->description) && is_array($data->description)) {
|
||||
$data->format = $data->description['format'];
|
||||
$data->description = $data->description['text'];
|
||||
} else if (empty($data->description)) {
|
||||
$data->description = '';
|
||||
$data->format = editors_get_preferred_format();
|
||||
}
|
||||
// Ensure form is defaulted correctly
|
||||
if (empty($data->format)) {
|
||||
$data->format = editors_get_preferred_format();
|
||||
}
|
||||
|
||||
if (empty($data->context)) {
|
||||
$data->context = $this->calculate_context($data);
|
||||
}
|
||||
$this->properties = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic property method
|
||||
*
|
||||
* Attempts to call a set_$key method if one exists otherwise falls back
|
||||
* to simply set the property
|
||||
*
|
||||
* @param string $key property name
|
||||
* @param mixed $value value of the property
|
||||
*/
|
||||
public function __set($key, $value) {
|
||||
if (method_exists($this, 'set_'.$key)) {
|
||||
$this->{'set_'.$key}($value);
|
||||
}
|
||||
$this->properties->{$key} = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic get method
|
||||
*
|
||||
* Attempts to call a get_$key method to return the property and ralls over
|
||||
* to return the raw property
|
||||
*
|
||||
* @param string $key property name
|
||||
* @return mixed property value
|
||||
*/
|
||||
public function __get($key) {
|
||||
if (method_exists($this, 'get_'.$key)) {
|
||||
return $this->{'get_'.$key}();
|
||||
}
|
||||
if (!isset($this->properties->{$key})) {
|
||||
throw new coding_exception('Undefined property requested');
|
||||
}
|
||||
return $this->properties->{$key};
|
||||
}
|
||||
|
||||
/**
|
||||
* Stupid PHP needs an isset magic method if you use the get magic method and
|
||||
* still want empty calls to work.... blah ~!
|
||||
*
|
||||
* @param string $key $key property name
|
||||
* @return bool|mixed property value, false if property is not exist
|
||||
*/
|
||||
public function __isset($key) {
|
||||
return !empty($this->properties->{$key});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the context value needed for calendar_event.
|
||||
* Event's type can be determine by the available value store in $data
|
||||
* It is important to check for the existence of course/courseid to determine
|
||||
* the course event.
|
||||
* Default value is set to CONTEXT_USER
|
||||
*
|
||||
* @param stdClass $data information about event
|
||||
* @return stdClass The context object.
|
||||
*/
|
||||
protected function calculate_context(stdClass $data) {
|
||||
global $USER, $DB;
|
||||
|
||||
$context = null;
|
||||
if (isset($data->courseid) && $data->courseid > 0) {
|
||||
$context = context_course::instance($data->courseid);
|
||||
} else if (isset($data->course) && $data->course > 0) {
|
||||
$context = context_course::instance($data->course);
|
||||
} else if (isset($data->groupid) && $data->groupid > 0) {
|
||||
$group = $DB->get_record('groups', array('id'=>$data->groupid));
|
||||
$context = context_course::instance($group->courseid);
|
||||
} else if (isset($data->userid) && $data->userid > 0 && $data->userid == $USER->id) {
|
||||
$context = context_user::instance($data->userid);
|
||||
} else if (isset($data->userid) && $data->userid > 0 && $data->userid != $USER->id &&
|
||||
isset($data->instance) && $data->instance > 0) {
|
||||
$cm = get_coursemodule_from_instance($data->modulename, $data->instance, 0, false, MUST_EXIST);
|
||||
$context = context_course::instance($cm->course);
|
||||
} else {
|
||||
$context = context_user::instance($data->userid);
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of editoroptions for this event: Called by __get
|
||||
* Please use $blah = $event->editoroptions;
|
||||
*
|
||||
* @return array event editor options
|
||||
*/
|
||||
protected function get_editoroptions() {
|
||||
return $this->editoroptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event description: Called by __get
|
||||
* Please use $blah = $event->description;
|
||||
*
|
||||
* @return string event description
|
||||
*/
|
||||
protected function get_description() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
if ($this->_description === null) {
|
||||
// Check if we have already resolved the context for this event
|
||||
if ($this->editorcontext === null) {
|
||||
// Switch on the event type to decide upon the appropriate context
|
||||
// to use for this event
|
||||
$this->editorcontext = $this->properties->context;
|
||||
if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
|
||||
&& $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
|
||||
return clean_text($this->properties->description, $this->properties->format);
|
||||
}
|
||||
}
|
||||
|
||||
// Work out the item id for the editor, if this is a repeated event then the files will
|
||||
// be associated with the original
|
||||
if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
$itemid = $this->properties->repeatid;
|
||||
} else {
|
||||
$itemid = $this->properties->id;
|
||||
}
|
||||
|
||||
// Convert file paths in the description so that things display correctly
|
||||
$this->_description = file_rewrite_pluginfile_urls($this->properties->description, 'pluginfile.php', $this->editorcontext->id, 'calendar', 'event_description', $itemid);
|
||||
// Clean the text so no nasties get through
|
||||
$this->_description = clean_text($this->_description, $this->properties->format);
|
||||
}
|
||||
// Finally return the description
|
||||
return $this->_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of repeat events there are in this events series
|
||||
*
|
||||
* @return int number of event repeated
|
||||
*/
|
||||
public function count_repeats() {
|
||||
global $DB;
|
||||
if (!empty($this->properties->repeatid)) {
|
||||
$this->properties->eventrepeats = $DB->count_records('event', array('repeatid'=>$this->properties->repeatid));
|
||||
// We don't want to count ourselves
|
||||
$this->properties->eventrepeats--;
|
||||
}
|
||||
return $this->properties->eventrepeats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or create an event within the database
|
||||
*
|
||||
* Pass in a object containing the event properties and this function will
|
||||
* insert it into the database and deal with any associated files
|
||||
*
|
||||
* @see self::create()
|
||||
* @see self::update()
|
||||
*
|
||||
* @param stdClass $data object of event
|
||||
* @param bool $checkcapability if moodle should check calendar managing capability or not
|
||||
* @return bool event updated
|
||||
*/
|
||||
public function update($data, $checkcapability=true) {
|
||||
global $DB, $USER;
|
||||
|
||||
foreach ($data as $key=>$value) {
|
||||
$this->properties->$key = $value;
|
||||
}
|
||||
|
||||
$this->properties->timemodified = time();
|
||||
$usingeditor = (!empty($this->properties->description) && is_array($this->properties->description));
|
||||
|
||||
// Prepare event data.
|
||||
$eventargs = array(
|
||||
'context' => $this->properties->context,
|
||||
'objectid' => $this->properties->id,
|
||||
'other' => array(
|
||||
'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
|
||||
'timestart' => $this->properties->timestart,
|
||||
'name' => $this->properties->name
|
||||
)
|
||||
);
|
||||
|
||||
if (empty($this->properties->id) || $this->properties->id < 1) {
|
||||
|
||||
if ($checkcapability) {
|
||||
if (!calendar_add_event_allowed($this->properties)) {
|
||||
print_error('nopermissiontoupdatecalendar');
|
||||
}
|
||||
}
|
||||
|
||||
if ($usingeditor) {
|
||||
switch ($this->properties->eventtype) {
|
||||
case 'user':
|
||||
$this->properties->courseid = 0;
|
||||
$this->properties->course = 0;
|
||||
$this->properties->groupid = 0;
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
case 'site':
|
||||
$this->properties->courseid = SITEID;
|
||||
$this->properties->course = SITEID;
|
||||
$this->properties->groupid = 0;
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
case 'course':
|
||||
$this->properties->groupid = 0;
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
case 'group':
|
||||
$this->properties->userid = $USER->id;
|
||||
break;
|
||||
default:
|
||||
// Ewww we should NEVER get here, but just incase we do lets
|
||||
// fail gracefully
|
||||
$usingeditor = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// If we are actually using the editor, we recalculate the context because some default values
|
||||
// were set when calculate_context() was called from the constructor.
|
||||
if ($usingeditor) {
|
||||
$this->properties->context = $this->calculate_context($this->properties);
|
||||
$this->editorcontext = $this->properties->context;
|
||||
}
|
||||
|
||||
$editor = $this->properties->description;
|
||||
$this->properties->format = $this->properties->description['format'];
|
||||
$this->properties->description = $this->properties->description['text'];
|
||||
}
|
||||
|
||||
// Insert the event into the database
|
||||
$this->properties->id = $DB->insert_record('event', $this->properties);
|
||||
|
||||
if ($usingeditor) {
|
||||
$this->properties->description = file_save_draft_area_files(
|
||||
$editor['itemid'],
|
||||
$this->editorcontext->id,
|
||||
'calendar',
|
||||
'event_description',
|
||||
$this->properties->id,
|
||||
$this->editoroptions,
|
||||
$editor['text'],
|
||||
$this->editoroptions['forcehttps']);
|
||||
$DB->set_field('event', 'description', $this->properties->description, array('id'=>$this->properties->id));
|
||||
}
|
||||
|
||||
// Log the event entry.
|
||||
$eventargs['objectid'] = $this->properties->id;
|
||||
$eventargs['context'] = $this->properties->context;
|
||||
$event = \core\event\calendar_event_created::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
$repeatedids = array();
|
||||
|
||||
if (!empty($this->properties->repeat)) {
|
||||
$this->properties->repeatid = $this->properties->id;
|
||||
$DB->set_field('event', 'repeatid', $this->properties->repeatid, array('id'=>$this->properties->id));
|
||||
|
||||
$eventcopy = clone($this->properties);
|
||||
unset($eventcopy->id);
|
||||
|
||||
$timestart = new DateTime('@' . $eventcopy->timestart);
|
||||
$timestart->setTimezone(core_date::get_user_timezone_object());
|
||||
|
||||
for($i = 1; $i < $eventcopy->repeats; $i++) {
|
||||
|
||||
$timestart->add(new DateInterval('P7D'));
|
||||
$eventcopy->timestart = $timestart->getTimestamp();
|
||||
|
||||
// Get the event id for the log record.
|
||||
$eventcopyid = $DB->insert_record('event', $eventcopy);
|
||||
|
||||
// If the context has been set delete all associated files
|
||||
if ($usingeditor) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$fs->create_file_from_storedfile(array('itemid'=>$eventcopyid), $file);
|
||||
}
|
||||
}
|
||||
|
||||
$repeatedids[] = $eventcopyid;
|
||||
|
||||
// Trigger an event.
|
||||
$eventargs['objectid'] = $eventcopyid;
|
||||
$eventargs['other']['timestart'] = $eventcopy->timestart;
|
||||
$event = \core\event\calendar_event_created::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
// Hook for tracking added events
|
||||
self::calendar_event_hook('add_event', array($this->properties, $repeatedids));
|
||||
return true;
|
||||
} else {
|
||||
|
||||
if ($checkcapability) {
|
||||
if(!calendar_edit_event_allowed($this->properties)) {
|
||||
print_error('nopermissiontoupdatecalendar');
|
||||
}
|
||||
}
|
||||
|
||||
if ($usingeditor) {
|
||||
if ($this->editorcontext !== null) {
|
||||
$this->properties->description = file_save_draft_area_files(
|
||||
$this->properties->description['itemid'],
|
||||
$this->editorcontext->id,
|
||||
'calendar',
|
||||
'event_description',
|
||||
$this->properties->id,
|
||||
$this->editoroptions,
|
||||
$this->properties->description['text'],
|
||||
$this->editoroptions['forcehttps']);
|
||||
} else {
|
||||
$this->properties->format = $this->properties->description['format'];
|
||||
$this->properties->description = $this->properties->description['text'];
|
||||
}
|
||||
}
|
||||
|
||||
$event = $DB->get_record('event', array('id'=>$this->properties->id));
|
||||
|
||||
$updaterepeated = (!empty($this->properties->repeatid) && !empty($this->properties->repeateditall));
|
||||
|
||||
if ($updaterepeated) {
|
||||
// Update all
|
||||
if ($this->properties->timestart != $event->timestart) {
|
||||
$timestartoffset = $this->properties->timestart - $event->timestart;
|
||||
$sql = "UPDATE {event}
|
||||
SET name = ?,
|
||||
description = ?,
|
||||
timestart = timestart + ?,
|
||||
timeduration = ?,
|
||||
timemodified = ?
|
||||
WHERE repeatid = ?";
|
||||
$params = array($this->properties->name, $this->properties->description, $timestartoffset, $this->properties->timeduration, time(), $event->repeatid);
|
||||
} else {
|
||||
$sql = "UPDATE {event} SET name = ?, description = ?, timeduration = ?, timemodified = ? WHERE repeatid = ?";
|
||||
$params = array($this->properties->name, $this->properties->description, $this->properties->timeduration, time(), $event->repeatid);
|
||||
}
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Trigger an update event for each of the calendar event.
|
||||
$events = $DB->get_records('event', array('repeatid' => $event->repeatid), '', 'id,timestart');
|
||||
foreach ($events as $event) {
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
} else {
|
||||
$DB->update_record('event', $this->properties);
|
||||
$event = calendar_event::load($this->properties->id);
|
||||
$this->properties = $event->properties();
|
||||
|
||||
// Trigger an update event.
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
// Hook for tracking event updates
|
||||
self::calendar_event_hook('update_event', array($this->properties, $updaterepeated));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an event and if selected an repeated events in the same series
|
||||
*
|
||||
* This function deletes an event, any associated events if $deleterepeated=true,
|
||||
* and cleans up any files associated with the events.
|
||||
*
|
||||
* @see self::delete()
|
||||
*
|
||||
* @param bool $deleterepeated delete event repeatedly
|
||||
* @return bool succession of deleting event
|
||||
*/
|
||||
public function delete($deleterepeated=false) {
|
||||
global $DB;
|
||||
|
||||
// If $this->properties->id is not set then something is wrong
|
||||
if (empty($this->properties->id)) {
|
||||
debugging('Attempting to delete an event before it has been loaded', DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
$calevent = $DB->get_record('event', array('id' => $this->properties->id), '*', MUST_EXIST);
|
||||
// Delete the event
|
||||
$DB->delete_records('event', array('id'=>$this->properties->id));
|
||||
|
||||
// Trigger an event for the delete action.
|
||||
$eventargs = array(
|
||||
'context' => $this->properties->context,
|
||||
'objectid' => $this->properties->id,
|
||||
'other' => array(
|
||||
'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
|
||||
'timestart' => $this->properties->timestart,
|
||||
'name' => $this->properties->name
|
||||
));
|
||||
$event = \core\event\calendar_event_deleted::create($eventargs);
|
||||
$event->add_record_snapshot('event', $calevent);
|
||||
$event->trigger();
|
||||
|
||||
// If we are deleting parent of a repeated event series, promote the next event in the series as parent
|
||||
if (($this->properties->id == $this->properties->repeatid) && !$deleterepeated) {
|
||||
$newparent = $DB->get_field_sql("SELECT id from {event} where repeatid = ? order by id ASC", array($this->properties->id), IGNORE_MULTIPLE);
|
||||
if (!empty($newparent)) {
|
||||
$DB->execute("UPDATE {event} SET repeatid = ? WHERE repeatid = ?", array($newparent, $this->properties->id));
|
||||
// Get all records where the repeatid is the same as the event being removed
|
||||
$events = $DB->get_records('event', array('repeatid' => $newparent));
|
||||
// For each of the returned events trigger the event_update hook and an update event.
|
||||
foreach ($events as $event) {
|
||||
// Trigger an event for the update.
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
self::calendar_event_hook('update_event', array($event, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the editor context hasn't already been set then set it now
|
||||
if ($this->editorcontext === null) {
|
||||
$this->editorcontext = $this->properties->context;
|
||||
}
|
||||
|
||||
// If the context has been set delete all associated files
|
||||
if ($this->editorcontext !== null) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the event deleted hook
|
||||
self::calendar_event_hook('delete_event', array($this->properties->id, $deleterepeated));
|
||||
|
||||
// If we need to delete repeated events then we will fetch them all and delete one by one
|
||||
if ($deleterepeated && !empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
// Get all records where the repeatid is the same as the event being removed
|
||||
$events = $DB->get_records('event', array('repeatid'=>$this->properties->repeatid));
|
||||
// For each of the returned events populate a calendar_event object and call delete
|
||||
// make sure the arg passed is false as we are already deleting all repeats
|
||||
foreach ($events as $event) {
|
||||
$event = new calendar_event($event);
|
||||
$event->delete(false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all event properties
|
||||
*
|
||||
* This function returns all of the events properties as an object and optionally
|
||||
* can prepare an editor for the description field at the same time. This is
|
||||
* designed to work when the properties are going to be used to set the default
|
||||
* values of a moodle forms form.
|
||||
*
|
||||
* @param bool $prepareeditor If set to true a editor is prepared for use with
|
||||
* the mforms editor element. (for description)
|
||||
* @return stdClass Object containing event properties
|
||||
*/
|
||||
public function properties($prepareeditor=false) {
|
||||
global $USER, $CFG, $DB;
|
||||
|
||||
// First take a copy of the properties. We don't want to actually change the
|
||||
// properties or we'd forever be converting back and forwards between an
|
||||
// editor formatted description and not
|
||||
$properties = clone($this->properties);
|
||||
// Clean the description here
|
||||
$properties->description = clean_text($properties->description, $properties->format);
|
||||
|
||||
// If set to true we need to prepare the properties for use with an editor
|
||||
// and prepare the file area
|
||||
if ($prepareeditor) {
|
||||
|
||||
// We may or may not have a property id. If we do then we need to work
|
||||
// out the context so we can copy the existing files to the draft area
|
||||
if (!empty($properties->id)) {
|
||||
|
||||
if ($properties->eventtype === 'site') {
|
||||
// Site context
|
||||
$this->editorcontext = $this->properties->context;
|
||||
} else if ($properties->eventtype === 'user') {
|
||||
// User context
|
||||
$this->editorcontext = $this->properties->context;
|
||||
} else if ($properties->eventtype === 'group' || $properties->eventtype === 'course') {
|
||||
// First check the course is valid
|
||||
$course = $DB->get_record('course', array('id'=>$properties->courseid));
|
||||
if (!$course) {
|
||||
print_error('invalidcourse');
|
||||
}
|
||||
// Course context
|
||||
$this->editorcontext = $this->properties->context;
|
||||
// We have a course and are within the course context so we had
|
||||
// better use the courses max bytes value
|
||||
$this->editoroptions['maxbytes'] = $course->maxbytes;
|
||||
} else {
|
||||
// If we get here we have a custom event type as used by some
|
||||
// modules. In this case the event will have been added by
|
||||
// code and we won't need the editor
|
||||
$this->editoroptions['maxbytes'] = 0;
|
||||
$this->editoroptions['maxfiles'] = 0;
|
||||
}
|
||||
|
||||
if (empty($this->editorcontext) || empty($this->editorcontext->id)) {
|
||||
$contextid = false;
|
||||
} else {
|
||||
// Get the context id that is what we really want
|
||||
$contextid = $this->editorcontext->id;
|
||||
}
|
||||
} else {
|
||||
|
||||
// If we get here then this is a new event in which case we don't need a
|
||||
// context as there is no existing files to copy to the draft area.
|
||||
$contextid = null;
|
||||
}
|
||||
|
||||
// If the contextid === false we don't support files so no preparing
|
||||
// a draft area
|
||||
if ($contextid !== false) {
|
||||
// Just encase it has already been submitted
|
||||
$draftiddescription = file_get_submitted_draft_itemid('description');
|
||||
// Prepare the draft area, this copies existing files to the draft area as well
|
||||
$properties->description = file_prepare_draft_area($draftiddescription, $contextid, 'calendar', 'event_description', $properties->id, $this->editoroptions, $properties->description);
|
||||
} else {
|
||||
$draftiddescription = 0;
|
||||
}
|
||||
|
||||
// Structure the description field as the editor requires
|
||||
$properties->description = array('text'=>$properties->description, 'format'=>$properties->format, 'itemid'=>$draftiddescription);
|
||||
}
|
||||
|
||||
// Finally return the properties
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the visibility of an event
|
||||
*
|
||||
* @param null|bool $force If it is left null the events visibility is flipped,
|
||||
* If it is false the event is made hidden, if it is true it
|
||||
* is made visible.
|
||||
* @return bool if event is successfully updated, toggle will be visible
|
||||
*/
|
||||
public function toggle_visibility($force=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// Set visible to the default if it is not already set
|
||||
if (empty($this->properties->visible)) {
|
||||
$this->properties->visible = 1;
|
||||
}
|
||||
|
||||
if ($force === true || ($force !== false && $this->properties->visible == 0)) {
|
||||
// Make this event visible
|
||||
$this->properties->visible = 1;
|
||||
// Fire the hook
|
||||
self::calendar_event_hook('show_event', array($this->properties));
|
||||
} else {
|
||||
// Make this event hidden
|
||||
$this->properties->visible = 0;
|
||||
// Fire the hook
|
||||
self::calendar_event_hook('hide_event', array($this->properties));
|
||||
}
|
||||
|
||||
// Update the database to reflect this change
|
||||
return $DB->set_field('event', 'visible', $this->properties->visible, array('id'=>$this->properties->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to call the hook for the specified action should a calendar type
|
||||
* by set $CFG->calendar, and the appopriate function defined
|
||||
*
|
||||
* @param string $action One of `update_event`, `add_event`, `delete_event`, `show_event`, `hide_event`
|
||||
* @param array $args The args to pass to the hook, usually the event is the first element
|
||||
* @return bool attempts to call event hook
|
||||
*/
|
||||
public static function calendar_event_hook($action, array $args) {
|
||||
global $CFG;
|
||||
static $extcalendarinc;
|
||||
if ($extcalendarinc === null) {
|
||||
if (!empty($CFG->calendar)) {
|
||||
if (is_readable($CFG->dirroot .'/calendar/'. $CFG->calendar .'/lib.php')) {
|
||||
include_once($CFG->dirroot .'/calendar/'. $CFG->calendar .'/lib.php');
|
||||
$extcalendarinc = true;
|
||||
} else {
|
||||
debugging("Calendar lib file missing or not readable at /calendar/{$CFG->calendar}/lib.php.",
|
||||
DEBUG_DEVELOPER);
|
||||
$extcalendarinc = false;
|
||||
}
|
||||
} else {
|
||||
$extcalendarinc = false;
|
||||
}
|
||||
}
|
||||
if($extcalendarinc === false) {
|
||||
return false;
|
||||
}
|
||||
$hook = $CFG->calendar .'_'.$action;
|
||||
if (function_exists($hook)) {
|
||||
call_user_func_array($hook, $args);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a calendar_event object when provided with an event id
|
||||
*
|
||||
* This function makes use of MUST_EXIST, if the event id passed in is invalid
|
||||
* it will result in an exception being thrown
|
||||
*
|
||||
* @param int|object $param event object or event id
|
||||
* @return calendar_event|false status for loading calendar_event
|
||||
*/
|
||||
public static function load($param) {
|
||||
global $DB;
|
||||
if (is_object($param)) {
|
||||
$event = new calendar_event($param);
|
||||
} else {
|
||||
$event = $DB->get_record('event', array('id'=>(int)$param), '*', MUST_EXIST);
|
||||
$event = new calendar_event($event);
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new event and returns a calendar_event object
|
||||
*
|
||||
* @param stdClass|array $properties An object containing event properties
|
||||
* @param bool $checkcapability Check caps or not
|
||||
* @throws coding_exception
|
||||
*
|
||||
* @return calendar_event|bool The event object or false if it failed
|
||||
*/
|
||||
public static function create($properties, $checkcapability = true) {
|
||||
if (is_array($properties)) {
|
||||
$properties = (object)$properties;
|
||||
}
|
||||
if (!is_object($properties)) {
|
||||
throw new coding_exception('When creating an event properties should be either an object or an assoc array');
|
||||
}
|
||||
$event = new calendar_event($properties);
|
||||
if ($event->update($properties, $checkcapability)) {
|
||||
return $event;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the text using the external API.
|
||||
* This function should we used when text formatting is required in external functions.
|
||||
*
|
||||
* @return array an array containing the text formatted and the text format
|
||||
*/
|
||||
public function format_external_text() {
|
||||
|
||||
if ($this->editorcontext === null) {
|
||||
// Switch on the event type to decide upon the appropriate context to use for this event.
|
||||
$this->editorcontext = $this->properties->context;
|
||||
|
||||
if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
|
||||
&& $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
|
||||
// We don't have a context here, do a normal format_text.
|
||||
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Work out the item id for the editor, if this is a repeated event then the files will be associated with the original.
|
||||
if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
|
||||
$itemid = $this->properties->repeatid;
|
||||
} else {
|
||||
$itemid = $this->properties->id;
|
||||
}
|
||||
|
||||
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id,
|
||||
'calendar', 'event_description', $itemid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar information class
|
||||
*
|
||||
|
@ -3149,7 +2359,7 @@ function calendar_add_icalendar_event($event, $courseid, $subscriptionid, $timez
|
|||
} else {
|
||||
$return = CALENDAR_IMPORT_EVENT_INSERTED; // Insert.
|
||||
}
|
||||
if ($createdevent = calendar_event::create($eventrecord, false)) {
|
||||
if ($createdevent = \core_calendar\event::create($eventrecord, false)) {
|
||||
if (!empty($event->properties['RRULE'])) {
|
||||
// Repeating events.
|
||||
date_default_timezone_set($tz); // Change time zone to parse all events.
|
||||
|
|
|
@ -183,7 +183,7 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
$underway = array();
|
||||
// First, print details about events that start today
|
||||
foreach ($events as $event) {
|
||||
$event = new calendar_event($event);
|
||||
$event = new \core_calendar\event($event);
|
||||
$event->calendarcourseid = $calendar->courseid;
|
||||
if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now
|
||||
$event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
|
||||
|
@ -212,11 +212,11 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
/**
|
||||
* Displays an event
|
||||
*
|
||||
* @param calendar_event $event
|
||||
* @param \core_calendar\event $event
|
||||
* @param bool $showactions
|
||||
* @return string
|
||||
*/
|
||||
public function event(calendar_event $event, $showactions=true) {
|
||||
public function event(\core_calendar\event $event, $showactions=true) {
|
||||
global $CFG;
|
||||
|
||||
$event = calendar_add_event_metadata($event);
|
||||
|
@ -366,7 +366,7 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
$events = calendar_get_events($display->tstart, $display->tend, $calendar->users, $calendar->groups, $calendar->courses);
|
||||
if (!empty($events)) {
|
||||
foreach($events as $eventid => $event) {
|
||||
$event = new calendar_event($event);
|
||||
$event = new \core_calendar\event($event);
|
||||
if (!empty($event->modulename)) {
|
||||
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
|
||||
if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
|
||||
|
@ -539,9 +539,8 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
if ($events) {
|
||||
$output .= html_writer::start_tag('div', array('class' => 'eventlist'));
|
||||
foreach ($events as $event) {
|
||||
// Convert to calendar_event object so that we transform description
|
||||
// accordingly
|
||||
$event = new calendar_event($event);
|
||||
// Convert to \core_calendar\event object so that we transform description accordingly.
|
||||
$event = new \core_calendar\event($event);
|
||||
$event->calendarcourseid = $calendar->courseid;
|
||||
$output .= $this->event($event);
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
|||
$prop->priority = $priority;
|
||||
}
|
||||
|
||||
$event = new calendar_event($prop);
|
||||
$event = new \core_calendar\event($prop);
|
||||
return $event->create($prop);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
|||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\core_calendar\event::create($event, false);
|
||||
}
|
||||
|
||||
$timestart = time() - 60;
|
||||
|
|
|
@ -992,10 +992,10 @@ function set_coursemodule_visible($id, $visible, $visibleoncoursepage = 1) {
|
|||
($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename)))) {
|
||||
foreach($events as $event) {
|
||||
if ($visible) {
|
||||
$event = new calendar_event($event);
|
||||
$event = new \core_calendar\event($event);
|
||||
$event->toggle_visibility(true);
|
||||
} else {
|
||||
$event = new calendar_event($event);
|
||||
$event = new \core_calendar\event($event);
|
||||
$event->toggle_visibility(false);
|
||||
}
|
||||
}
|
||||
|
@ -1169,7 +1169,7 @@ function course_delete_module($cmid, $async = false) {
|
|||
// Delete events from calendar.
|
||||
if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
|
||||
foreach($events as $event) {
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1212,7 +1212,7 @@ class core_course_courselib_testcase extends advanced_testcase {
|
|||
// Check the events visibility.
|
||||
if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $cm->modname))) {
|
||||
foreach ($events as $event) {
|
||||
$calevent = new calendar_event($event);
|
||||
$calevent = new \core_calendar\event($event);
|
||||
$this->assertEquals($visibility, $calevent->visible, "$cm->modname calendar_event visibility");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,5 +45,7 @@ $renamedclasses = array(
|
|||
'core_competency\\external\\persistent_exporter' => 'core\\external\\persistent_exporter',
|
||||
'core_competency\\external\\comment_area_exporter' => 'core_comment\\external\\comment_area_exporter',
|
||||
'core_competency\\external\\stored_file_exporter' => 'core_files\\external\\stored_file_exporter',
|
||||
'core_competency\\external\\user_summary_exporter' => 'core_user\\external\\user_summary_exporter'
|
||||
'core_competency\\external\\user_summary_exporter' => 'core_user\\external\\user_summary_exporter',
|
||||
'core_search\area\base_activity' => 'core_search\base_activity',
|
||||
'calendar_event' => 'core_calendar\event'
|
||||
);
|
||||
|
|
|
@ -1163,41 +1163,41 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
|
|||
|
||||
|
||||
/**
|
||||
* @deprecated please use calendar_event::create() instead.
|
||||
* @deprecated please use \core_calendar\event::create() instead.
|
||||
*/
|
||||
function add_event($event) {
|
||||
throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
|
||||
throw new coding_exception('add_event() can not be used any more, please use \core_calendar\event::create() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please calendar_event->update() instead.
|
||||
* @deprecated please \core_calendar\event->update() instead.
|
||||
*/
|
||||
function update_event($event) {
|
||||
throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
|
||||
throw new coding_exception('update_event() is removed, please use \core_calendar\event->update() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use calendar_event->delete() instead.
|
||||
* @deprecated please use \core_calendar\event->delete() instead.
|
||||
*/
|
||||
function delete_event($id) {
|
||||
throw new coding_exception('delete_event() can not be used any more, please use '.
|
||||
'calendar_event->delete() instead.');
|
||||
'\core_calendar\event->delete() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use calendar_event->toggle_visibility(false) instead.
|
||||
* @deprecated please use \core_calendar\event->toggle_visibility(false) instead.
|
||||
*/
|
||||
function hide_event($event) {
|
||||
throw new coding_exception('hide_event() can not be used any more, please use '.
|
||||
'calendar_event->toggle_visibility(false) instead.');
|
||||
'\core_calendar\event->toggle_visibility(false) instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use calendar_event->toggle_visibility(true) instead.
|
||||
* @deprecated please use \core_calendar\event->toggle_visibility(true) instead.
|
||||
*/
|
||||
function show_event($event) {
|
||||
throw new coding_exception('show_event() can not be used any more, please use '.
|
||||
'calendar_event->toggle_visibility(true) instead.');
|
||||
'\core_calendar\event->toggle_visibility(true) instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -69,6 +69,7 @@ information provided here is intended especially for developers.
|
|||
* New 'priority' column for the event table to determine which event to show in case of events with user and group overrides.
|
||||
* Webservices core_course_search_courses and core_course_get_courses_by_field will always return the sortorder field.
|
||||
* core_course_external::get_activities_overview has been deprecated. Please do not call this function any more.
|
||||
* Class 'calendar_event' has been renamed and is now deprecated. Please use 'core_calendar\event' instead.
|
||||
|
||||
=== 3.2 ===
|
||||
|
||||
|
|
|
@ -300,13 +300,13 @@ function assign_update_events($assign, $override = null) {
|
|||
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
|
||||
$event->timestart = $duedate;
|
||||
$event->eventtype = 'due';
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete any leftover events.
|
||||
foreach ($oldevents as $badevent) {
|
||||
$badevent = calendar_event::load($badevent);
|
||||
$badevent = \core_calendar\event::load($badevent);
|
||||
$badevent->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -792,7 +792,7 @@ class assign {
|
|||
}
|
||||
$events = $DB->get_records('event', $conds);
|
||||
foreach ($events as $event) {
|
||||
$eventold = calendar_event::load($event);
|
||||
$eventold = \core_calendar\event::load($event);
|
||||
$eventold->delete();
|
||||
}
|
||||
|
||||
|
@ -1197,7 +1197,7 @@ class assign {
|
|||
}
|
||||
|
||||
if ($event->id) {
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
unset($event->id);
|
||||
|
@ -1208,7 +1208,7 @@ class assign {
|
|||
$event->instance = $instance->id;
|
||||
$event->eventtype = $eventtype;
|
||||
$event->timeduration = 0;
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
} else {
|
||||
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id, 'eventtype' => $eventtype));
|
||||
|
|
|
@ -126,7 +126,7 @@ function chat_add_instance($chat) {
|
|||
$event->timestart = $chat->chattime;
|
||||
$event->timeduration = 0;
|
||||
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
return $returnid;
|
||||
}
|
||||
|
@ -157,11 +157,11 @@ function chat_update_instance($chat) {
|
|||
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
|
||||
$event->timestart = $chat->chattime;
|
||||
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Do not publish this event, so delete it.
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
} else {
|
||||
|
@ -179,7 +179,7 @@ function chat_update_instance($chat) {
|
|||
$event->timestart = $chat->chattime;
|
||||
$event->timeduration = 0;
|
||||
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ function chat_refresh_events($courseid = 0) {
|
|||
$event->timestart = $chat->chattime;
|
||||
|
||||
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id))) {
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else if ($chat->schedule > 0) {
|
||||
// The chat is scheduled and the event should be published.
|
||||
|
@ -459,7 +459,7 @@ function chat_refresh_events($courseid = 0) {
|
|||
$event->timeduration = 0;
|
||||
$event->visible = $DB->get_field('course_modules', 'visible', array('module' => $moduleid, 'instance' => $chat->id));
|
||||
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -665,7 +665,7 @@ function chat_update_chat_times($chatid=0) {
|
|||
|
||||
if ($event->id = $DB->get_field_select('event', 'id', $cond, $params)) {
|
||||
$event->timestart = $chat->chattime;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,11 +52,11 @@ function choice_set_events($choice) {
|
|||
$event->timestart = $choice->timeopen;
|
||||
$event->visible = instance_is_visible('choice', $choice);
|
||||
$event->timeduration = 0;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Calendar event is on longer needed.
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
} else {
|
||||
|
@ -73,7 +73,7 @@ function choice_set_events($choice) {
|
|||
$event->timestart = $choice->timeopen;
|
||||
$event->visible = instance_is_visible('choice', $choice);
|
||||
$event->timeduration = 0;
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,11 +88,11 @@ function choice_set_events($choice) {
|
|||
$event->timestart = $choice->timeclose;
|
||||
$event->visible = instance_is_visible('choice', $choice);
|
||||
$event->timeduration = 0;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Calendar event is on longer needed.
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
} else {
|
||||
|
@ -110,7 +110,7 @@ function choice_set_events($choice) {
|
|||
$event->timestart = $choice->timeclose;
|
||||
$event->visible = instance_is_visible('choice', $choice);
|
||||
$event->timeduration = 0;
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1054,7 +1054,7 @@ function data_delete_instance($id) { // takes the dataid
|
|||
// Remove old calendar events.
|
||||
$events = $DB->get_records('event', array('modulename' => 'data', 'instance' => $id));
|
||||
foreach ($events as $event) {
|
||||
$event = calendar_event::load($event);
|
||||
$event = \core_calendar\event::load($event);
|
||||
$event->delete();
|
||||
}
|
||||
|
||||
|
|
|
@ -608,11 +608,11 @@ function data_set_events($data) {
|
|||
$event->timestart = $data->timeavailablefrom;
|
||||
$event->visible = instance_is_visible('data', $data);
|
||||
$event->timeduration = 0;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Calendar event is on longer needed.
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
} else {
|
||||
|
@ -629,7 +629,7 @@ function data_set_events($data) {
|
|||
$event->timestart = $data->timeavailablefrom;
|
||||
$event->visible = instance_is_visible('data', $data);
|
||||
$event->timeduration = 0;
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -644,11 +644,11 @@ function data_set_events($data) {
|
|||
$event->timestart = $data->timeavailableto;
|
||||
$event->visible = instance_is_visible('data', $data);
|
||||
$event->timeduration = 0;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Calendar event is on longer needed.
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
} else {
|
||||
|
@ -666,7 +666,7 @@ function data_set_events($data) {
|
|||
$event->timestart = $data->timeavailableto;
|
||||
$event->visible = instance_is_visible('data', $data);
|
||||
$event->timeduration = 0;
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -811,7 +811,7 @@ function feedback_set_events($feedback) {
|
|||
if ($eventid) {
|
||||
// Calendar event exists so update it.
|
||||
$event->id = $eventid;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Event doesn't exist so create one.
|
||||
|
@ -821,11 +821,11 @@ function feedback_set_events($feedback) {
|
|||
$event->modulename = 'feedback';
|
||||
$event->instance = $feedback->id;
|
||||
$event->eventtype = 'open';
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
} else if ($eventid) {
|
||||
// Calendar event is on longer needed.
|
||||
$calendarevent = calendar_event::load($eventid);
|
||||
$calendarevent = \core_calendar\event::load($eventid);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
|
||||
|
@ -843,7 +843,7 @@ function feedback_set_events($feedback) {
|
|||
if ($eventid) {
|
||||
// Calendar event exists so update it.
|
||||
$event->id = $eventid;
|
||||
$calendarevent = calendar_event::load($event->id);
|
||||
$calendarevent = \core_calendar\event::load($event->id);
|
||||
$calendarevent->update($event);
|
||||
} else {
|
||||
// Event doesn't exist so create one.
|
||||
|
@ -853,11 +853,11 @@ function feedback_set_events($feedback) {
|
|||
$event->modulename = 'feedback';
|
||||
$event->instance = $feedback->id;
|
||||
$event->eventtype = 'close';
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
} else if ($eventid) {
|
||||
// Calendar event is on longer needed.
|
||||
$calendarevent = calendar_event::load($eventid);
|
||||
$calendarevent = \core_calendar\event::load($eventid);
|
||||
$calendarevent->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,8 +206,8 @@ function lesson_update_events($lesson, $override = null) {
|
|||
unset($event->id);
|
||||
}
|
||||
$event->name = $eventname.' ('.get_string('lessonopens', 'lesson').')';
|
||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||
calendar_event::create($event);
|
||||
// The method \core_calendar\event::create will reuse a db record if the id field is set.
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
if ($deadline && $addclose) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
|
@ -224,14 +224,14 @@ function lesson_update_events($lesson, $override = null) {
|
|||
$event->priority = $closepriorities[$deadline];
|
||||
}
|
||||
}
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete any leftover events.
|
||||
foreach ($oldevents as $badevent) {
|
||||
$badevent = calendar_event::load($badevent);
|
||||
$badevent = \core_calendar\event::load($badevent);
|
||||
$badevent->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1571,7 +1571,7 @@ class lesson extends lesson_base {
|
|||
$DB->delete_records("lesson_branch", array("lessonid"=>$this->properties->id));
|
||||
if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$this->properties->id))) {
|
||||
foreach($events as $event) {
|
||||
$event = calendar_event::load($event);
|
||||
$event = \core_calendar\event::load($event);
|
||||
$event->delete();
|
||||
}
|
||||
}
|
||||
|
@ -1609,7 +1609,7 @@ class lesson extends lesson_base {
|
|||
}
|
||||
$events = $DB->get_records('event', $conds);
|
||||
foreach ($events as $event) {
|
||||
$eventold = calendar_event::load($event);
|
||||
$eventold = \core_calendar\event::load($event);
|
||||
$eventold->delete();
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ function quiz_delete_override($quiz, $overrideid) {
|
|||
'instance' => $quiz->id, 'groupid' => (int)$override->groupid,
|
||||
'userid' => (int)$override->userid));
|
||||
foreach ($events as $event) {
|
||||
$eventold = calendar_event::load($event);
|
||||
$eventold = \core_calendar\event::load($event);
|
||||
$eventold->delete();
|
||||
}
|
||||
|
||||
|
@ -1284,8 +1284,8 @@ function quiz_update_events($quiz, $override = null) {
|
|||
unset($event->id);
|
||||
}
|
||||
$event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
|
||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||
calendar_event::create($event);
|
||||
// The method \core_calendar\event::create will reuse a db record if the id field is set.
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
if ($timeclose && $addclose) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
|
@ -1302,14 +1302,14 @@ function quiz_update_events($quiz, $override = null) {
|
|||
$event->priority = $closepriorities[$timeclose];
|
||||
}
|
||||
}
|
||||
calendar_event::create($event);
|
||||
\core_calendar\event::create($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete any leftover events.
|
||||
foreach ($oldevents as $badevent) {
|
||||
$badevent = calendar_event::load($badevent);
|
||||
$badevent = \core_calendar\event::load($badevent);
|
||||
$badevent->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ function workshop_delete_instance($id) {
|
|||
// delete the calendar events
|
||||
$events = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
|
||||
foreach ($events as $event) {
|
||||
$event = calendar_event::load($event);
|
||||
$event = \core_calendar\event::load($event);
|
||||
$event->delete();
|
||||
}
|
||||
|
||||
|
@ -1714,7 +1714,7 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
|
|||
unset($event->id);
|
||||
}
|
||||
// update() will reuse a db record if the id field is set
|
||||
$eventobj = new calendar_event($event);
|
||||
$eventobj = new \core_calendar\event($event);
|
||||
$eventobj->update($event, false);
|
||||
}
|
||||
|
||||
|
@ -1729,7 +1729,7 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
|
|||
unset($event->id);
|
||||
}
|
||||
// update() will reuse a db record if the id field is set
|
||||
$eventobj = new calendar_event($event);
|
||||
$eventobj = new \core_calendar\event($event);
|
||||
$eventobj->update($event, false);
|
||||
}
|
||||
|
||||
|
@ -1744,7 +1744,7 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
|
|||
unset($event->id);
|
||||
}
|
||||
// update() will reuse a db record if the id field is set
|
||||
$eventobj = new calendar_event($event);
|
||||
$eventobj = new \core_calendar\event($event);
|
||||
$eventobj->update($event, false);
|
||||
}
|
||||
|
||||
|
@ -1759,13 +1759,13 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
|
|||
unset($event->id);
|
||||
}
|
||||
// update() will reuse a db record if the id field is set
|
||||
$eventobj = new calendar_event($event);
|
||||
$eventobj = new \core_calendar\event($event);
|
||||
$eventobj->update($event, false);
|
||||
}
|
||||
|
||||
// delete any leftover events
|
||||
foreach ($currentevents as $oldevent) {
|
||||
$oldevent = calendar_event::load($oldevent);
|
||||
$oldevent = \core_calendar\event::load($oldevent);
|
||||
$oldevent->delete();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue