Part of MDL-55611 epic.
if (!isset($events[$eventid])) {
continue;
}
- $event = new event($events[$eventid]);
+ $event = new \calendar_event($events[$eventid]);
$popupalt = '';
$component = 'moodle';
if (!empty($event->modulename)) {
/**
* 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) {
/**
* 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.
} 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.
+++ /dev/null
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains the class for the calendar events.
- *
- * @package core_calendar
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_calendar;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/calendar/lib.php');
-
-/**
- * The class for the calendar events.
- *
- * @package core_calendar
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class event {
-
- /** @var array An object containing the event properties can be accessed via the magic __get/set methods */
- protected $properties = null;
-
- /** @var string The converted event discription with file paths resolved.
- * This gets populated when someone requests description for the first time */
- protected $_description = null;
-
- /** @var array The options to use with this description editor */
- protected $editoroptions = array(
- 'subdirs' => false,
- 'forcehttps' => false,
- 'maxfiles' => -1,
- 'maxbytes' => null,
- 'trusttext' => false);
-
- /** @var object The context to use with the description editor */
- protected $editorcontext = null;
-
- /**
- * Instantiates a new event and optionally populates its properties with the data provided.
- *
- * @param \stdClass $data Optional. An object containing the properties to for
- * an event
- */
- public function __construct($data = null) {
- global $CFG, $USER;
-
- // First convert to object if it is not already (should either be object or assoc array).
- if (!is_object($data)) {
- $data = (object) $data;
- }
-
- $this->editoroptions['maxbytes'] = $CFG->maxbytes;
-
- $data->eventrepeats = 0;
-
- if (empty($data->id)) {
- $data->id = null;
- }
-
- if (!empty($data->subscriptionid)) {
- $data->subscription = 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);
- }
-}
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;
$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;
};
$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) {
defined('MOODLE_INTERNAL') || die();
-use core_calendar\event;
-
/**
* Interface for an event mapper class
*
/**
* 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);
/**
* 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) {
// 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;
$cloneevent->repeatid = $event->id;
$cloneevent->timestart = $time;
unset($cloneevent->id);
- event::create($cloneevent, false);
+ \calendar_event::create($cloneevent, false);
}
}
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
$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');
}
}
}
$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');
}
$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)) {
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) {
}
} 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)) ||
$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)) {
*/
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
*
$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,
/**
* 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);
$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)) {
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);
}
]
];
foreach ($events as $event) {
- \core_calendar\event::create($event, false);
+ calendar_event::create($event, false);
}
$timestart = time() - 60;
$timeend = time() + 60;
],
];
foreach ($events as $event) {
- \core_calendar\event::create($event, false);
+ calendar_event::create($event, false);
}
$timestart = $now - 100;
$timeend = $now + (3 * 86400);
],
];
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);
* 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();
$record->$name = $value;
}
- $event = new \core_calendar\event($record);
+ $event = new calendar_event($record);
return $event->create($record, false);
}
}
* 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();
$record->$name = $value;
}
- $event = new \core_calendar\event($record);
+ $event = new calendar_event($record);
return $event->create($record, false);
}
}
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;
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);
}
/**
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);
* 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();
$record->$name = $value;
}
- $event = new \core_calendar\event($record);
+ $event = new calendar_event($record);
return $event->create($record, false);
}
}
/**
* 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) {
$prop->priority = $priority;
}
- $event = new \core_calendar\event($prop);
+ $event = new calendar_event($prop);
return $event->create($prop);
}
* 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();
$record->$name = $value;
}
- $event = new \core_calendar\event($record);
+ $event = new \calendar_event($record);
return $event->create($record);
}
];
foreach ($events as $event) {
- \core_calendar\event::create($event, false);
+ calendar_event::create($event, false);
}
// Get all events.
];
foreach ($events as $event) {
- \core_calendar\event::create($event, false);
+ calendar_event::create($event, false);
}
$timestart = $now - 100;
];
foreach ($repeatingevents as $event) {
- \core_calendar\event::create($event, false);
+ calendar_event::create($event, false);
}
// Make sure repeating events are not filtered out.
* 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();
$record->$name = $value;
}
- $event = new \core_calendar\event($record);
+ $event = new calendar_event($record);
return $event->create($record, false);
}
}
*/
class core_calendar_rrule_manager_testcase extends advanced_testcase {
- /** @var core_calendar\event a dummy event */
+ /** @var calendar_event a dummy event */
protected $event;
/**
$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;
$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
$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 {
$event->visible = instance_is_visible($modulename, $instance);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ \calendar_event::create($event);
}
}
($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);
}
}
// 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();
}
}
// 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");
}
}
'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'
);
/**
- * @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.');
}
/**
* 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) {
* 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.
* 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.
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();
}
}
* 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');
/**
* 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;
* 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
}
$events = $DB->get_records('event', $conds);
foreach ($events as $event) {
- $eventold = \core_calendar\event::load($event);
+ $eventold = calendar_event::load($event);
$eventold->delete();
}
// 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,
// 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,
*
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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);
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
$event->timesort = $chat->chattime;
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
return $returnid;
}
$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 {
$event->timesort = $chat->chattime;
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
$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.
$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;
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);
}
}
/**
* 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;
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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;
$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 {
$event->timesort = $choice->timeopen;
$event->visible = instance_is_visible('choice', $choice);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
$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 {
$event->timesort = $choice->timeclose;
$event->visible = instance_is_visible('choice', $choice);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
}
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
// 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();
}
/**
* 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;
$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 {
$event->timesort = $data->timeavailablefrom;
$event->visible = instance_is_visible('data', $data);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
$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 {
$event->timesort = $data->timeavailableto;
$event->visible = instance_is_visible('data', $data);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
}
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
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.
$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();
}
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.
$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();
}
}
/**
* 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;
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
* 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;
}
/**
* 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);
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
\ No newline at end of file
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)) {
$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();
}
}
/**
* 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');
$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();
}
}
}
$events = $DB->get_records('event', $conds);
foreach ($events as $event) {
- $eventold = \core_calendar\event::load($event);
+ $eventold = calendar_event::load($event);
$eventold->delete();
}
* @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();
$event->type = CALENDAR_EVENT_TYPE_ACTION;
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
$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();
}
'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();
}
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)) {
$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();
}
}
/**
* 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;
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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;
$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 {
$event->visible = instance_is_visible('scorm', $scorm);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
$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 {
$event->visible = instance_is_visible('scorm', $scorm);
$event->timeduration = 0;
- \core_calendar\event::create($event);
+ calendar_event::create($event);
}
}
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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);
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($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_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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
\ No newline at end of file
/**
* 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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}
// 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();
}
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);
}
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);
}
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);
}
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();
}
}
/**
* 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];
* @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();
$event->eventtype = $eventtype;
$event->timestart = time();
- return \core_calendar\event::create($event);
+ return calendar_event::create($event);
}
}