diff --git a/calendar/classes/api.php b/calendar/classes/api.php index 8b05c1d2075..a053b9a523b 100644 --- a/calendar/classes/api.php +++ b/calendar/classes/api.php @@ -280,7 +280,7 @@ class api { if (!isset($events[$eventid])) { continue; } - $event = new event($events[$eventid]); + $event = new \calendar_event($events[$eventid]); $popupalt = ''; $component = 'moodle'; if (!empty($event->modulename)) { @@ -1354,7 +1354,7 @@ class api { /** * Return the capability for editing calendar event * - * @param event $event event object + * @param \calendar_event $event event object * @return bool capability to edit event */ public static function can_edit_event($event) { @@ -1444,7 +1444,7 @@ class api { /** * Get event format time * - * @param event $event event object + * @param \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. @@ -1884,7 +1884,7 @@ class api { } else { $return = CALENDAR_IMPORT_EVENT_INSERTED; // Insert. } - if ($createdevent = event::create($eventrecord, false)) { + if ($createdevent = \calendar_event::create($eventrecord, false)) { if (!empty($event->properties['RRULE'])) { // Repeating events. date_default_timezone_set($tz); // Change time zone to parse all events. diff --git a/calendar/classes/event.php b/calendar/classes/event.php deleted file mode 100644 index 62d17faa3ea..00000000000 --- a/calendar/classes/event.php +++ /dev/null @@ -1,784 +0,0 @@ -. - -/** - * Contains the class for the calendar events. - * - * @package core_calendar - * @copyright 2016 Mark Nelson - * @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 - * @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 = api::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 (!\core_calendar\api::can_add_event($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(); - } - } - - return true; - } else { - - if ($checkcapability) { - if (!api::can_edit_event($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), '', '*'); - foreach ($events as $calendarevent) { - $eventargs['objectid'] = $calendarevent->id; - $eventargs['other']['timestart'] = $calendarevent->timestart; - $event = \core\event\calendar_event_updated::create($eventargs); - $event->add_record_snapshot('event', $calendarevent); - $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->add_record_snapshot('event', $this->properties); - $event->trigger(); - } - - 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 an update event. - foreach ($events as $calendarevent) { - // Trigger an event for the update. - $eventargs['objectid'] = $calendarevent->id; - $eventargs['other']['timestart'] = $calendarevent->timestart; - $event = \core\event\calendar_event_updated::create($eventargs); - $event->add_record_snapshot('event', $calendarevent); - $event->trigger(); - } - } - } - - // 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(); - } - } - - // 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; - } else { - // Make this event hidden. - $this->properties->visible = 0; - } - - // Update the database to reflect this change. - $success = $DB->set_field('event', 'visible', $this->properties->visible, array('id' => $this->properties->id)); - $calendarevent = $DB->get_record('event', array('id' => $this->properties->id), '*', MUST_EXIST); - - // 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 - ) - ); - $event = \core\event\calendar_event_updated::create($eventargs); - $event->add_record_snapshot('event', $calendarevent); - $event->trigger(); - - return $success; - } - - /** - * 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); - } -} diff --git a/calendar/classes/local/event/mappers/event_mapper.php b/calendar/classes/local/event/mappers/event_mapper.php index d88b23b5465..9464d88306b 100644 --- a/calendar/classes/local/event/mappers/event_mapper.php +++ b/calendar/classes/local/event/mappers/event_mapper.php @@ -26,7 +26,6 @@ namespace core_calendar\local\event\mappers; defined('MOODLE_INTERNAL') || die(); -use core_calendar\event; use core_calendar\local\interfaces\event_factory_interface; use core_calendar\local\interfaces\event_interface; use core_calendar\local\interfaces\action_event_interface; @@ -53,7 +52,7 @@ class event_mapper implements event_mapper_interface { $this->factory = $factory; } - public function from_legacy_event_to_event(event $legacyevent) { + public function from_legacy_event_to_event(\calendar_event $legacyevent) { $coalesce = function($property) use ($legacyevent) { return property_exists($legacyevent, $property) ? $legacyevent->{$property} : null; }; @@ -85,7 +84,7 @@ class event_mapper implements event_mapper_interface { $action = ($event instanceof action_event_interface) ? $event->get_action() : null; $timeduration = $event->get_times()->get_end_time()->getTimestamp() - $event->get_times()->get_start_time()->getTimestamp(); - return new event($this->from_event_to_stdclass($event)); + return new \calendar_event($this->from_event_to_stdclass($event)); } public function from_event_to_stdclass(event_interface $event) { diff --git a/calendar/classes/local/interfaces/event_mapper_interface.php b/calendar/classes/local/interfaces/event_mapper_interface.php index bed0630c184..3258450873a 100644 --- a/calendar/classes/local/interfaces/event_mapper_interface.php +++ b/calendar/classes/local/interfaces/event_mapper_interface.php @@ -26,8 +26,6 @@ namespace core_calendar\local\interfaces; defined('MOODLE_INTERNAL') || die(); -use core_calendar\event; - /** * Interface for an event mapper class * @@ -38,16 +36,16 @@ interface event_mapper_interface { /** * Map a legacy event to an event. * - * @param event $event The legacy event. + * @param \calendar_event $event The legacy event. * @return event_interface The mapped event. */ - public function from_legacy_event_to_event(event $event); + public function from_legacy_event_to_event(\calendar_event $event); /** * Map an event to a legacy event. * * @param event_interface $event The legacy event. - * @return event The mapped legacy event. + * @return \calendar_event The mapped legacy event. */ public function from_event_to_legacy_event(event_interface $event); diff --git a/calendar/classes/rrule_manager.php b/calendar/classes/rrule_manager.php index f4883e7152c..78cee59681d 100644 --- a/calendar/classes/rrule_manager.php +++ b/calendar/classes/rrule_manager.php @@ -223,7 +223,7 @@ class rrule_manager { /** * Create events for specified rrule. * - * @param event $passedevent Properties of event to create. + * @param \calendar_event $passedevent Properties of event to create. * @throws moodle_exception */ public function create_events($passedevent) { @@ -245,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 event($eventrec); + $calevent = new \calendar_event($eventrec); $updatedata = (object)['timestart' => $eventtimes[0], 'repeatid' => $eventrec->id]; $calevent->update($updatedata, false); $eventrec->timestart = $calevent->timestart; @@ -719,7 +719,7 @@ class rrule_manager { $cloneevent->repeatid = $event->id; $cloneevent->timestart = $time; unset($cloneevent->id); - event::create($cloneevent, false); + \calendar_event::create($cloneevent, false); } } diff --git a/calendar/delete.php b/calendar/delete.php index 68ca6c8cd4a..6ebb06edf7f 100644 --- a/calendar/delete.php +++ b/calendar/delete.php @@ -41,7 +41,7 @@ if(!$site = get_site()) { redirect(new moodle_url('/admin/index.php')); } -$event = \core_calendar\event::load($eventid); +$event = calendar_event::load($eventid); /** * We are going to be picky here, and require that any event types other than diff --git a/calendar/event.php b/calendar/event.php index 12813321f68..dcf655878d9 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -113,7 +113,7 @@ $calendar->prepare_for_view($course, $courses); $formoptions = new stdClass; if ($eventid !== 0) { $title = get_string('editevent', 'calendar'); - $event = \core_calendar\event::load($eventid); + $event = calendar_event::load($eventid); if (!\core_calendar\api::can_edit_event($event)) { print_error('nopermissions'); } @@ -149,7 +149,7 @@ if ($eventid !== 0) { } } $event->timestart = $time; - $event = new \core_calendar\event($event); + $event = new calendar_event($event); if (!\core_calendar\api::can_add_event($event)) { print_error('nopermissions'); } diff --git a/calendar/externallib.php b/calendar/externallib.php index b27af445362..6365dd2f721 100644 --- a/calendar/externallib.php +++ b/calendar/externallib.php @@ -83,7 +83,7 @@ class core_calendar_external extends external_api { $transaction = $DB->start_delegated_transaction(); foreach ($params['events'] as $event) { - $eventobj = \core_calendar\event::load($event['eventid']); + $eventobj = calendar_event::load($event['eventid']); // Let's check if the user is allowed to delete an event. if (!\core_calendar\api::can_edit_event($eventobj)) { @@ -247,7 +247,7 @@ class core_calendar_external extends external_api { foreach ($eventlist as $eventid => $eventobj) { $event = (array) $eventobj; // Description formatting. - $calendareventobj = new \core_calendar\event($event); + $calendareventobj = new calendar_event($event); list($event['description'], $event['format']) = $calendareventobj->format_external_text(); if ($hassystemcap) { @@ -260,7 +260,7 @@ class core_calendar_external extends external_api { } } else { // Can the user actually see this event? - $eventobj = \core_calendar\event::load($eventobj); + $eventobj = 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)) || @@ -620,7 +620,7 @@ class core_calendar_external extends external_api { $event['repeat'] = 0; } - $eventobj = new \core_calendar\event($event); + $eventobj = new calendar_event($event); // Let's check if the user is allowed to delete an event. if (!\core_calendar\api::can_add_event($eventobj)) { diff --git a/calendar/lib.php b/calendar/lib.php index 9a4b8961a6d..597282c78e2 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -135,6 +135,786 @@ define('CALENDAR_EVENT_TYPE_STANDARD', 0); */ define('CALENDAR_EVENT_TYPE_ACTION', 1); +/** + * 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 = \core_calendar\api::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 (!\core_calendar\api::can_add_event($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(); + } + } + + return true; + } else { + + if ($checkcapability) { + if (!\core_calendar\api::can_edit_event($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), '', '*'); + foreach ($events as $calendarevent) { + $eventargs['objectid'] = $calendarevent->id; + $eventargs['other']['timestart'] = $calendarevent->timestart; + $event = \core\event\calendar_event_updated::create($eventargs); + $event->add_record_snapshot('event', $calendarevent); + $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->add_record_snapshot('event', $this->properties); + $event->trigger(); + } + + 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 an update event. + foreach ($events as $calendarevent) { + // Trigger an event for the update. + $eventargs['objectid'] = $calendarevent->id; + $eventargs['other']['timestart'] = $calendarevent->timestart; + $event = \core\event\calendar_event_updated::create($eventargs); + $event->add_record_snapshot('event', $calendarevent); + $event->trigger(); + } + } + } + + // 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(); + } + } + + // 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 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 $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; + } else { + // Make this event hidden. + $this->properties->visible = 0; + } + + // Update the database to reflect this change. + $success = $DB->set_field('event', 'visible', $this->properties->visible, array('id' => $this->properties->id)); + $calendarevent = $DB->get_record('event', array('id' => $this->properties->id), '*', MUST_EXIST); + + // 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 + ) + ); + $event = \core\event\calendar_event_updated::create($eventargs); + $event->add_record_snapshot('event', $calendarevent); + $event->trigger(); + + return $success; + } + + /** + * 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 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 an 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 * diff --git a/calendar/renderer.php b/calendar/renderer.php index 42721b912d9..3b228190dcf 100644 --- a/calendar/renderer.php +++ b/calendar/renderer.php @@ -189,7 +189,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 \core_calendar\event($event); + $event = new calendar_event($event); $event->calendarcourseid = $calendar->courseid; if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now $event->time = \core_calendar\api::get_format_event_time($event, time(), null, false, @@ -220,11 +220,11 @@ class core_calendar_renderer extends plugin_renderer_base { /** * Displays an event * - * @param \core_calendar\event $event + * @param calendar_event $event * @param bool $showactions * @return string */ - public function event(\core_calendar\event $event, $showactions=true) { + public function event(calendar_event $event, $showactions=true) { global $CFG; $event = \core_calendar\api::add_event_metadata($event); @@ -375,7 +375,7 @@ class core_calendar_renderer extends plugin_renderer_base { $calendar->courses); if (!empty($events)) { foreach($events as $eventid => $event) { - $event = new \core_calendar\event($event); + $event = new 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)) { @@ -552,8 +552,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 \core_calendar\event object so that we transform description accordingly. - $event = new \core_calendar\event($event); + // Convert to calendar_event object so that we transform description accordingly. + $event = new calendar_event($event); $event->calendarcourseid = $calendar->courseid; $output .= $this->event($event); } diff --git a/calendar/tests/api_test.php b/calendar/tests/api_test.php index 1383f12fa0d..7b2eaff0a2a 100644 --- a/calendar/tests/api_test.php +++ b/calendar/tests/api_test.php @@ -121,7 +121,7 @@ class core_calendar_api_testcase extends advanced_testcase { ] ]; foreach ($events as $event) { - \core_calendar\event::create($event, false); + calendar_event::create($event, false); } $timestart = time() - 60; $timeend = time() + 60; @@ -232,7 +232,7 @@ class core_calendar_api_testcase extends advanced_testcase { ], ]; foreach ($events as $event) { - \core_calendar\event::create($event, false); + calendar_event::create($event, false); } $timestart = $now - 100; $timeend = $now + (3 * 86400); @@ -298,7 +298,7 @@ class core_calendar_api_testcase extends advanced_testcase { ], ]; foreach ($repeatingevents as $event) { - \core_calendar\event::create($event, false); + calendar_event::create($event, false); } // Make sure repeating events are not filtered out. $events = \core_calendar\api::get_events($timestart, $timeend, true, true, true); diff --git a/calendar/tests/core_container_test.php b/calendar/tests/core_container_test.php index d4df1a1d747..1daca8afca1 100644 --- a/calendar/tests/core_container_test.php +++ b/calendar/tests/core_container_test.php @@ -296,7 +296,7 @@ class core_calendar_container_testcase extends advanced_testcase { * Helper function to create calendar events using the old code. * * @param array $properties A list of calendar event properties to set - * @return \core_calendar\event|bool + * @return calendar_event|bool */ protected function create_event($properties = []) { $record = new \stdClass(); @@ -312,7 +312,7 @@ class core_calendar_container_testcase extends advanced_testcase { $record->$name = $value; } - $event = new \core_calendar\event($record); + $event = new calendar_event($record); return $event->create($record, false); } } diff --git a/calendar/tests/event_factory_test.php b/calendar/tests/event_factory_test.php index 306479d343e..fe369f7f843 100644 --- a/calendar/tests/event_factory_test.php +++ b/calendar/tests/event_factory_test.php @@ -446,7 +446,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase { * Helper function to create calendar events using the old code. * * @param array $properties A list of calendar event properties to set - * @return \core_calendar\event + * @return calendar_event */ protected function create_event($properties = []) { $record = new \stdClass(); @@ -462,7 +462,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase { $record->$name = $value; } - $event = new \core_calendar\event($record); + $event = new calendar_event($record); return $event->create($record, false); } } diff --git a/calendar/tests/event_mapper_test.php b/calendar/tests/event_mapper_test.php index c8a1d270bad..472924ba57b 100644 --- a/calendar/tests/event_mapper_test.php +++ b/calendar/tests/event_mapper_test.php @@ -24,7 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -use core_calendar\event; +global $CFG; +require_once($CFG->dirroot . '/calendar/lib.php'); + use core_calendar\local\event\mappers\event_mapper; use core_calendar\local\event\value_objects\action; use core_calendar\local\event\value_objects\event_description; @@ -68,7 +70,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase { new event_mapper_test_event_factory() ); $legacyevent = $mapper->from_event_to_legacy_event($event); - $this->assertInstanceOf(event::class, $legacyevent); + $this->assertInstanceOf(calendar_event::class, $legacyevent); } /** @@ -121,7 +123,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase { new event_mapper_test_event_factory() ); $legacyevent = $mapper->from_event_to_legacy_event($event); - $this->assertInstanceOf(event::class, $legacyevent); + $this->assertInstanceOf(calendar_event::class, $legacyevent); $this->assertEquals($legacyevent->actionname, 'test action'); $this->assertInstanceOf(\moodle_url::class, $legacyevent->actionurl); $this->assertEquals($legacyevent->actionnum, 1729); @@ -132,7 +134,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase { * Helper function to create calendar events using the old code. * * @param array $properties A list of calendar event properties to set - * @return event + * @return calendar_event */ protected function create_event($properties = []) { $record = new \stdClass(); @@ -148,7 +150,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase { $record->$name = $value; } - $event = new \core_calendar\event($record); + $event = new calendar_event($record); return $event->create($record, false); } } @@ -279,7 +281,7 @@ class event_mapper_test_event implements event_interface { /** * Constructor. * - * @param \core_calendar\event $legacyevent Legacy event to exctract IDs etc from. + * @param calendar_event $legacyevent Legacy event to exctract IDs etc from. */ public function __construct($legacyevent = null) { if ($legacyevent) { diff --git a/calendar/tests/externallib_test.php b/calendar/tests/externallib_test.php index 96900918743..62f93363104 100644 --- a/calendar/tests/externallib_test.php +++ b/calendar/tests/externallib_test.php @@ -126,7 +126,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase { $prop->priority = $priority; } - $event = new \core_calendar\event($prop); + $event = new calendar_event($prop); return $event->create($prop); } diff --git a/calendar/tests/helpers.php b/calendar/tests/helpers.php index 371d5fa91ba..b3e3404b9d7 100644 --- a/calendar/tests/helpers.php +++ b/calendar/tests/helpers.php @@ -41,7 +41,7 @@ use core_calendar\local\interfaces\event_factory_interface; * Create a calendar event with the given properties. * * @param array $properties The properties to set on the event - * @return \core_calendar\event + * @return \calendar_event */ function create_event($properties) { $record = new \stdClass(); @@ -59,7 +59,7 @@ function create_event($properties) { $record->$name = $value; } - $event = new \core_calendar\event($record); + $event = new \calendar_event($record); return $event->create($record); } diff --git a/calendar/tests/raw_event_retrieval_strategy_test.php b/calendar/tests/raw_event_retrieval_strategy_test.php index 7ebf9cfa6e2..cbf8d706d40 100644 --- a/calendar/tests/raw_event_retrieval_strategy_test.php +++ b/calendar/tests/raw_event_retrieval_strategy_test.php @@ -80,7 +80,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc ]; foreach ($events as $event) { - \core_calendar\event::create($event, false); + calendar_event::create($event, false); } // Get all events. @@ -200,7 +200,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc ]; foreach ($events as $event) { - \core_calendar\event::create($event, false); + calendar_event::create($event, false); } $timestart = $now - 100; @@ -270,7 +270,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc ]; foreach ($repeatingevents as $event) { - \core_calendar\event::create($event, false); + calendar_event::create($event, false); } // Make sure repeating events are not filtered out. diff --git a/calendar/tests/repeat_event_collection_test.php b/calendar/tests/repeat_event_collection_test.php index 33334b40ef6..b8f46a46c39 100644 --- a/calendar/tests/repeat_event_collection_test.php +++ b/calendar/tests/repeat_event_collection_test.php @@ -118,7 +118,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase { * Helper function to create calendar events using the old code. * * @param array $properties A list of calendar event properties to set - * @return \core_calendar\event + * @return calendar_event */ protected function create_event($properties = []) { $record = new \stdClass(); @@ -136,7 +136,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase { $record->$name = $value; } - $event = new \core_calendar\event($record); + $event = new calendar_event($record); return $event->create($record, false); } } diff --git a/calendar/tests/rrule_manager_test.php b/calendar/tests/rrule_manager_test.php index 11b16627a25..2b0f315a953 100644 --- a/calendar/tests/rrule_manager_test.php +++ b/calendar/tests/rrule_manager_test.php @@ -40,7 +40,7 @@ use core_calendar\rrule_manager; */ class core_calendar_rrule_manager_testcase extends advanced_testcase { - /** @var core_calendar\event a dummy event */ + /** @var calendar_event a dummy event */ protected $event; /** @@ -78,7 +78,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase { $event->groupid = 0; $event->courseid = 0; $event->eventtype = 'user'; - $eventobj = core_calendar\event::create($event, false); + $eventobj = calendar_event::create($event, false); $DB->set_field('event', 'repeatid', $eventobj->id, array('id' => $eventobj->id)); $eventobj->repeatid = $eventobj->id; $this->event = $eventobj; @@ -2703,7 +2703,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase { $newdatetime = DateTime::createFromFormat('Ymd\THis', $datestr, $timezone); // Update the start date of the parent event. - $calevent = core_calendar\event::load($this->event->id); + $calevent = calendar_event::load($this->event->id); $updatedata = (object)[ 'timestart' => $newdatetime->getTimestamp(), 'repeatid' => $this->event->id diff --git a/completion/classes/api.php b/completion/classes/api.php index 022ac52b1ac..418d8498866 100644 --- a/completion/classes/api.php +++ b/completion/classes/api.php @@ -85,11 +85,11 @@ class api { $event->visible = instance_is_visible($modulename, $instance); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = \calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is no longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = \calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -107,7 +107,7 @@ class api { $event->visible = instance_is_visible($modulename, $instance); $event->timeduration = 0; - \core_calendar\event::create($event); + \calendar_event::create($event); } } diff --git a/course/lib.php b/course/lib.php index 0224c84ba59..980173f8307 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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 \core_calendar\event($event); + $event = new calendar_event($event); $event->toggle_visibility(true); } else { - $event = new \core_calendar\event($event); + $event = new 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 = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } diff --git a/course/tests/courselib_test.php b/course/tests/courselib_test.php index d80cca2e1f6..52edef8b1f9 100644 --- a/course/tests/courselib_test.php +++ b/course/tests/courselib_test.php @@ -1213,7 +1213,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 \core_calendar\event($event); + $calevent = new calendar_event($event); $this->assertEquals($visibility, $calevent->visible, "$cm->modname calendar_event visibility"); } } diff --git a/lib/db/renamedclasses.php b/lib/db/renamedclasses.php index f60c4a126b5..30d4b42fb36 100644 --- a/lib/db/renamedclasses.php +++ b/lib/db/renamedclasses.php @@ -45,7 +45,5 @@ $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_search\area\base_activity' => 'core_search\base_activity', - 'calendar_event' => 'core_calendar\event' + 'core_competency\\external\\user_summary_exporter' => 'core_user\\external\\user_summary_exporter' ); diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index d6fd428aaf2..0a2eaf74c6b 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -1163,41 +1163,41 @@ function navmenu($course, $cm=NULL, $targetwindow='self') { /** - * @deprecated please use \core_calendar\event::create() instead. + * @deprecated please use calendar_event::create() instead. */ function add_event($event) { - throw new coding_exception('add_event() can not be used any more, please use \core_calendar\event::create() instead.'); + throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.'); } /** - * @deprecated please \core_calendar\event->update() instead. + * @deprecated please calendar_event->update() instead. */ function update_event($event) { - throw new coding_exception('update_event() is removed, please use \core_calendar\event->update() instead.'); + throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.'); } /** - * @deprecated please use \core_calendar\event->delete() instead. + * @deprecated please use calendar_event->delete() instead. */ function delete_event($id) { throw new coding_exception('delete_event() can not be used any more, please use '. - '\core_calendar\event->delete() instead.'); + 'calendar_event->delete() instead.'); } /** - * @deprecated please use \core_calendar\event->toggle_visibility(false) instead. + * @deprecated please use calendar_event->toggle_visibility(false) instead. */ function hide_event($event) { throw new coding_exception('hide_event() can not be used any more, please use '. - '\core_calendar\event->toggle_visibility(false) instead.'); + 'calendar_event->toggle_visibility(false) instead.'); } /** - * @deprecated please use \core_calendar\event->toggle_visibility(true) instead. + * @deprecated please use calendar_event->toggle_visibility(true) instead. */ function show_event($event) { throw new coding_exception('show_event() can not be used any more, please use '. - '\core_calendar\event->toggle_visibility(true) instead.'); + 'calendar_event->toggle_visibility(true) instead.'); } /** @@ -7177,7 +7177,7 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) { * Return the capability for editing calendar event. * * @deprecated since 3.3 - * @param \core_calendar\event $event event object + * @param calendar_event $event event object * @return bool capability to edit event */ function calendar_edit_event_allowed($event) { @@ -7204,7 +7204,7 @@ function calendar_get_default_courses() { * Get event format time. * * @deprecated since 3.3 - * @param \core_calendar\event $event event object + * @param 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. diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 2ec85f03cc6..78bd18ffc2e 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -69,7 +69,6 @@ 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. * YUI module moodle-core-formautosubmit has been removed, use jquery .change() instead (see lib/templates/url_select.mustache for an example) * Changed the pix mustache template helper to accept context variables for the key, component and alt text. diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 70b211a388c..f9fb3e20034 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -300,13 +300,13 @@ function assign_update_events($assign, $override = null) { unset($event->id); } $event->name = $eventname.' ('.get_string('duedate', 'assign').')'; - \core_calendar\event::create($event); + calendar_event::create($event); } } // Delete any leftover events. foreach ($oldevents as $badevent) { - $badevent = \core_calendar\event::load($badevent); + $badevent = calendar_event::load($badevent); $badevent->delete(); } } @@ -1714,10 +1714,10 @@ function assign_check_updates_since(cm_info $cm, $from, $filter = array()) { * the ASSIGN_EVENT_TYPE_GRADINGDUE event will not be shown to students on their calendar, and * ASSIGN_EVENT_TYPE_DUE events will not be shown to teachers. * - * @param \core_calendar\event $event + * @param calendar_event $event * @return bool Returns true if the event is visible to the current user, false otherwise. */ -function mod_assign_core_calendar_is_event_visible(\core_calendar\event $event) { +function mod_assign_core_calendar_is_event_visible(calendar_event $event) { global $CFG, $USER; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -1737,11 +1737,11 @@ function mod_assign_core_calendar_is_event_visible(\core_calendar\event $event) /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_assign_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_assign_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $CFG, $USER; @@ -1794,11 +1794,11 @@ function mod_assign_core_calendar_provide_event_action(\core_calendar\event $eve * Callback function that determines whether an action event should be showing its item count * based on the event type and the item count. * - * @param \core_calendar\event $event The calendar event. + * @param calendar_event $event The calendar event. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_assign_core_calendar_event_action_shows_item_count(\core_calendar\event $event, $itemcount = 0) { +function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { // List of event types where the action event's item count should be shown. $eventtypesshowingitemcount = [ ASSIGN_EVENT_TYPE_GRADINGDUE diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 4ca21b3fcc0..a9808d422bf 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -799,7 +799,7 @@ class assign { } $events = $DB->get_records('event', $conds); foreach ($events as $event) { - $eventold = \core_calendar\event::load($event); + $eventold = calendar_event::load($event); $eventold->delete(); } @@ -1212,10 +1212,10 @@ class assign { // Now process the event. if ($event->id) { - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { - \core_calendar\event::create($event); + calendar_event::create($event); } } else { $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id, @@ -1232,10 +1232,10 @@ class assign { // Now process the event. if ($event->id) { - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { - \core_calendar\event::create($event); + calendar_event::create($event); } } else { $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id, diff --git a/mod/assign/tests/lib_test.php b/mod/assign/tests/lib_test.php index 2a568af4907..62e3bdd712c 100644 --- a/mod/assign/tests/lib_test.php +++ b/mod/assign/tests/lib_test.php @@ -593,7 +593,7 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase { * * @param int $instanceid The assign id. * @param string $eventtype The event type. eg. ASSIGN_EVENT_TYPE_DUE. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($instanceid, $eventtype) { $event = new stdClass(); @@ -605,6 +605,6 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/book/lib.php b/mod/book/lib.php index b0e0e360bbf..04b11c09cdd 100644 --- a/mod/book/lib.php +++ b/mod/book/lib.php @@ -701,11 +701,11 @@ function mod_book_get_fontawesome_icon_map() { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_book_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_book_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['book'][$event->instance]; $context = context_module::instance($cm->id); diff --git a/mod/book/tests/lib_test.php b/mod/book/tests/lib_test.php index 8838385cc64..39015a305b8 100644 --- a/mod/book/tests/lib_test.php +++ b/mod/book/tests/lib_test.php @@ -222,7 +222,7 @@ class mod_book_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -234,6 +234,6 @@ class mod_book_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 8d95641a539..bc4d8639335 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -131,7 +131,7 @@ function chat_add_instance($chat) { $event->timesort = $chat->chattime; $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } return $returnid; } @@ -164,11 +164,11 @@ function chat_update_instance($chat) { $event->timestart = $chat->chattime; $event->timesort = $chat->chattime; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Do not publish this event, so delete it. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -188,7 +188,7 @@ function chat_update_instance($chat) { $event->timesort = $chat->chattime; $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } @@ -456,7 +456,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 = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else if ($chat->schedule > 0) { // The chat is scheduled and the event should be published. @@ -469,7 +469,7 @@ function chat_refresh_events($courseid = 0) { $event->timeduration = 0; $event->visible = $DB->get_field('course_modules', 'visible', array('module' => $moduleid, 'instance' => $chat->id)); - \core_calendar\event::create($event); + calendar_event::create($event); } } return true; @@ -675,7 +675,7 @@ function chat_update_chat_times($chatid=0) { if ($event->id = $DB->get_field_select('event', 'id', $cond, $params)) { $event->timestart = $chat->chattime; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event, false); } } @@ -1410,11 +1410,11 @@ function chat_view($chat, $course, $cm, $context) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_chat_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_chat_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $DB; diff --git a/mod/chat/tests/lib_test.php b/mod/chat/tests/lib_test.php index c0533030d04..4edef1aea5a 100644 --- a/mod/chat/tests/lib_test.php +++ b/mod/chat/tests/lib_test.php @@ -149,7 +149,7 @@ class mod_chat_lib_testcase extends advanced_testcase { * @param int $courseid * @param int $instanceid The chat id. * @param string $eventtype The event type. eg. ASSIGN_EVENT_TYPE_DUE. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -161,6 +161,6 @@ class mod_chat_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/choice/lib.php b/mod/choice/lib.php index b1bed45e0fd..abb250441a5 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -1185,11 +1185,11 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_choice_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_choice_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $DB; diff --git a/mod/choice/locallib.php b/mod/choice/locallib.php index d87fb134cb4..ab33373c14e 100644 --- a/mod/choice/locallib.php +++ b/mod/choice/locallib.php @@ -57,11 +57,11 @@ function choice_set_events($choice) { $event->timesort = $choice->timeopen; $event->visible = instance_is_visible('choice', $choice); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -78,7 +78,7 @@ function choice_set_events($choice) { $event->timesort = $choice->timeopen; $event->visible = instance_is_visible('choice', $choice); $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } @@ -96,11 +96,11 @@ function choice_set_events($choice) { $event->timesort = $choice->timeclose; $event->visible = instance_is_visible('choice', $choice); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -117,7 +117,7 @@ function choice_set_events($choice) { $event->timesort = $choice->timeclose; $event->visible = instance_is_visible('choice', $choice); $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } } diff --git a/mod/choice/tests/lib_test.php b/mod/choice/tests/lib_test.php index a3105ccdae8..97323c1d94e 100644 --- a/mod/choice/tests/lib_test.php +++ b/mod/choice/tests/lib_test.php @@ -385,7 +385,7 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase { * @param int $courseid * @param int $instanceid The choice id. * @param string $eventtype The event type. eg. CHOICE_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -397,6 +397,6 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/data/lib.php b/mod/data/lib.php index 098092fa072..952d749a36d 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -1057,7 +1057,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 = \core_calendar\event::load($event); + $event = calendar_event::load($event); $event->delete(); } @@ -4219,11 +4219,11 @@ function data_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_data_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_data_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $DB; diff --git a/mod/data/locallib.php b/mod/data/locallib.php index 9903162ad38..89624ef5858 100644 --- a/mod/data/locallib.php +++ b/mod/data/locallib.php @@ -612,11 +612,11 @@ function data_set_events($data) { $event->timesort = $data->timeavailablefrom; $event->visible = instance_is_visible('data', $data); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -633,7 +633,7 @@ function data_set_events($data) { $event->timesort = $data->timeavailablefrom; $event->visible = instance_is_visible('data', $data); $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } @@ -651,11 +651,11 @@ function data_set_events($data) { $event->timesort = $data->timeavailableto; $event->visible = instance_is_visible('data', $data); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -672,7 +672,7 @@ function data_set_events($data) { $event->timesort = $data->timeavailableto; $event->visible = instance_is_visible('data', $data); $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } } diff --git a/mod/data/tests/lib_test.php b/mod/data/tests/lib_test.php index 18348261a67..f8aa5ca82ff 100644 --- a/mod/data/tests/lib_test.php +++ b/mod/data/tests/lib_test.php @@ -1116,7 +1116,7 @@ class mod_data_lib_testcase extends advanced_testcase { * @param int $courseid * @param int $instanceid The data id. * @param string $eventtype The event type. eg. DATA_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -1128,6 +1128,6 @@ class mod_data_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 9eb476bb38b..ef64fdbc089 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -818,7 +818,7 @@ function feedback_set_events($feedback) { if ($eventid) { // Calendar event exists so update it. $event->id = $eventid; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Event doesn't exist so create one. @@ -828,11 +828,11 @@ function feedback_set_events($feedback) { $event->modulename = 'feedback'; $event->instance = $feedback->id; $event->eventtype = FEEDBACK_EVENT_TYPE_OPEN; - \core_calendar\event::create($event); + calendar_event::create($event); } } else if ($eventid) { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($eventid); + $calendarevent = calendar_event::load($eventid); $calendarevent->delete(); } @@ -853,7 +853,7 @@ function feedback_set_events($feedback) { if ($eventid) { // Calendar event exists so update it. $event->id = $eventid; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Event doesn't exist so create one. @@ -862,11 +862,11 @@ function feedback_set_events($feedback) { $event->userid = 0; $event->modulename = 'feedback'; $event->instance = $feedback->id; - \core_calendar\event::create($event); + calendar_event::create($event); } } else if ($eventid) { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($eventid); + $calendarevent = calendar_event::load($eventid); $calendarevent->delete(); } } @@ -3372,11 +3372,11 @@ function feedback_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_feedback_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_feedback_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $DB; diff --git a/mod/feedback/tests/lib_test.php b/mod/feedback/tests/lib_test.php index 3388c64728e..5f92789719d 100644 --- a/mod/feedback/tests/lib_test.php +++ b/mod/feedback/tests/lib_test.php @@ -235,7 +235,7 @@ class mod_feedback_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The feedback id. * @param string $eventtype The event type. eg. FEEDBACK_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -247,6 +247,6 @@ class mod_feedback_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/folder/lib.php b/mod/folder/lib.php index ca899121db5..161cd02d454 100644 --- a/mod/folder/lib.php +++ b/mod/folder/lib.php @@ -774,11 +774,11 @@ function folder_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_folder_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_folder_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['folder'][$event->instance]; diff --git a/mod/folder/tests/lib_test.php b/mod/folder/tests/lib_test.php index 45c920c2e6c..c4b33156ff7 100644 --- a/mod/folder/tests/lib_test.php +++ b/mod/folder/tests/lib_test.php @@ -155,7 +155,7 @@ class mod_folder_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -167,6 +167,6 @@ class mod_folder_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 91243a86fa5..0785ceb9133 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -8129,11 +8129,11 @@ function mod_forum_get_fontawesome_icon_map() { * Callback function that determines whether an action event should be showing its item count * based on the event type and the item count. * - * @param \core_calendar\event $event The calendar event. + * @param calendar_event $event The calendar event. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_forum_core_calendar_event_action_shows_item_count(\core_calendar\event $event, $itemcount = 0) { +function mod_forum_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { // Always show item count for forums if item count is greater than 0. return $itemcount > 0; } @@ -8141,11 +8141,11 @@ function mod_forum_core_calendar_event_action_shows_item_count(\core_calendar\ev /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_forum_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_forum_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['forum'][$event->instance]; $context = context_module::instance($cm->id); diff --git a/mod/forum/tests/lib_test.php b/mod/forum/tests/lib_test.php index d83a32cb9b8..0af8f261598 100644 --- a/mod/forum/tests/lib_test.php +++ b/mod/forum/tests/lib_test.php @@ -3416,7 +3416,7 @@ class mod_forum_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -3428,6 +3428,6 @@ class mod_forum_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 91af3008da9..f145becbbe2 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -4173,11 +4173,11 @@ function forum_get_fontawesome_icon_map() { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_glossary_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_glossary_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['glossary'][$event->instance]; diff --git a/mod/glossary/tests/lib_test.php b/mod/glossary/tests/lib_test.php index 3e95f8afeab..df2be0c07f3 100644 --- a/mod/glossary/tests/lib_test.php +++ b/mod/glossary/tests/lib_test.php @@ -180,7 +180,7 @@ class mod_glossary_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -192,6 +192,6 @@ class mod_glossary_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/imscp/lib.php b/mod/imscp/lib.php index c23ecb4833d..cc0dbdca34e 100644 --- a/mod/imscp/lib.php +++ b/mod/imscp/lib.php @@ -471,11 +471,11 @@ function imscp_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_imscp_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_imscp_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['imscp'][$event->instance]; diff --git a/mod/imscp/tests/lib_test.php b/mod/imscp/tests/lib_test.php index a40fd434d50..cd2e13e9718 100644 --- a/mod/imscp/tests/lib_test.php +++ b/mod/imscp/tests/lib_test.php @@ -173,7 +173,7 @@ class mod_imscp_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -185,6 +185,6 @@ class mod_imscp_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/label/lib.php b/mod/label/lib.php index a057f138f79..d456100e4ff 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -353,11 +353,11 @@ function label_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_label_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_label_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['label'][$event->instance]; diff --git a/mod/label/tests/lib_test.php b/mod/label/tests/lib_test.php index 347d75c45bd..38d9834945d 100644 --- a/mod/label/tests/lib_test.php +++ b/mod/label/tests/lib_test.php @@ -104,7 +104,7 @@ class mod_label_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -116,6 +116,6 @@ class mod_label_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } \ No newline at end of file diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index d7a2dfbb282..65f2c820adb 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -208,8 +208,8 @@ function lesson_update_events($lesson, $override = null) { unset($event->id); } $event->name = $eventname.' ('.get_string('lessonopens', 'lesson').')'; - // The method \core_calendar\event::create will reuse a db record if the id field is set. - \core_calendar\event::create($event); + // The method calendar_event::create will reuse a db record if the id field is set. + calendar_event::create($event); } if ($deadline && $addclose) { if ($oldevent = array_shift($oldevents)) { @@ -228,14 +228,14 @@ function lesson_update_events($lesson, $override = null) { $event->priority = $closepriorities[$deadline]; } } - \core_calendar\event::create($event); + calendar_event::create($event); } } } // Delete any leftover events. foreach ($oldevents as $badevent) { - $badevent = \core_calendar\event::load($badevent); + $badevent = calendar_event::load($badevent); $badevent->delete(); } } @@ -1570,11 +1570,11 @@ function lesson_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_lesson_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_lesson_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $DB, $CFG, $USER; require_once($CFG->dirroot . '/mod/lesson/locallib.php'); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 4cabf511e0f..fff9f82e672 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -1575,7 +1575,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 = \core_calendar\event::load($event); + $event = calendar_event::load($event); $event->delete(); } } @@ -1613,7 +1613,7 @@ class lesson extends lesson_base { } $events = $DB->get_records('event', $conds); foreach ($events as $event) { - $eventold = \core_calendar\event::load($event); + $eventold = calendar_event::load($event); $eventold->delete(); } diff --git a/mod/lesson/tests/lib_test.php b/mod/lesson/tests/lib_test.php index 5f687449af3..7bd187d3852 100644 --- a/mod/lesson/tests/lib_test.php +++ b/mod/lesson/tests/lib_test.php @@ -276,7 +276,7 @@ class mod_lesson_lib_testcase extends advanced_testcase { * @param int $courseid * @param int $instanceid The lesson id. * @param string $eventtype The event type. eg. LESSON_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -287,6 +287,6 @@ class mod_lesson_lib_testcase extends advanced_testcase { $event->type = CALENDAR_EVENT_TYPE_ACTION; $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/lti/lib.php b/mod/lti/lib.php index 146d72cdf73..e7df1cbc256 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -628,11 +628,11 @@ function mod_lti_get_fontawesome_icon_map() { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_lti_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_lti_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['lti'][$event->instance]; diff --git a/mod/lti/tests/lib_test.php b/mod/lti/tests/lib_test.php index 14cb1fe07dc..b5267131716 100644 --- a/mod/lti/tests/lib_test.php +++ b/mod/lti/tests/lib_test.php @@ -171,7 +171,7 @@ class mod_lti_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -183,6 +183,6 @@ class mod_lti_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/page/lib.php b/mod/page/lib.php index 8d2a62d5a2b..b1f5a844ee3 100644 --- a/mod/page/lib.php +++ b/mod/page/lib.php @@ -535,11 +535,11 @@ function page_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_page_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_page_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['page'][$event->instance]; diff --git a/mod/page/tests/lib_test.php b/mod/page/tests/lib_test.php index 616e7e92711..809455100b2 100644 --- a/mod/page/tests/lib_test.php +++ b/mod/page/tests/lib_test.php @@ -155,7 +155,7 @@ class mod_page_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -167,6 +167,6 @@ class mod_page_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 99a7dadb96f..47ac20fffe9 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -197,7 +197,7 @@ function quiz_delete_instance($id) { $events = $DB->get_records('event', array('modulename' => 'quiz', 'instance' => $quiz->id)); foreach ($events as $event) { - $event = core_calendar\event::load($event); + $event = calendar_event::load($event); $event->delete(); } @@ -229,7 +229,7 @@ function quiz_delete_override($quiz, $overrideid) { 'instance' => $quiz->id, 'groupid' => (int)$override->groupid, 'userid' => (int)$override->userid)); foreach ($events as $event) { - $eventold = \core_calendar\event::load($event); + $eventold = calendar_event::load($event); $eventold->delete(); } @@ -1292,8 +1292,8 @@ function quiz_update_events($quiz, $override = null) { unset($event->id); } $event->name = $eventname.' ('.get_string('quizopens', 'quiz').')'; - // The method \core_calendar\event::create will reuse a db record if the id field is set. - \core_calendar\event::create($event); + // The method calendar_event::create will reuse a db record if the id field is set. + calendar_event::create($event); } if ($timeclose && $addclose) { if ($oldevent = array_shift($oldevents)) { @@ -1312,14 +1312,14 @@ function quiz_update_events($quiz, $override = null) { $event->priority = $closepriorities[$timeclose]; } } - \core_calendar\event::create($event); + calendar_event::create($event); } } } // Delete any leftover events. foreach ($oldevents as $badevent) { - $badevent = \core_calendar\event::load($badevent); + $badevent = calendar_event::load($badevent); $badevent->delete(); } } @@ -2079,11 +2079,11 @@ function mod_quiz_get_fontawesome_icon_map() { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_quiz_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_quiz_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $CFG, $USER; diff --git a/mod/quiz/tests/lib_test.php b/mod/quiz/tests/lib_test.php index 1c31d26a023..a7bf1d2df6c 100644 --- a/mod/quiz/tests/lib_test.php +++ b/mod/quiz/tests/lib_test.php @@ -676,7 +676,7 @@ class mod_quiz_lib_testcase extends advanced_testcase { * @param int $courseid * @param int $instanceid The quiz id. * @param string $eventtype The event type. eg. QUIZ_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -688,7 +688,7 @@ class mod_quiz_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 104e5662a5e..da5f0fa60fe 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -550,11 +550,11 @@ function resource_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_resource_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_resource_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['resource'][$event->instance]; diff --git a/mod/resource/tests/lib_test.php b/mod/resource/tests/lib_test.php index 9f008c9ae30..0b740f5468c 100644 --- a/mod/resource/tests/lib_test.php +++ b/mod/resource/tests/lib_test.php @@ -218,7 +218,7 @@ class mod_resource_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -230,6 +230,6 @@ class mod_resource_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index efe0dbdcb3f..c57a12a352f 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1595,11 +1595,11 @@ function scorm_refresh_events($courseid = 0) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_scorm_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_scorm_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { global $CFG, $DB; diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 4f08a3bf245..869de923df9 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -2384,11 +2384,11 @@ function scorm_update_calendar(stdClass $scorm, $cmid) { $event->visible = instance_is_visible('scorm', $scorm); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -2406,7 +2406,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) { $event->visible = instance_is_visible('scorm', $scorm); $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } @@ -2425,11 +2425,11 @@ function scorm_update_calendar(stdClass $scorm, $cmid) { $event->visible = instance_is_visible('scorm', $scorm); $event->timeduration = 0; - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->update($event); } else { // Calendar event is on longer needed. - $calendarevent = \core_calendar\event::load($event->id); + $calendarevent = calendar_event::load($event->id); $calendarevent->delete(); } } else { @@ -2447,7 +2447,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) { $event->visible = instance_is_visible('scorm', $scorm); $event->timeduration = 0; - \core_calendar\event::create($event); + calendar_event::create($event); } } diff --git a/mod/scorm/tests/lib_test.php b/mod/scorm/tests/lib_test.php index 893d5d5adf8..fcc928b9339 100644 --- a/mod/scorm/tests/lib_test.php +++ b/mod/scorm/tests/lib_test.php @@ -313,7 +313,7 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase { * @param int $courseid * @param int $instanceid The data id. * @param string $eventtype The event type. eg. DATA_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -325,6 +325,6 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/survey/lib.php b/mod/survey/lib.php index fe3cff31a59..e7cb63acee3 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -1089,11 +1089,11 @@ function survey_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_survey_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_survey_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['survey'][$event->instance]; $context = context_module::instance($cm->id); diff --git a/mod/survey/tests/lib_test.php b/mod/survey/tests/lib_test.php index 81bd4304721..545b96a175b 100644 --- a/mod/survey/tests/lib_test.php +++ b/mod/survey/tests/lib_test.php @@ -261,7 +261,7 @@ class mod_survey_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -273,6 +273,6 @@ class mod_survey_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/url/lib.php b/mod/url/lib.php index f0b244e7cd5..b0aa75e9856 100644 --- a/mod/url/lib.php +++ b/mod/url/lib.php @@ -378,11 +378,11 @@ function url_check_updates_since(cm_info $cm, $from, $filter = array()) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_url_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_url_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['url'][$event->instance]; diff --git a/mod/url/tests/lib_test.php b/mod/url/tests/lib_test.php index 39c3d1dde49..571ee2a2dc7 100644 --- a/mod/url/tests/lib_test.php +++ b/mod/url/tests/lib_test.php @@ -182,7 +182,7 @@ class mod_url_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -194,6 +194,6 @@ class mod_url_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } \ No newline at end of file diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index 7fbe38b1ced..24984cd8b81 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -804,11 +804,11 @@ function mod_wiki_get_fontawesome_icon_map() { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_wiki_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_wiki_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['wiki'][$event->instance]; diff --git a/mod/wiki/tests/lib_test.php b/mod/wiki/tests/lib_test.php index 99c8428d0aa..9ecaf09a7a2 100644 --- a/mod/wiki/tests/lib_test.php +++ b/mod/wiki/tests/lib_test.php @@ -805,7 +805,7 @@ class mod_wiki_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The instance id. * @param string $eventtype The event type. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -817,6 +817,6 @@ class mod_wiki_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } } diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 29df113505c..d08b7218e4d 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -270,7 +270,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 = \core_calendar\event::load($event); + $event = calendar_event::load($event); $event->delete(); } @@ -1721,7 +1721,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 \core_calendar\event($event); + $eventobj = new calendar_event($event); $eventobj->update($event, false); } @@ -1739,7 +1739,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 \core_calendar\event($event); + $eventobj = new calendar_event($event); $eventobj->update($event, false); } @@ -1757,7 +1757,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 \core_calendar\event($event); + $eventobj = new calendar_event($event); $eventobj->update($event, false); } @@ -1775,13 +1775,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 \core_calendar\event($event); + $eventobj = new calendar_event($event); $eventobj->update($event, false); } // delete any leftover events foreach ($currentevents as $oldevent) { - $oldevent = \core_calendar\event::load($oldevent); + $oldevent = calendar_event::load($oldevent); $oldevent->delete(); } } @@ -1789,11 +1789,11 @@ function workshop_calendar_update(stdClass $workshop, $cmid) { /** * Handles creating actions for events. * - * @param \core_calendar\event $event + * @param calendar_event $event * @param \core_calendar\action_factory $factory * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null */ -function mod_workshop_core_calendar_provide_event_action(\core_calendar\event $event, +function mod_workshop_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { $cm = get_fast_modinfo($event->courseid)->instances['workshop'][$event->instance]; diff --git a/mod/workshop/tests/lib_test.php b/mod/workshop/tests/lib_test.php index 439b41f7681..9c745a7af7d 100644 --- a/mod/workshop/tests/lib_test.php +++ b/mod/workshop/tests/lib_test.php @@ -131,7 +131,7 @@ class mod_workshop_lib_testcase extends advanced_testcase { * @param int $courseid The course id. * @param int $instanceid The workshop id. * @param string $eventtype The event type. eg. WORKSHOP_EVENT_TYPE_OPEN. - * @return bool|\core_calendar\event + * @return bool|calendar_event */ private function create_action_event($courseid, $instanceid, $eventtype) { $event = new stdClass(); @@ -143,6 +143,6 @@ class mod_workshop_lib_testcase extends advanced_testcase { $event->eventtype = $eventtype; $event->timestart = time(); - return \core_calendar\event::create($event); + return calendar_event::create($event); } }