MDL-58423 core_calendar: moved \core_calendar\event class
authorMark Nelson <markn@moodle.com>
Wed, 29 Mar 2017 05:33:11 +0000 (13:33 +0800)
committerDan Poltawski <dan@moodle.com>
Tue, 4 Apr 2017 10:01:49 +0000 (11:01 +0100)
Part of MDL-55611 epic.

72 files changed:
calendar/classes/api.php
calendar/classes/event.php [deleted file]
calendar/classes/local/event/mappers/event_mapper.php
calendar/classes/local/interfaces/event_mapper_interface.php
calendar/classes/rrule_manager.php
calendar/delete.php
calendar/event.php
calendar/externallib.php
calendar/lib.php
calendar/renderer.php
calendar/tests/api_test.php
calendar/tests/core_container_test.php
calendar/tests/event_factory_test.php
calendar/tests/event_mapper_test.php
calendar/tests/externallib_test.php
calendar/tests/helpers.php
calendar/tests/raw_event_retrieval_strategy_test.php
calendar/tests/repeat_event_collection_test.php
calendar/tests/rrule_manager_test.php
completion/classes/api.php
course/lib.php
course/tests/courselib_test.php
lib/db/renamedclasses.php
lib/deprecatedlib.php
lib/upgrade.txt
mod/assign/lib.php
mod/assign/locallib.php
mod/assign/tests/lib_test.php
mod/book/lib.php
mod/book/tests/lib_test.php
mod/chat/lib.php
mod/chat/tests/lib_test.php
mod/choice/lib.php
mod/choice/locallib.php
mod/choice/tests/lib_test.php
mod/data/lib.php
mod/data/locallib.php
mod/data/tests/lib_test.php
mod/feedback/lib.php
mod/feedback/tests/lib_test.php
mod/folder/lib.php
mod/folder/tests/lib_test.php
mod/forum/lib.php
mod/forum/tests/lib_test.php
mod/glossary/lib.php
mod/glossary/tests/lib_test.php
mod/imscp/lib.php
mod/imscp/tests/lib_test.php
mod/label/lib.php
mod/label/tests/lib_test.php
mod/lesson/lib.php
mod/lesson/locallib.php
mod/lesson/tests/lib_test.php
mod/lti/lib.php
mod/lti/tests/lib_test.php
mod/page/lib.php
mod/page/tests/lib_test.php
mod/quiz/lib.php
mod/quiz/tests/lib_test.php
mod/resource/lib.php
mod/resource/tests/lib_test.php
mod/scorm/lib.php
mod/scorm/locallib.php
mod/scorm/tests/lib_test.php
mod/survey/lib.php
mod/survey/tests/lib_test.php
mod/url/lib.php
mod/url/tests/lib_test.php
mod/wiki/lib.php
mod/wiki/tests/lib_test.php
mod/workshop/lib.php
mod/workshop/tests/lib_test.php

index 8b05c1d..a053b9a 100644 (file)
@@ -280,7 +280,7 @@ class api {
                     if (!isset($events[$eventid])) {
                         continue;
                     }
-                    $event = new event($events[$eventid]);
+                    $event = new \calendar_event($events[$eventid]);
                     $popupalt  = '';
                     $component = 'moodle';
                     if (!empty($event->modulename)) {
@@ -1354,7 +1354,7 @@ class api {
     /**
      * Return the capability for editing calendar event
      *
-     * @param event $event event object
+     * @param \calendar_event $event event object
      * @return bool capability to edit event
      */
     public static function can_edit_event($event) {
@@ -1444,7 +1444,7 @@ class api {
     /**
      * Get event format time
      *
-     * @param event $event event object
+     * @param \calendar_event $event event object
      * @param int $now current time in gmt
      * @param array $linkparams list of params for event link
      * @param bool $usecommonwords the words as formatted date/time.
@@ -1884,7 +1884,7 @@ class api {
         } else {
             $return = CALENDAR_IMPORT_EVENT_INSERTED; // Insert.
         }
-        if ($createdevent = event::create($eventrecord, false)) {
+        if ($createdevent = \calendar_event::create($eventrecord, false)) {
             if (!empty($event->properties['RRULE'])) {
                 // Repeating events.
                 date_default_timezone_set($tz); // Change time zone to parse all events.
diff --git a/calendar/classes/event.php b/calendar/classes/event.php
deleted file mode 100644 (file)
index 62d17fa..0000000
+++ /dev/null
@@ -1,784 +0,0 @@
-<?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);
-    }
-}
index d88b23b..9464d88 100644 (file)
@@ -26,7 +26,6 @@ namespace core_calendar\local\event\mappers;
 
 defined('MOODLE_INTERNAL') || die();
 
-use core_calendar\event;
 use core_calendar\local\interfaces\event_factory_interface;
 use core_calendar\local\interfaces\event_interface;
 use core_calendar\local\interfaces\action_event_interface;
@@ -53,7 +52,7 @@ class event_mapper implements event_mapper_interface {
         $this->factory = $factory;
     }
 
-    public function from_legacy_event_to_event(event $legacyevent) {
+    public function from_legacy_event_to_event(\calendar_event $legacyevent) {
         $coalesce = function($property) use ($legacyevent) {
             return property_exists($legacyevent, $property) ? $legacyevent->{$property} : null;
         };
@@ -85,7 +84,7 @@ class event_mapper implements event_mapper_interface {
         $action = ($event instanceof action_event_interface) ? $event->get_action() : null;
         $timeduration = $event->get_times()->get_end_time()->getTimestamp() - $event->get_times()->get_start_time()->getTimestamp();
 
-        return new event($this->from_event_to_stdclass($event));
+        return new \calendar_event($this->from_event_to_stdclass($event));
     }
 
     public function from_event_to_stdclass(event_interface $event) {
index bed0630..3258450 100644 (file)
@@ -26,8 +26,6 @@ namespace core_calendar\local\interfaces;
 
 defined('MOODLE_INTERNAL') || die();
 
-use core_calendar\event;
-
 /**
  * Interface for an event mapper class
  *
@@ -38,16 +36,16 @@ interface event_mapper_interface {
     /**
      * Map a legacy event to an event.
      *
-     * @param event $event The legacy event.
+     * @param \calendar_event $event The legacy event.
      * @return event_interface The mapped event.
      */
-    public function from_legacy_event_to_event(event $event);
+    public function from_legacy_event_to_event(\calendar_event $event);
 
     /**
      * Map an event to a legacy event.
      *
      * @param event_interface $event The legacy event.
-     * @return event The mapped legacy event.
+     * @return \calendar_event The mapped legacy event.
      */
     public function from_event_to_legacy_event(event_interface $event);
 
index f4883e7..78cee59 100644 (file)
@@ -223,7 +223,7 @@ class rrule_manager {
     /**
      * Create events for specified rrule.
      *
-     * @param event $passedevent Properties of event to create.
+     * @param \calendar_event $passedevent Properties of event to create.
      * @throws moodle_exception
      */
     public function create_events($passedevent) {
@@ -245,7 +245,7 @@ class rrule_manager {
 
         // Adjust the parent event's timestart, if necessary.
         if (count($eventtimes) > 0 && !in_array($eventrec->timestart, $eventtimes)) {
-            $calevent = new event($eventrec);
+            $calevent = new \calendar_event($eventrec);
             $updatedata = (object)['timestart' => $eventtimes[0], 'repeatid' => $eventrec->id];
             $calevent->update($updatedata, false);
             $eventrec->timestart = $calevent->timestart;
@@ -719,7 +719,7 @@ class rrule_manager {
             $cloneevent->repeatid = $event->id;
             $cloneevent->timestart = $time;
             unset($cloneevent->id);
-            event::create($cloneevent, false);
+            \calendar_event::create($cloneevent, false);
         }
     }
 
index 68ca6c8..6ebb06e 100644 (file)
@@ -41,7 +41,7 @@ if(!$site = get_site()) {
     redirect(new moodle_url('/admin/index.php'));
 }
 
-$event = \core_calendar\event::load($eventid);
+$event = calendar_event::load($eventid);
 
 /**
  * We are going to be picky here, and require that any event types other than
index 1281332..dcf6558 100644 (file)
@@ -113,7 +113,7 @@ $calendar->prepare_for_view($course, $courses);
 $formoptions = new stdClass;
 if ($eventid !== 0) {
     $title = get_string('editevent', 'calendar');
-    $event = \core_calendar\event::load($eventid);
+    $event = calendar_event::load($eventid);
     if (!\core_calendar\api::can_edit_event($event)) {
         print_error('nopermissions');
     }
@@ -149,7 +149,7 @@ if ($eventid !== 0) {
         }
     }
     $event->timestart = $time;
-    $event = new \core_calendar\event($event);
+    $event = new calendar_event($event);
     if (!\core_calendar\api::can_add_event($event)) {
         print_error('nopermissions');
     }
index b27af44..6365dd2 100644 (file)
@@ -83,7 +83,7 @@ class core_calendar_external extends external_api {
         $transaction = $DB->start_delegated_transaction();
 
         foreach ($params['events'] as $event) {
-            $eventobj = \core_calendar\event::load($event['eventid']);
+            $eventobj = calendar_event::load($event['eventid']);
 
             // Let's check if the user is allowed to delete an event.
             if (!\core_calendar\api::can_edit_event($eventobj)) {
@@ -247,7 +247,7 @@ class core_calendar_external extends external_api {
         foreach ($eventlist as $eventid => $eventobj) {
             $event = (array) $eventobj;
             // Description formatting.
-            $calendareventobj = new \core_calendar\event($event);
+            $calendareventobj = new calendar_event($event);
             list($event['description'], $event['format']) = $calendareventobj->format_external_text();
 
             if ($hassystemcap) {
@@ -260,7 +260,7 @@ class core_calendar_external extends external_api {
                 }
             } else {
                 // Can the user actually see this event?
-                $eventobj = \core_calendar\event::load($eventobj);
+                $eventobj = calendar_event::load($eventobj);
                 if (($eventobj->courseid == $SITE->id) ||
                             (!empty($eventobj->groupid) && in_array($eventobj->groupid, $groups)) ||
                             (!empty($eventobj->courseid) && in_array($eventobj->courseid, $courses)) ||
@@ -620,7 +620,7 @@ class core_calendar_external extends external_api {
                 $event['repeat'] = 0;
             }
 
-            $eventobj = new \core_calendar\event($event);
+            $eventobj = new calendar_event($event);
 
             // Let's check if the user is allowed to delete an event.
             if (!\core_calendar\api::can_add_event($eventobj)) {
index 9a4b896..597282c 100644 (file)
@@ -135,6 +135,786 @@ define('CALENDAR_EVENT_TYPE_STANDARD', 0);
  */
 define('CALENDAR_EVENT_TYPE_ACTION', 1);
 
+/**
+ * Manage calendar events.
+ *
+ * This class provides the required functionality in order to manage calendar events.
+ * It was introduced as part of Moodle 2.0 and was created in order to provide a
+ * better framework for dealing with calendar events in particular regard to file
+ * handling through the new file API.
+ *
+ * @package    core_calendar
+ * @category   calendar
+ * @copyright  2009 Sam Hemelryk
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *
+ * @property int $id The id within the event table
+ * @property string $name The name of the event
+ * @property string $description The description of the event
+ * @property int $format The format of the description FORMAT_?
+ * @property int $courseid The course the event is associated with (0 if none)
+ * @property int $groupid The group the event is associated with (0 if none)
+ * @property int $userid The user the event is associated with (0 if none)
+ * @property int $repeatid If this is a repeated event this will be set to the
+ *                          id of the original
+ * @property string $modulename If added by a module this will be the module name
+ * @property int $instance If added by a module this will be the module instance
+ * @property string $eventtype The event type
+ * @property int $timestart The start time as a timestamp
+ * @property int $timeduration The duration of the event in seconds
+ * @property int $visible 1 if the event is visible
+ * @property int $uuid ?
+ * @property int $sequence ?
+ * @property int $timemodified The time last modified as a timestamp
+ */
+class calendar_event {
+
+    /** @var array An object containing the event properties can be accessed via the magic __get/set methods */
+    protected $properties = null;
+
+    /** @var string The converted event discription with file paths resolved.
+     *              This gets populated when someone requests description for the first time */
+    protected $_description = null;
+
+    /** @var array The options to use with this description editor */
+    protected $editoroptions = array(
+        'subdirs' => false,
+        'forcehttps' => false,
+        'maxfiles' => -1,
+        'maxbytes' => null,
+        'trusttext' => false);
+
+    /** @var object The context to use with the description editor */
+    protected $editorcontext = null;
+
+    /**
+     * Instantiates a new event and optionally populates its properties with the data provided.
+     *
+     * @param \stdClass $data Optional. An object containing the properties to for
+     *                  an event
+     */
+    public function __construct($data = null) {
+        global $CFG, $USER;
+
+        // First convert to object if it is not already (should either be object or assoc array).
+        if (!is_object($data)) {
+            $data = (object) $data;
+        }
+
+        $this->editoroptions['maxbytes'] = $CFG->maxbytes;
+
+        $data->eventrepeats = 0;
+
+        if (empty($data->id)) {
+            $data->id = null;
+        }
+
+        if (!empty($data->subscriptionid)) {
+            $data->subscription = \core_calendar\api::get_subscription($data->subscriptionid);
+        }
+
+        // Default to a user event.
+        if (empty($data->eventtype)) {
+            $data->eventtype = 'user';
+        }
+
+        // Default to the current user.
+        if (empty($data->userid)) {
+            $data->userid = $USER->id;
+        }
+
+        if (!empty($data->timeduration) && is_array($data->timeduration)) {
+            $data->timeduration = make_timestamp(
+                    $data->timeduration['year'], $data->timeduration['month'], $data->timeduration['day'],
+                    $data->timeduration['hour'], $data->timeduration['minute']) - $data->timestart;
+        }
+
+        if (!empty($data->description) && is_array($data->description)) {
+            $data->format = $data->description['format'];
+            $data->description = $data->description['text'];
+        } else if (empty($data->description)) {
+            $data->description = '';
+            $data->format = editors_get_preferred_format();
+        }
+
+        // Ensure form is defaulted correctly.
+        if (empty($data->format)) {
+            $data->format = editors_get_preferred_format();
+        }
+
+        $this->properties = $data;
+
+        if (empty($data->context)) {
+            $this->properties->context = $this->calculate_context();
+        }
+    }
+
+    /**
+     * Magic set method.
+     *
+     * Attempts to call a set_$key method if one exists otherwise falls back
+     * to simply set the property.
+     *
+     * @param string $key property name
+     * @param mixed $value value of the property
+     */
+    public function __set($key, $value) {
+        if (method_exists($this, 'set_'.$key)) {
+            $this->{'set_'.$key}($value);
+        }
+        $this->properties->{$key} = $value;
+    }
+
+    /**
+     * Magic get method.
+     *
+     * Attempts to call a get_$key method to return the property and ralls over
+     * to return the raw property.
+     *
+     * @param string $key property name
+     * @return mixed property value
+     * @throws \coding_exception
+     */
+    public function __get($key) {
+        if (method_exists($this, 'get_'.$key)) {
+            return $this->{'get_'.$key}();
+        }
+        if (!isset($this->properties->{$key})) {
+            throw new \coding_exception('Undefined property requested');
+        }
+        return $this->properties->{$key};
+    }
+
+    /**
+     * Magic isset method.
+     *
+     * PHP needs an isset magic method if you use the get magic method and
+     * still want empty calls to work.
+     *
+     * @param string $key $key property name
+     * @return bool|mixed property value, false if property is not exist
+     */
+    public function __isset($key) {
+        return !empty($this->properties->{$key});
+    }
+
+    /**
+     * Calculate the context value needed for an event.
+     *
+     * Event's type can be determine by the available value store in $data
+     * It is important to check for the existence of course/courseid to determine
+     * the course event.
+     * Default value is set to CONTEXT_USER
+     *
+     * @return \stdClass The context object.
+     */
+    protected function calculate_context() {
+        global $USER, $DB;
+
+        $context = null;
+        if (isset($this->properties->courseid) && $this->properties->courseid > 0) {
+            $context = \context_course::instance($this->properties->courseid);
+        } else if (isset($this->properties->course) && $this->properties->course > 0) {
+            $context = \context_course::instance($this->properties->course);
+        } else if (isset($this->properties->groupid) && $this->properties->groupid > 0) {
+            $group = $DB->get_record('groups', array('id' => $this->properties->groupid));
+            $context = \context_course::instance($group->courseid);
+        } else if (isset($this->properties->userid) && $this->properties->userid > 0
+            && $this->properties->userid == $USER->id) {
+            $context = \context_user::instance($this->properties->userid);
+        } else if (isset($this->properties->userid) && $this->properties->userid > 0
+            && $this->properties->userid != $USER->id &&
+            isset($this->properties->instance) && $this->properties->instance > 0) {
+            $cm = get_coursemodule_from_instance($this->properties->modulename, $this->properties->instance, 0,
+                false, MUST_EXIST);
+            $context = \context_course::instance($cm->course);
+        } else {
+            $context = \context_user::instance($this->properties->userid);
+        }
+
+        return $context;
+    }
+
+    /**
+     * Returns an array of editoroptions for this event.
+     *
+     * @return array event editor options
+     */
+    protected function get_editoroptions() {
+        return $this->editoroptions;
+    }
+
+    /**
+     * Returns an event description: Called by __get
+     * Please use $blah = $event->description;
+     *
+     * @return string event description
+     */
+    protected function get_description() {
+        global $CFG;
+
+        require_once($CFG->libdir . '/filelib.php');
+
+        if ($this->_description === null) {
+            // Check if we have already resolved the context for this event.
+            if ($this->editorcontext === null) {
+                // Switch on the event type to decide upon the appropriate context to use for this event.
+                $this->editorcontext = $this->properties->context;
+                if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
+                    && $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
+                    return clean_text($this->properties->description, $this->properties->format);
+                }
+            }
+
+            // Work out the item id for the editor, if this is a repeated event
+            // then the files will be associated with the original.
+            if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
+                $itemid = $this->properties->repeatid;
+            } else {
+                $itemid = $this->properties->id;
+            }
+
+            // Convert file paths in the description so that things display correctly.
+            $this->_description = file_rewrite_pluginfile_urls($this->properties->description, 'pluginfile.php',
+                $this->editorcontext->id, 'calendar', 'event_description', $itemid);
+            // Clean the text so no nasties get through.
+            $this->_description = clean_text($this->_description, $this->properties->format);
+        }
+
+        // Finally return the description.
+        return $this->_description;
+    }
+
+    /**
+     * Return the number of repeat events there are in this events series.
+     *
+     * @return int number of event repeated
+     */
+    public function count_repeats() {
+        global $DB;
+        if (!empty($this->properties->repeatid)) {
+            $this->properties->eventrepeats = $DB->count_records('event',
+                array('repeatid' => $this->properties->repeatid));
+            // We don't want to count ourselves.
+            $this->properties->eventrepeats--;
+        }
+        return $this->properties->eventrepeats;
+    }
+
+    /**
+     * Update or create an event within the database
+     *
+     * Pass in a object containing the event properties and this function will
+     * insert it into the database and deal with any associated files
+     *
+     * @see self::create()
+     * @see self::update()
+     *
+     * @param \stdClass $data object of event
+     * @param bool $checkcapability if moodle should check calendar managing capability or not
+     * @return bool event updated
+     */
+    public function update($data, $checkcapability=true) {
+        global $DB, $USER;
+
+        foreach ($data as $key => $value) {
+            $this->properties->$key = $value;
+        }
+
+        $this->properties->timemodified = time();
+        $usingeditor = (!empty($this->properties->description) && is_array($this->properties->description));
+
+        // Prepare event data.
+        $eventargs = array(
+            'context' => $this->properties->context,
+            'objectid' => $this->properties->id,
+            'other' => array(
+                'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
+                'timestart' => $this->properties->timestart,
+                'name' => $this->properties->name
+            )
+        );
+
+        if (empty($this->properties->id) || $this->properties->id < 1) {
+
+            if ($checkcapability) {
+                if (!\core_calendar\api::can_add_event($this->properties)) {
+                    print_error('nopermissiontoupdatecalendar');
+                }
+            }
+
+            if ($usingeditor) {
+                switch ($this->properties->eventtype) {
+                    case 'user':
+                        $this->properties->courseid = 0;
+                        $this->properties->course = 0;
+                        $this->properties->groupid = 0;
+                        $this->properties->userid = $USER->id;
+                        break;
+                    case 'site':
+                        $this->properties->courseid = SITEID;
+                        $this->properties->course = SITEID;
+                        $this->properties->groupid = 0;
+                        $this->properties->userid = $USER->id;
+                        break;
+                    case 'course':
+                        $this->properties->groupid = 0;
+                        $this->properties->userid = $USER->id;
+                        break;
+                    case 'group':
+                        $this->properties->userid = $USER->id;
+                        break;
+                    default:
+                        // We should NEVER get here, but just incase we do lets fail gracefully.
+                        $usingeditor = false;
+                        break;
+                }
+
+                // If we are actually using the editor, we recalculate the context because some default values
+                // were set when calculate_context() was called from the constructor.
+                if ($usingeditor) {
+                    $this->properties->context = $this->calculate_context();
+                    $this->editorcontext = $this->properties->context;
+                }
+
+                $editor = $this->properties->description;
+                $this->properties->format = $this->properties->description['format'];
+                $this->properties->description = $this->properties->description['text'];
+            }
+
+            // Insert the event into the database.
+            $this->properties->id = $DB->insert_record('event', $this->properties);
+
+            if ($usingeditor) {
+                $this->properties->description = file_save_draft_area_files(
+                    $editor['itemid'],
+                    $this->editorcontext->id,
+                    'calendar',
+                    'event_description',
+                    $this->properties->id,
+                    $this->editoroptions,
+                    $editor['text'],
+                    $this->editoroptions['forcehttps']);
+                $DB->set_field('event', 'description', $this->properties->description,
+                    array('id' => $this->properties->id));
+            }
+
+            // Log the event entry.
+            $eventargs['objectid'] = $this->properties->id;
+            $eventargs['context'] = $this->properties->context;
+            $event = \core\event\calendar_event_created::create($eventargs);
+            $event->trigger();
+
+            $repeatedids = array();
+
+            if (!empty($this->properties->repeat)) {
+                $this->properties->repeatid = $this->properties->id;
+                $DB->set_field('event', 'repeatid', $this->properties->repeatid, array('id' => $this->properties->id));
+
+                $eventcopy = clone($this->properties);
+                unset($eventcopy->id);
+
+                $timestart = new \DateTime('@' . $eventcopy->timestart);
+                $timestart->setTimezone(\core_date::get_user_timezone_object());
+
+                for ($i = 1; $i < $eventcopy->repeats; $i++) {
+
+                    $timestart->add(new \DateInterval('P7D'));
+                    $eventcopy->timestart = $timestart->getTimestamp();
+
+                    // Get the event id for the log record.
+                    $eventcopyid = $DB->insert_record('event', $eventcopy);
+
+                    // If the context has been set delete all associated files.
+                    if ($usingeditor) {
+                        $fs = get_file_storage();
+                        $files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description',
+                            $this->properties->id);
+                        foreach ($files as $file) {
+                            $fs->create_file_from_storedfile(array('itemid' => $eventcopyid), $file);
+                        }
+                    }
+
+                    $repeatedids[] = $eventcopyid;
+
+                    // Trigger an event.
+                    $eventargs['objectid'] = $eventcopyid;
+                    $eventargs['other']['timestart'] = $eventcopy->timestart;
+                    $event = \core\event\calendar_event_created::create($eventargs);
+                    $event->trigger();
+                }
+            }
+
+            return true;
+        } else {
+
+            if ($checkcapability) {
+                if (!\core_calendar\api::can_edit_event($this->properties)) {
+                    print_error('nopermissiontoupdatecalendar');
+                }
+            }
+
+            if ($usingeditor) {
+                if ($this->editorcontext !== null) {
+                    $this->properties->description = file_save_draft_area_files(
+                        $this->properties->description['itemid'],
+                        $this->editorcontext->id,
+                        'calendar',
+                        'event_description',
+                        $this->properties->id,
+                        $this->editoroptions,
+                        $this->properties->description['text'],
+                        $this->editoroptions['forcehttps']);
+                } else {
+                    $this->properties->format = $this->properties->description['format'];
+                    $this->properties->description = $this->properties->description['text'];
+                }
+            }
+
+            $event = $DB->get_record('event', array('id' => $this->properties->id));
+
+            $updaterepeated = (!empty($this->properties->repeatid) && !empty($this->properties->repeateditall));
+
+            if ($updaterepeated) {
+                // Update all.
+                if ($this->properties->timestart != $event->timestart) {
+                    $timestartoffset = $this->properties->timestart - $event->timestart;
+                    $sql = "UPDATE {event}
+                               SET name = ?,
+                                   description = ?,
+                                   timestart = timestart + ?,
+                                   timeduration = ?,
+                                   timemodified = ?
+                             WHERE repeatid = ?";
+                    $params = array($this->properties->name, $this->properties->description, $timestartoffset,
+                        $this->properties->timeduration, time(), $event->repeatid);
+                } else {
+                    $sql = "UPDATE {event} SET name = ?, description = ?, timeduration = ?, timemodified = ? WHERE repeatid = ?";
+                    $params = array($this->properties->name, $this->properties->description,
+                        $this->properties->timeduration, time(), $event->repeatid);
+                }
+                $DB->execute($sql, $params);
+
+                // Trigger an update event for each of the calendar event.
+                $events = $DB->get_records('event', array('repeatid' => $event->repeatid), '', '*');
+                foreach ($events as $calendarevent) {
+                    $eventargs['objectid'] = $calendarevent->id;
+                    $eventargs['other']['timestart'] = $calendarevent->timestart;
+                    $event = \core\event\calendar_event_updated::create($eventargs);
+                    $event->add_record_snapshot('event', $calendarevent);
+                    $event->trigger();
+                }
+            } else {
+                $DB->update_record('event', $this->properties);
+                $event = self::load($this->properties->id);
+                $this->properties = $event->properties();
+
+                // Trigger an update event.
+                $event = \core\event\calendar_event_updated::create($eventargs);
+                $event->add_record_snapshot('event', $this->properties);
+                $event->trigger();
+            }
+
+            return true;
+        }
+    }
+
+    /**
+     * Deletes an event and if selected an repeated events in the same series
+     *
+     * This function deletes an event, any associated events if $deleterepeated=true,
+     * and cleans up any files associated with the events.
+     *
+     * @see self::delete()
+     *
+     * @param bool $deleterepeated  delete event repeatedly
+     * @return bool succession of deleting event
+     */
+    public function delete($deleterepeated = false) {
+        global $DB;
+
+        // If $this->properties->id is not set then something is wrong.
+        if (empty($this->properties->id)) {
+            debugging('Attempting to delete an event before it has been loaded', DEBUG_DEVELOPER);
+            return false;
+        }
+        $calevent = $DB->get_record('event',  array('id' => $this->properties->id), '*', MUST_EXIST);
+        // Delete the event.
+        $DB->delete_records('event', array('id' => $this->properties->id));
+
+        // Trigger an event for the delete action.
+        $eventargs = array(
+            'context' => $this->properties->context,
+            'objectid' => $this->properties->id,
+            'other' => array(
+                'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
+                'timestart' => $this->properties->timestart,
+                'name' => $this->properties->name
+            ));
+        $event = \core\event\calendar_event_deleted::create($eventargs);
+        $event->add_record_snapshot('event', $calevent);
+        $event->trigger();
+
+        // If we are deleting parent of a repeated event series, promote the next event in the series as parent.
+        if (($this->properties->id == $this->properties->repeatid) && !$deleterepeated) {
+            $newparent = $DB->get_field_sql("SELECT id from {event} where repeatid = ? order by id ASC",
+                array($this->properties->id), IGNORE_MULTIPLE);
+            if (!empty($newparent)) {
+                $DB->execute("UPDATE {event} SET repeatid = ? WHERE repeatid = ?",
+                    array($newparent, $this->properties->id));
+                // Get all records where the repeatid is the same as the event being removed.
+                $events = $DB->get_records('event', array('repeatid' => $newparent));
+                // For each of the returned events trigger an update event.
+                foreach ($events as $calendarevent) {
+                    // Trigger an event for the update.
+                    $eventargs['objectid'] = $calendarevent->id;
+                    $eventargs['other']['timestart'] = $calendarevent->timestart;
+                    $event = \core\event\calendar_event_updated::create($eventargs);
+                    $event->add_record_snapshot('event', $calendarevent);
+                    $event->trigger();
+                }
+            }
+        }
+
+        // If the editor context hasn't already been set then set it now.
+        if ($this->editorcontext === null) {
+            $this->editorcontext = $this->properties->context;
+        }
+
+        // If the context has been set delete all associated files.
+        if ($this->editorcontext !== null) {
+            $fs = get_file_storage();
+            $files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
+            foreach ($files as $file) {
+                $file->delete();
+            }
+        }
+
+        // If we need to delete repeated events then we will fetch them all and delete one by one.
+        if ($deleterepeated && !empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
+            // Get all records where the repeatid is the same as the event being removed.
+            $events = $DB->get_records('event', array('repeatid' => $this->properties->repeatid));
+            // For each of the returned events populate an event object and call delete.
+            // make sure the arg passed is false as we are already deleting all repeats.
+            foreach ($events as $event) {
+                $event = new calendar_event($event);
+                $event->delete(false);
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Fetch all event properties.
+     *
+     * This function returns all of the events properties as an object and optionally
+     * can prepare an editor for the description field at the same time. This is
+     * designed to work when the properties are going to be used to set the default
+     * values of a moodle forms form.
+     *
+     * @param bool $prepareeditor If set to true a editor is prepared for use with
+     *              the mforms editor element. (for description)
+     * @return \stdClass Object containing event properties
+     */
+    public function properties($prepareeditor = false) {
+        global $DB;
+
+        // First take a copy of the properties. We don't want to actually change the
+        // properties or we'd forever be converting back and forwards between an
+        // editor formatted description and not.
+        $properties = clone($this->properties);
+        // Clean the description here.
+        $properties->description = clean_text($properties->description, $properties->format);
+
+        // If set to true we need to prepare the properties for use with an editor
+        // and prepare the file area.
+        if ($prepareeditor) {
+
+            // We may or may not have a property id. If we do then we need to work
+            // out the context so we can copy the existing files to the draft area.
+            if (!empty($properties->id)) {
+
+                if ($properties->eventtype === 'site') {
+                    // Site context.
+                    $this->editorcontext = $this->properties->context;
+                } else if ($properties->eventtype === 'user') {
+                    // User context.
+                    $this->editorcontext = $this->properties->context;
+                } else if ($properties->eventtype === 'group' || $properties->eventtype === 'course') {
+                    // First check the course is valid.
+                    $course = $DB->get_record('course', array('id' => $properties->courseid));
+                    if (!$course) {
+                        print_error('invalidcourse');
+                    }
+                    // Course context.
+                    $this->editorcontext = $this->properties->context;
+                    // We have a course and are within the course context so we had
+                    // better use the courses max bytes value.
+                    $this->editoroptions['maxbytes'] = $course->maxbytes;
+                } else {
+                    // If we get here we have a custom event type as used by some
+                    // modules. In this case the event will have been added by
+                    // code and we won't need the editor.
+                    $this->editoroptions['maxbytes'] = 0;
+                    $this->editoroptions['maxfiles'] = 0;
+                }
+
+                if (empty($this->editorcontext) || empty($this->editorcontext->id)) {
+                    $contextid = false;
+                } else {
+                    // Get the context id that is what we really want.
+                    $contextid = $this->editorcontext->id;
+                }
+            } else {
+
+                // If we get here then this is a new event in which case we don't need a
+                // context as there is no existing files to copy to the draft area.
+                $contextid = null;
+            }
+
+            // If the contextid === false we don't support files so no preparing
+            // a draft area.
+            if ($contextid !== false) {
+                // Just encase it has already been submitted.
+                $draftiddescription = file_get_submitted_draft_itemid('description');
+                // Prepare the draft area, this copies existing files to the draft area as well.
+                $properties->description = file_prepare_draft_area($draftiddescription, $contextid, 'calendar',
+                    'event_description', $properties->id, $this->editoroptions, $properties->description);
+            } else {
+                $draftiddescription = 0;
+            }
+
+            // Structure the description field as the editor requires.
+            $properties->description = array('text' => $properties->description, 'format' => $properties->format,
+                'itemid' => $draftiddescription);
+        }
+
+        // Finally return the properties.
+        return $properties;
+    }
+
+    /**
+     * Toggles the visibility of an event
+     *
+     * @param null|bool $force If it is left null the events visibility is flipped,
+     *                   If it is false the event is made hidden, if it is true it
+     *                   is made visible.
+     * @return bool if event is successfully updated, toggle will be visible
+     */
+    public function toggle_visibility($force = null) {
+        global $DB;
+
+        // Set visible to the default if it is not already set.
+        if (empty($this->properties->visible)) {
+            $this->properties->visible = 1;
+        }
+
+        if ($force === true || ($force !== false && $this->properties->visible == 0)) {
+            // Make this event visible.
+            $this->properties->visible = 1;
+        } else {
+            // Make this event hidden.
+            $this->properties->visible = 0;
+        }
+
+        // Update the database to reflect this change.
+        $success = $DB->set_field('event', 'visible', $this->properties->visible, array('id' => $this->properties->id));
+        $calendarevent = $DB->get_record('event',  array('id' => $this->properties->id), '*', MUST_EXIST);
+
+        // Prepare event data.
+        $eventargs = array(
+            'context' => $this->properties->context,
+            'objectid' => $this->properties->id,
+            'other' => array(
+                'repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid,
+                'timestart' => $this->properties->timestart,
+                'name' => $this->properties->name
+            )
+        );
+        $event = \core\event\calendar_event_updated::create($eventargs);
+        $event->add_record_snapshot('event', $calendarevent);
+        $event->trigger();
+
+        return $success;
+    }
+
+    /**
+     * Returns an event object when provided with an event id.
+     *
+     * This function makes use of MUST_EXIST, if the event id passed in is invalid
+     * it will result in an exception being thrown.
+     *
+     * @param int|object $param event object or event id
+     * @return calendar_event
+     */
+    public static function load($param) {
+        global $DB;
+        if (is_object($param)) {
+            $event = new calendar_event($param);
+        } else {
+            $event = $DB->get_record('event', array('id' => (int)$param), '*', MUST_EXIST);
+            $event = new calendar_event($event);
+        }
+        return $event;
+    }
+
+    /**
+     * Creates a new event and returns an event object
+     *
+     * @param \stdClass|array $properties An object containing event properties
+     * @param bool $checkcapability Check caps or not
+     * @throws \coding_exception
+     *
+     * @return calendar_event|bool The event object or false if it failed
+     */
+    public static function create($properties, $checkcapability = true) {
+        if (is_array($properties)) {
+            $properties = (object)$properties;
+        }
+        if (!is_object($properties)) {
+            throw new \coding_exception('When creating an event properties should be either an object or an assoc array');
+        }
+        $event = new calendar_event($properties);
+        if ($event->update($properties, $checkcapability)) {
+            return $event;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Format the text using the external API.
+     *
+     * This function should we used when text formatting is required in external functions.
+     *
+     * @return array an array containing the text formatted and the text format
+     */
+    public function format_external_text() {
+
+        if ($this->editorcontext === null) {
+            // Switch on the event type to decide upon the appropriate context to use for this event.
+            $this->editorcontext = $this->properties->context;
+
+            if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course'
+                && $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
+                // We don't have a context here, do a normal format_text.
+                return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id);
+            }
+        }
+
+        // Work out the item id for the editor, if this is a repeated event then the files will be associated with the original.
+        if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
+            $itemid = $this->properties->repeatid;
+        } else {
+            $itemid = $this->properties->id;
+        }
+
+        return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id,
+            'calendar', 'event_description', $itemid);
+    }
+}
+
 /**
  * Calendar information class
  *
index 42721b9..3b22819 100644 (file)
@@ -189,7 +189,7 @@ class core_calendar_renderer extends plugin_renderer_base {
             $underway = array();
             // First, print details about events that start today
             foreach ($events as $event) {
-                $event = new \core_calendar\event($event);
+                $event = new calendar_event($event);
                 $event->calendarcourseid = $calendar->courseid;
                 if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) {  // Print it now
                     $event->time = \core_calendar\api::get_format_event_time($event, time(), null, false,
@@ -220,11 +220,11 @@ class core_calendar_renderer extends plugin_renderer_base {
     /**
      * Displays an event
      *
-     * @param \core_calendar\event $event
+     * @param calendar_event $event
      * @param bool $showactions
      * @return string
      */
-    public function event(\core_calendar\event $event, $showactions=true) {
+    public function event(calendar_event $event, $showactions=true) {
         global $CFG;
 
         $event = \core_calendar\api::add_event_metadata($event);
@@ -375,7 +375,7 @@ class core_calendar_renderer extends plugin_renderer_base {
             $calendar->courses);
         if (!empty($events)) {
             foreach($events as $eventid => $event) {
-                $event = new \core_calendar\event($event);
+                $event = new calendar_event($event);
                 if (!empty($event->modulename)) {
                     $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
                     if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
@@ -552,8 +552,8 @@ class core_calendar_renderer extends plugin_renderer_base {
         if ($events) {
             $output .= html_writer::start_tag('div', array('class' => 'eventlist'));
             foreach ($events as $event) {
-                // Convert to \core_calendar\event object so that we transform description accordingly.
-                $event = new \core_calendar\event($event);
+                // Convert to calendar_event object so that we transform description accordingly.
+                $event = new calendar_event($event);
                 $event->calendarcourseid = $calendar->courseid;
                 $output .= $this->event($event);
             }
index 1383f12..7b2eaff 100644 (file)
@@ -121,7 +121,7 @@ class core_calendar_api_testcase extends advanced_testcase {
             ]
         ];
         foreach ($events as $event) {
-            \core_calendar\event::create($event, false);
+            calendar_event::create($event, false);
         }
         $timestart = time() - 60;
         $timeend = time() + 60;
@@ -232,7 +232,7 @@ class core_calendar_api_testcase extends advanced_testcase {
             ],
         ];
         foreach ($events as $event) {
-            \core_calendar\event::create($event, false);
+            calendar_event::create($event, false);
         }
         $timestart = $now - 100;
         $timeend = $now + (3 * 86400);
@@ -298,7 +298,7 @@ class core_calendar_api_testcase extends advanced_testcase {
             ],
         ];
         foreach ($repeatingevents as $event) {
-            \core_calendar\event::create($event, false);
+            calendar_event::create($event, false);
         }
         // Make sure repeating events are not filtered out.
         $events = \core_calendar\api::get_events($timestart, $timeend, true, true, true);
index d4df1a1..1daca8a 100644 (file)
@@ -296,7 +296,7 @@ class core_calendar_container_testcase extends advanced_testcase {
      * Helper function to create calendar events using the old code.
      *
      * @param array $properties A list of calendar event properties to set
-     * @return \core_calendar\event|bool
+     * @return calendar_event|bool
      */
     protected function create_event($properties = []) {
         $record = new \stdClass();
@@ -312,7 +312,7 @@ class core_calendar_container_testcase extends advanced_testcase {
             $record->$name = $value;
         }
 
-        $event = new \core_calendar\event($record);
+        $event = new calendar_event($record);
         return $event->create($record, false);
     }
 }
index 306479d..fe369f7 100644 (file)
@@ -446,7 +446,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
      * Helper function to create calendar events using the old code.
      *
      * @param array $properties A list of calendar event properties to set
-     * @return \core_calendar\event
+     * @return calendar_event
      */
     protected function create_event($properties = []) {
         $record = new \stdClass();
@@ -462,7 +462,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
             $record->$name = $value;
         }
 
-        $event = new \core_calendar\event($record);
+        $event = new calendar_event($record);
         return $event->create($record, false);
     }
 }
index c8a1d27..472924b 100644 (file)
@@ -24,7 +24,9 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-use core_calendar\event;
+global $CFG;
+require_once($CFG->dirroot . '/calendar/lib.php');
+
 use core_calendar\local\event\mappers\event_mapper;
 use core_calendar\local\event\value_objects\action;
 use core_calendar\local\event\value_objects\event_description;
@@ -68,7 +70,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
             new event_mapper_test_event_factory()
         );
         $legacyevent = $mapper->from_event_to_legacy_event($event);
-        $this->assertInstanceOf(event::class, $legacyevent);
+        $this->assertInstanceOf(calendar_event::class, $legacyevent);
     }
 
     /**
@@ -121,7 +123,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
             new event_mapper_test_event_factory()
         );
         $legacyevent = $mapper->from_event_to_legacy_event($event);
-        $this->assertInstanceOf(event::class, $legacyevent);
+        $this->assertInstanceOf(calendar_event::class, $legacyevent);
         $this->assertEquals($legacyevent->actionname, 'test action');
         $this->assertInstanceOf(\moodle_url::class, $legacyevent->actionurl);
         $this->assertEquals($legacyevent->actionnum, 1729);
@@ -132,7 +134,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
      * Helper function to create calendar events using the old code.
      *
      * @param array $properties A list of calendar event properties to set
-     * @return event
+     * @return calendar_event
      */
     protected function create_event($properties = []) {
         $record = new \stdClass();
@@ -148,7 +150,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
             $record->$name = $value;
         }
 
-        $event = new \core_calendar\event($record);
+        $event = new calendar_event($record);
         return $event->create($record, false);
     }
 }
@@ -279,7 +281,7 @@ class event_mapper_test_event implements event_interface {
     /**
      * Constructor.
      *
-     * @param \core_calendar\event $legacyevent Legacy event to exctract IDs etc from.
+     * @param calendar_event $legacyevent Legacy event to exctract IDs etc from.
      */
     public function __construct($legacyevent = null) {
         if ($legacyevent) {
index 9690091..62f9336 100644 (file)
@@ -126,7 +126,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
             $prop->priority = $priority;
         }
 
-        $event = new \core_calendar\event($prop);
+        $event = new calendar_event($prop);
         return $event->create($prop);
     }
 
index 371d5fa..b3e3404 100644 (file)
@@ -41,7 +41,7 @@ use core_calendar\local\interfaces\event_factory_interface;
  * Create a calendar event with the given properties.
  *
  * @param array $properties The properties to set on the event
- * @return \core_calendar\event
+ * @return \calendar_event
  */
 function create_event($properties) {
     $record = new \stdClass();
@@ -59,7 +59,7 @@ function create_event($properties) {
         $record->$name = $value;
     }
 
-    $event = new \core_calendar\event($record);
+    $event = new \calendar_event($record);
     return $event->create($record);
 }
 
index 7ebf9cf..cbf8d70 100644 (file)
@@ -80,7 +80,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
         ];
 
         foreach ($events as $event) {
-            \core_calendar\event::create($event, false);
+            calendar_event::create($event, false);
         }
 
         // Get all events.
@@ -200,7 +200,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
         ];
 
         foreach ($events as $event) {
-            \core_calendar\event::create($event, false);
+            calendar_event::create($event, false);
         }
 
         $timestart = $now - 100;
@@ -270,7 +270,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
         ];
 
         foreach ($repeatingevents as $event) {
-            \core_calendar\event::create($event, false);
+            calendar_event::create($event, false);
         }
 
         // Make sure repeating events are not filtered out.
index 33334b4..b8f46a4 100644 (file)
@@ -118,7 +118,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
      * Helper function to create calendar events using the old code.
      *
      * @param array $properties A list of calendar event properties to set
-     * @return \core_calendar\event
+     * @return calendar_event
      */
     protected function create_event($properties = []) {
         $record = new \stdClass();
@@ -136,7 +136,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
             $record->$name = $value;
         }
 
-        $event = new \core_calendar\event($record);
+        $event = new calendar_event($record);
         return $event->create($record, false);
     }
 }
index 11b1662..2b0f315 100644 (file)
@@ -40,7 +40,7 @@ use core_calendar\rrule_manager;
  */
 class core_calendar_rrule_manager_testcase extends advanced_testcase {
 
-    /** @var core_calendar\event a dummy event */
+    /** @var calendar_event a dummy event */
     protected $event;
 
     /**
@@ -78,7 +78,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
         $event->groupid = 0;
         $event->courseid = 0;
         $event->eventtype = 'user';
-        $eventobj = core_calendar\event::create($event, false);
+        $eventobj = calendar_event::create($event, false);
         $DB->set_field('event', 'repeatid', $eventobj->id, array('id' => $eventobj->id));
         $eventobj->repeatid = $eventobj->id;
         $this->event = $eventobj;
@@ -2703,7 +2703,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
         $newdatetime = DateTime::createFromFormat('Ymd\THis', $datestr, $timezone);
 
         // Update the start date of the parent event.
-        $calevent = core_calendar\event::load($this->event->id);
+        $calevent = calendar_event::load($this->event->id);
         $updatedata = (object)[
             'timestart' => $newdatetime->getTimestamp(),
             'repeatid' => $this->event->id
index 022ac52..418d849 100644 (file)
@@ -85,11 +85,11 @@ class api {
                 $event->visible = instance_is_visible($modulename, $instance);
                 $event->timeduration = 0;
 
-                $calendarevent = \core_calendar\event::load($event->id);
+                $calendarevent = \calendar_event::load($event->id);
                 $calendarevent->update($event);
             } else {
                 // Calendar event is no longer needed.
-                $calendarevent = \core_calendar\event::load($event->id);
+                $calendarevent = \calendar_event::load($event->id);
                 $calendarevent->delete();
             }
         } else {
@@ -107,7 +107,7 @@ class api {
                 $event->visible = instance_is_visible($modulename, $instance);
                 $event->timeduration = 0;
 
-                \core_calendar\event::create($event);
+                \calendar_event::create($event);
             }
         }
 
index 0224c84..980173f 100644 (file)
@@ -992,10 +992,10 @@ function set_coursemodule_visible($id, $visible, $visibleoncoursepage = 1) {
             ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename)))) {
         foreach($events as $event) {
             if ($visible) {
-                $event = new \core_calendar\event($event);
+                $event = new calendar_event($event);
                 $event->toggle_visibility(true);
             } else {
-                $event = new \core_calendar\event($event);
+                $event = new calendar_event($event);
                 $event->toggle_visibility(false);
             }
         }
@@ -1169,7 +1169,7 @@ function course_delete_module($cmid, $async = false) {
     // Delete events from calendar.
     if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
         foreach($events as $event) {
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     }
index d80cca2..52edef8 100644 (file)
@@ -1213,7 +1213,7 @@ class core_course_courselib_testcase extends advanced_testcase {
         // Check the events visibility.
         if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $cm->modname))) {
             foreach ($events as $event) {
-                $calevent = new \core_calendar\event($event);
+                $calevent = new calendar_event($event);
                 $this->assertEquals($visibility, $calevent->visible, "$cm->modname calendar_event visibility");
             }
         }
index f60c4a1..30d4b42 100644 (file)
@@ -45,7 +45,5 @@ $renamedclasses = array(
     'core_competency\\external\\persistent_exporter' => 'core\\external\\persistent_exporter',
     'core_competency\\external\\comment_area_exporter' => 'core_comment\\external\\comment_area_exporter',
     'core_competency\\external\\stored_file_exporter' => 'core_files\\external\\stored_file_exporter',
-    'core_competency\\external\\user_summary_exporter' => 'core_user\\external\\user_summary_exporter',
-    'core_search\area\base_activity' => 'core_search\base_activity',
-    'calendar_event' => 'core_calendar\event'
+    'core_competency\\external\\user_summary_exporter' => 'core_user\\external\\user_summary_exporter'
 );
index d6fd428..0a2eaf7 100644 (file)
@@ -1163,41 +1163,41 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
 
 
 /**
- * @deprecated please use \core_calendar\event::create() instead.
+ * @deprecated please use calendar_event::create() instead.
  */
 function add_event($event) {
-    throw new coding_exception('add_event() can not be used any more, please use \core_calendar\event::create() instead.');
+    throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
 }
 
 /**
- * @deprecated please \core_calendar\event->update() instead.
+ * @deprecated please calendar_event->update() instead.
  */
 function update_event($event) {
-    throw new coding_exception('update_event() is removed, please use \core_calendar\event->update() instead.');
+    throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
 }
 
 /**
- * @deprecated please use \core_calendar\event->delete() instead.
+ * @deprecated please use calendar_event->delete() instead.
  */
 function delete_event($id) {
     throw new coding_exception('delete_event() can not be used any more, please use '.
-        '\core_calendar\event->delete() instead.');
+        'calendar_event->delete() instead.');
 }
 
 /**
- * @deprecated please use \core_calendar\event->toggle_visibility(false) instead.
+ * @deprecated please use calendar_event->toggle_visibility(false) instead.
  */
 function hide_event($event) {
     throw new coding_exception('hide_event() can not be used any more, please use '.
-        '\core_calendar\event->toggle_visibility(false) instead.');
+        'calendar_event->toggle_visibility(false) instead.');
 }
 
 /**
- * @deprecated please use \core_calendar\event->toggle_visibility(true) instead.
+ * @deprecated please use calendar_event->toggle_visibility(true) instead.
  */
 function show_event($event) {
     throw new coding_exception('show_event() can not be used any more, please use '.
-        '\core_calendar\event->toggle_visibility(true) instead.');
+        'calendar_event->toggle_visibility(true) instead.');
 }
 
 /**
@@ -7177,7 +7177,7 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
  * Return the capability for editing calendar event.
  *
  * @deprecated since 3.3
- * @param \core_calendar\event $event event object
+ * @param calendar_event $event event object
  * @return bool capability to edit event
  */
 function calendar_edit_event_allowed($event) {
@@ -7204,7 +7204,7 @@ function calendar_get_default_courses() {
  * Get event format time.
  *
  * @deprecated since 3.3
- * @param \core_calendar\event $event event object
+ * @param calendar_event $event event object
  * @param int $now current time in gmt
  * @param array $linkparams list of params for event link
  * @param bool $usecommonwords the words as formatted date/time.
index 2ec85f0..78bd18f 100644 (file)
@@ -69,7 +69,6 @@ information provided here is intended especially for developers.
 * New 'priority' column for the event table to determine which event to show in case of events with user and group overrides.
 * Webservices core_course_search_courses and core_course_get_courses_by_field will always return the sortorder field.
 * core_course_external::get_activities_overview has been deprecated. Please do not call this function any more.
-* Class 'calendar_event' has been renamed and is now deprecated. Please use 'core_calendar\event' instead.
 * YUI module moodle-core-formautosubmit has been removed, use jquery .change() instead (see lib/templates/url_select.mustache for
   an example)
 * Changed the pix mustache template helper to accept context variables for the key, component and alt text.
index 70b211a..f9fb3e2 100644 (file)
@@ -300,13 +300,13 @@ function assign_update_events($assign, $override = null) {
                 unset($event->id);
             }
             $event->name      = $eventname.' ('.get_string('duedate', 'assign').')';
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 
     // Delete any leftover events.
     foreach ($oldevents as $badevent) {
-        $badevent = \core_calendar\event::load($badevent);
+        $badevent = calendar_event::load($badevent);
         $badevent->delete();
     }
 }
@@ -1714,10 +1714,10 @@ function assign_check_updates_since(cm_info $cm, $from, $filter = array()) {
  * the ASSIGN_EVENT_TYPE_GRADINGDUE event will not be shown to students on their calendar, and
  * ASSIGN_EVENT_TYPE_DUE events will not be shown to teachers.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @return bool Returns true if the event is visible to the current user, false otherwise.
  */
-function mod_assign_core_calendar_is_event_visible(\core_calendar\event $event) {
+function mod_assign_core_calendar_is_event_visible(calendar_event $event) {
     global $CFG, $USER;
 
     require_once($CFG->dirroot . '/mod/assign/locallib.php');
@@ -1737,11 +1737,11 @@ function mod_assign_core_calendar_is_event_visible(\core_calendar\event $event)
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_assign_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_assign_core_calendar_provide_event_action(calendar_event $event,
                                                        \core_calendar\action_factory $factory) {
 
     global $CFG, $USER;
@@ -1794,11 +1794,11 @@ function mod_assign_core_calendar_provide_event_action(\core_calendar\event $eve
  * Callback function that determines whether an action event should be showing its item count
  * based on the event type and the item count.
  *
- * @param \core_calendar\event $event The calendar event.
+ * @param calendar_event $event The calendar event.
  * @param int $itemcount The item count associated with the action event.
  * @return bool
  */
-function mod_assign_core_calendar_event_action_shows_item_count(\core_calendar\event $event, $itemcount = 0) {
+function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) {
     // List of event types where the action event's item count should be shown.
     $eventtypesshowingitemcount = [
         ASSIGN_EVENT_TYPE_GRADINGDUE
index 4ca21b3..a9808d4 100644 (file)
@@ -799,7 +799,7 @@ class assign {
         }
         $events = $DB->get_records('event', $conds);
         foreach ($events as $event) {
-            $eventold = \core_calendar\event::load($event);
+            $eventold = calendar_event::load($event);
             $eventold->delete();
         }
 
@@ -1212,10 +1212,10 @@ class assign {
 
             // Now process the event.
             if ($event->id) {
-                $calendarevent = \core_calendar\event::load($event->id);
+                $calendarevent = calendar_event::load($event->id);
                 $calendarevent->update($event);
             } else {
-                \core_calendar\event::create($event);
+                calendar_event::create($event);
             }
         } else {
             $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
@@ -1232,10 +1232,10 @@ class assign {
 
             // Now process the event.
             if ($event->id) {
-                $calendarevent = \core_calendar\event::load($event->id);
+                $calendarevent = calendar_event::load($event->id);
                 $calendarevent->update($event);
             } else {
-                \core_calendar\event::create($event);
+                calendar_event::create($event);
             }
         } else {
             $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
index 2a568af..62e3bdd 100644 (file)
@@ -593,7 +593,7 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase {
      *
      * @param int $instanceid The assign id.
      * @param string $eventtype The event type. eg. ASSIGN_EVENT_TYPE_DUE.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($instanceid, $eventtype) {
         $event = new stdClass();
@@ -605,6 +605,6 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index b0e0e36..04b11c0 100644 (file)
@@ -701,11 +701,11 @@ function mod_book_get_fontawesome_icon_map() {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_book_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_book_core_calendar_provide_event_action(calendar_event $event,
                                                      \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['book'][$event->instance];
     $context = context_module::instance($cm->id);
index 8838385..39015a3 100644 (file)
@@ -222,7 +222,7 @@ class mod_book_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -234,6 +234,6 @@ class mod_book_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 8d95641..bc4d863 100644 (file)
@@ -131,7 +131,7 @@ function chat_add_instance($chat) {
         $event->timesort    = $chat->chattime;
         $event->timeduration = 0;
 
-        \core_calendar\event::create($event);
+        calendar_event::create($event);
     }
     return $returnid;
 }
@@ -164,11 +164,11 @@ function chat_update_instance($chat) {
             $event->timestart   = $chat->chattime;
             $event->timesort    = $chat->chattime;
 
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Do not publish this event, so delete it.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -188,7 +188,7 @@ function chat_update_instance($chat) {
             $event->timesort    = $chat->chattime;
             $event->timeduration = 0;
 
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 
@@ -456,7 +456,7 @@ function chat_refresh_events($courseid = 0) {
         $event->timestart   = $chat->chattime;
 
         if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id))) {
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else if ($chat->schedule > 0) {
             // The chat is scheduled and the event should be published.
@@ -469,7 +469,7 @@ function chat_refresh_events($courseid = 0) {
             $event->timeduration = 0;
             $event->visible = $DB->get_field('course_modules', 'visible', array('module' => $moduleid, 'instance' => $chat->id));
 
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
     return true;
@@ -675,7 +675,7 @@ function chat_update_chat_times($chatid=0) {
 
         if ($event->id = $DB->get_field_select('event', 'id', $cond, $params)) {
             $event->timestart   = $chat->chattime;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event, false);
         }
     }
@@ -1410,11 +1410,11 @@ function chat_view($chat, $course, $cm, $context) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_chat_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_chat_core_calendar_provide_event_action(calendar_event $event,
                                                      \core_calendar\action_factory $factory) {
     global $DB;
 
index c053303..4edef1a 100644 (file)
@@ -149,7 +149,7 @@ class mod_chat_lib_testcase extends advanced_testcase {
      * @param int $courseid
      * @param int $instanceid The chat id.
      * @param string $eventtype The event type. eg. ASSIGN_EVENT_TYPE_DUE.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -161,6 +161,6 @@ class mod_chat_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index b1bed45..abb2504 100644 (file)
@@ -1185,11 +1185,11 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_choice_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_choice_core_calendar_provide_event_action(calendar_event $event,
                                                        \core_calendar\action_factory $factory) {
     global $DB;
 
index d87fb13..ab33373 100644 (file)
@@ -57,11 +57,11 @@ function choice_set_events($choice) {
             $event->timesort     = $choice->timeopen;
             $event->visible      = instance_is_visible('choice', $choice);
             $event->timeduration = 0;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Calendar event is on longer needed.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -78,7 +78,7 @@ function choice_set_events($choice) {
             $event->timesort     = $choice->timeopen;
             $event->visible      = instance_is_visible('choice', $choice);
             $event->timeduration = 0;
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 
@@ -96,11 +96,11 @@ function choice_set_events($choice) {
             $event->timesort     = $choice->timeclose;
             $event->visible      = instance_is_visible('choice', $choice);
             $event->timeduration = 0;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Calendar event is on longer needed.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -117,7 +117,7 @@ function choice_set_events($choice) {
             $event->timesort     = $choice->timeclose;
             $event->visible      = instance_is_visible('choice', $choice);
             $event->timeduration = 0;
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 }
index a3105cc..97323c1 100644 (file)
@@ -385,7 +385,7 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
      * @param int $courseid
      * @param int $instanceid The choice id.
      * @param string $eventtype The event type. eg. CHOICE_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -397,6 +397,6 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 098092f..952d749 100644 (file)
@@ -1057,7 +1057,7 @@ function data_delete_instance($id) {    // takes the dataid
     // Remove old calendar events.
     $events = $DB->get_records('event', array('modulename' => 'data', 'instance' => $id));
     foreach ($events as $event) {
-        $event = \core_calendar\event::load($event);
+        $event = calendar_event::load($event);
         $event->delete();
     }
 
@@ -4219,11 +4219,11 @@ function data_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_data_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_data_core_calendar_provide_event_action(calendar_event $event,
                                                        \core_calendar\action_factory $factory) {
     global $DB;
 
index 9903162..89624ef 100644 (file)
@@ -612,11 +612,11 @@ function data_set_events($data) {
             $event->timesort     = $data->timeavailablefrom;
             $event->visible      = instance_is_visible('data', $data);
             $event->timeduration = 0;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Calendar event is on longer needed.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -633,7 +633,7 @@ function data_set_events($data) {
             $event->timesort     = $data->timeavailablefrom;
             $event->visible      = instance_is_visible('data', $data);
             $event->timeduration = 0;
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 
@@ -651,11 +651,11 @@ function data_set_events($data) {
             $event->timesort     = $data->timeavailableto;
             $event->visible      = instance_is_visible('data', $data);
             $event->timeduration = 0;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Calendar event is on longer needed.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -672,7 +672,7 @@ function data_set_events($data) {
             $event->timesort     = $data->timeavailableto;
             $event->visible      = instance_is_visible('data', $data);
             $event->timeduration = 0;
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 }
index 1834826..f8aa5ca 100644 (file)
@@ -1116,7 +1116,7 @@ class mod_data_lib_testcase extends advanced_testcase {
      * @param int $courseid
      * @param int $instanceid The data id.
      * @param string $eventtype The event type. eg. DATA_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -1128,6 +1128,6 @@ class mod_data_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 9eb476b..ef64fdb 100644 (file)
@@ -818,7 +818,7 @@ function feedback_set_events($feedback) {
         if ($eventid) {
             // Calendar event exists so update it.
             $event->id = $eventid;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Event doesn't exist so create one.
@@ -828,11 +828,11 @@ function feedback_set_events($feedback) {
             $event->modulename   = 'feedback';
             $event->instance     = $feedback->id;
             $event->eventtype    = FEEDBACK_EVENT_TYPE_OPEN;
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     } else if ($eventid) {
         // Calendar event is on longer needed.
-        $calendarevent = \core_calendar\event::load($eventid);
+        $calendarevent = calendar_event::load($eventid);
         $calendarevent->delete();
     }
 
@@ -853,7 +853,7 @@ function feedback_set_events($feedback) {
         if ($eventid) {
             // Calendar event exists so update it.
             $event->id = $eventid;
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Event doesn't exist so create one.
@@ -862,11 +862,11 @@ function feedback_set_events($feedback) {
             $event->userid       = 0;
             $event->modulename   = 'feedback';
             $event->instance     = $feedback->id;
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     } else if ($eventid) {
         // Calendar event is on longer needed.
-        $calendarevent = \core_calendar\event::load($eventid);
+        $calendarevent = calendar_event::load($eventid);
         $calendarevent->delete();
     }
 }
@@ -3372,11 +3372,11 @@ function feedback_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_feedback_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_feedback_core_calendar_provide_event_action(calendar_event $event,
                                                          \core_calendar\action_factory $factory) {
     global $DB;
 
index 3388c64..5f92789 100644 (file)
@@ -235,7 +235,7 @@ class mod_feedback_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The feedback id.
      * @param string $eventtype The event type. eg. FEEDBACK_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -247,6 +247,6 @@ class mod_feedback_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index ca89912..161cd02 100644 (file)
@@ -774,11 +774,11 @@ function folder_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_folder_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_folder_core_calendar_provide_event_action(calendar_event $event,
                                                      \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['folder'][$event->instance];
 
index 45c920c..c4b3315 100644 (file)
@@ -155,7 +155,7 @@ class mod_folder_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -167,6 +167,6 @@ class mod_folder_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 91243a8..0785ceb 100644 (file)
@@ -8129,11 +8129,11 @@ function mod_forum_get_fontawesome_icon_map() {
  * Callback function that determines whether an action event should be showing its item count
  * based on the event type and the item count.
  *
- * @param \core_calendar\event $event The calendar event.
+ * @param calendar_event $event The calendar event.
  * @param int $itemcount The item count associated with the action event.
  * @return bool
  */
-function mod_forum_core_calendar_event_action_shows_item_count(\core_calendar\event $event, $itemcount = 0) {
+function mod_forum_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) {
     // Always show item count for forums if item count is greater than 0.
     return $itemcount > 0;
 }
@@ -8141,11 +8141,11 @@ function mod_forum_core_calendar_event_action_shows_item_count(\core_calendar\ev
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_forum_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_forum_core_calendar_provide_event_action(calendar_event $event,
                                                        \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['forum'][$event->instance];
     $context = context_module::instance($cm->id);
index d83a32c..0af8f26 100644 (file)
@@ -3416,7 +3416,7 @@ class mod_forum_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -3428,6 +3428,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 91af300..f145bec 100644 (file)
@@ -4173,11 +4173,11 @@ function forum_get_fontawesome_icon_map() {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_glossary_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_glossary_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['glossary'][$event->instance];
 
index 3e95f8a..df2be0c 100644 (file)
@@ -180,7 +180,7 @@ class mod_glossary_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -192,6 +192,6 @@ class mod_glossary_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index c23ecb4..cc0dbdc 100644 (file)
@@ -471,11 +471,11 @@ function imscp_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_imscp_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_imscp_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['imscp'][$event->instance];
 
index a40fd43..cd2e13e 100644 (file)
@@ -173,7 +173,7 @@ class mod_imscp_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -185,6 +185,6 @@ class mod_imscp_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index a057f13..d456100 100644 (file)
@@ -353,11 +353,11 @@ function label_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_label_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_label_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['label'][$event->instance];
 
index 347d75c..38d9834 100644 (file)
@@ -104,7 +104,7 @@ class mod_label_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -116,6 +116,6 @@ class mod_label_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
\ No newline at end of file
index d7a2dfb..65f2c82 100644 (file)
@@ -208,8 +208,8 @@ function lesson_update_events($lesson, $override = null) {
                     unset($event->id);
                 }
                 $event->name = $eventname.' ('.get_string('lessonopens', 'lesson').')';
-                // The method \core_calendar\event::create will reuse a db record if the id field is set.
-                \core_calendar\event::create($event);
+                // The method calendar_event::create will reuse a db record if the id field is set.
+                calendar_event::create($event);
             }
             if ($deadline && $addclose) {
                 if ($oldevent = array_shift($oldevents)) {
@@ -228,14 +228,14 @@ function lesson_update_events($lesson, $override = null) {
                         $event->priority = $closepriorities[$deadline];
                     }
                 }
-                \core_calendar\event::create($event);
+                calendar_event::create($event);
             }
         }
     }
 
     // Delete any leftover events.
     foreach ($oldevents as $badevent) {
-        $badevent = \core_calendar\event::load($badevent);
+        $badevent = calendar_event::load($badevent);
         $badevent->delete();
     }
 }
@@ -1570,11 +1570,11 @@ function lesson_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_lesson_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_lesson_core_calendar_provide_event_action(calendar_event $event,
                                                        \core_calendar\action_factory $factory) {
     global $DB, $CFG, $USER;
     require_once($CFG->dirroot . '/mod/lesson/locallib.php');
index 4cabf51..fff9f82 100644 (file)
@@ -1575,7 +1575,7 @@ class lesson extends lesson_base {
         $DB->delete_records("lesson_branch", array("lessonid"=>$this->properties->id));
         if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$this->properties->id))) {
             foreach($events as $event) {
-                $event = \core_calendar\event::load($event);
+                $event = calendar_event::load($event);
                 $event->delete();
             }
         }
@@ -1613,7 +1613,7 @@ class lesson extends lesson_base {
         }
         $events = $DB->get_records('event', $conds);
         foreach ($events as $event) {
-            $eventold = \core_calendar\event::load($event);
+            $eventold = calendar_event::load($event);
             $eventold->delete();
         }
 
index 5f68744..7bd187d 100644 (file)
@@ -276,7 +276,7 @@ class mod_lesson_lib_testcase extends advanced_testcase {
      * @param int $courseid
      * @param int $instanceid The lesson id.
      * @param string $eventtype The event type. eg. LESSON_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -287,6 +287,6 @@ class mod_lesson_lib_testcase extends advanced_testcase {
         $event->type = CALENDAR_EVENT_TYPE_ACTION;
         $event->eventtype = $eventtype;
         $event->timestart = time();
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 146d72c..e7df1cb 100644 (file)
@@ -628,11 +628,11 @@ function mod_lti_get_fontawesome_icon_map() {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_lti_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_lti_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['lti'][$event->instance];
 
index 14cb1fe..b526713 100644 (file)
@@ -171,7 +171,7 @@ class mod_lti_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -183,6 +183,6 @@ class mod_lti_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 8d2a62d..b1f5a84 100644 (file)
@@ -535,11 +535,11 @@ function page_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_page_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_page_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['page'][$event->instance];
 
index 616e7e9..8094551 100644 (file)
@@ -155,7 +155,7 @@ class mod_page_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -167,6 +167,6 @@ class mod_page_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 99a7dad..47ac20f 100644 (file)
@@ -197,7 +197,7 @@ function quiz_delete_instance($id) {
 
     $events = $DB->get_records('event', array('modulename' => 'quiz', 'instance' => $quiz->id));
     foreach ($events as $event) {
-        $event = core_calendar\event::load($event);
+        $event = calendar_event::load($event);
         $event->delete();
     }
 
@@ -229,7 +229,7 @@ function quiz_delete_override($quiz, $overrideid) {
             'instance' => $quiz->id, 'groupid' => (int)$override->groupid,
             'userid' => (int)$override->userid));
     foreach ($events as $event) {
-        $eventold = \core_calendar\event::load($event);
+        $eventold = calendar_event::load($event);
         $eventold->delete();
     }
 
@@ -1292,8 +1292,8 @@ function quiz_update_events($quiz, $override = null) {
                     unset($event->id);
                 }
                 $event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
-                // The method \core_calendar\event::create will reuse a db record if the id field is set.
-                \core_calendar\event::create($event);
+                // The method calendar_event::create will reuse a db record if the id field is set.
+                calendar_event::create($event);
             }
             if ($timeclose && $addclose) {
                 if ($oldevent = array_shift($oldevents)) {
@@ -1312,14 +1312,14 @@ function quiz_update_events($quiz, $override = null) {
                         $event->priority = $closepriorities[$timeclose];
                     }
                 }
-                \core_calendar\event::create($event);
+                calendar_event::create($event);
             }
         }
     }
 
     // Delete any leftover events.
     foreach ($oldevents as $badevent) {
-        $badevent = \core_calendar\event::load($badevent);
+        $badevent = calendar_event::load($badevent);
         $badevent->delete();
     }
 }
@@ -2079,11 +2079,11 @@ function mod_quiz_get_fontawesome_icon_map() {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_quiz_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_quiz_core_calendar_provide_event_action(calendar_event $event,
                                                      \core_calendar\action_factory $factory) {
     global $CFG, $USER;
 
index 1c31d26..a7bf1d2 100644 (file)
@@ -676,7 +676,7 @@ class mod_quiz_lib_testcase extends advanced_testcase {
      * @param int $courseid
      * @param int $instanceid The quiz id.
      * @param string $eventtype The event type. eg. QUIZ_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -688,7 +688,7 @@ class mod_quiz_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 
 }
index 104e566..da5f0fa 100644 (file)
@@ -550,11 +550,11 @@ function resource_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_resource_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_resource_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['resource'][$event->instance];
 
index 9f008c9..0b740f5 100644 (file)
@@ -218,7 +218,7 @@ class mod_resource_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -230,6 +230,6 @@ class mod_resource_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index efe0dbd..c57a12a 100644 (file)
@@ -1595,11 +1595,11 @@ function scorm_refresh_events($courseid = 0) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_scorm_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_scorm_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     global $CFG, $DB;
 
index 4f08a3b..869de92 100644 (file)
@@ -2384,11 +2384,11 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
             $event->visible = instance_is_visible('scorm', $scorm);
             $event->timeduration = 0;
 
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Calendar event is on longer needed.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -2406,7 +2406,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
             $event->visible = instance_is_visible('scorm', $scorm);
             $event->timeduration = 0;
 
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 
@@ -2425,11 +2425,11 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
             $event->visible = instance_is_visible('scorm', $scorm);
             $event->timeduration = 0;
 
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             // Calendar event is on longer needed.
-            $calendarevent = \core_calendar\event::load($event->id);
+            $calendarevent = calendar_event::load($event->id);
             $calendarevent->delete();
         }
     } else {
@@ -2447,7 +2447,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
             $event->visible = instance_is_visible('scorm', $scorm);
             $event->timeduration = 0;
 
-            \core_calendar\event::create($event);
+            calendar_event::create($event);
         }
     }
 
index 893d5d5..fcc928b 100644 (file)
@@ -313,7 +313,7 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
      * @param int $courseid
      * @param int $instanceid The data id.
      * @param string $eventtype The event type. eg. DATA_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -325,6 +325,6 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index fe3cff3..e7cb63a 100644 (file)
@@ -1089,11 +1089,11 @@ function survey_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_survey_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_survey_core_calendar_provide_event_action(calendar_event $event,
                                                       \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['survey'][$event->instance];
     $context = context_module::instance($cm->id);
index 81bd430..545b96a 100644 (file)
@@ -261,7 +261,7 @@ class mod_survey_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -273,6 +273,6 @@ class mod_survey_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index f0b244e..b0aa75e 100644 (file)
@@ -378,11 +378,11 @@ function url_check_updates_since(cm_info $cm, $from, $filter = array()) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_url_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_url_core_calendar_provide_event_action(calendar_event $event,
                                                        \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['url'][$event->instance];
 
index 39c3d1d..571ee2a 100644 (file)
@@ -182,7 +182,7 @@ class mod_url_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -194,6 +194,6 @@ class mod_url_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
\ No newline at end of file
index 7fbe38b..24984cd 100644 (file)
@@ -804,11 +804,11 @@ function mod_wiki_get_fontawesome_icon_map() {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_wiki_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_wiki_core_calendar_provide_event_action(calendar_event $event,
                                                     \core_calendar\action_factory $factory) {
     $cm = get_fast_modinfo($event->courseid)->instances['wiki'][$event->instance];
 
index 99c8428..9ecaf09 100644 (file)
@@ -805,7 +805,7 @@ class mod_wiki_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The instance id.
      * @param string $eventtype The event type.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -817,6 +817,6 @@ class mod_wiki_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }
index 29df113..d08b721 100644 (file)
@@ -270,7 +270,7 @@ function workshop_delete_instance($id) {
     // delete the calendar events
     $events = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
     foreach ($events as $event) {
-        $event = \core_calendar\event::load($event);
+        $event = calendar_event::load($event);
         $event->delete();
     }
 
@@ -1721,7 +1721,7 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
             unset($event->id);
         }
         // update() will reuse a db record if the id field is set
-        $eventobj = new \core_calendar\event($event);
+        $eventobj = new calendar_event($event);
         $eventobj->update($event, false);
     }
 
@@ -1739,7 +1739,7 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
             unset($event->id);
         }
         // update() will reuse a db record if the id field is set
-        $eventobj = new \core_calendar\event($event);
+        $eventobj = new calendar_event($event);
         $eventobj->update($event, false);
     }
 
@@ -1757,7 +1757,7 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
             unset($event->id);
         }
         // update() will reuse a db record if the id field is set
-        $eventobj = new \core_calendar\event($event);
+        $eventobj = new calendar_event($event);
         $eventobj->update($event, false);
     }
 
@@ -1775,13 +1775,13 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
             unset($event->id);
         }
         // update() will reuse a db record if the id field is set
-        $eventobj = new \core_calendar\event($event);
+        $eventobj = new calendar_event($event);
         $eventobj->update($event, false);
     }
 
     // delete any leftover events
     foreach ($currentevents as $oldevent) {
-        $oldevent = \core_calendar\event::load($oldevent);
+        $oldevent = calendar_event::load($oldevent);
         $oldevent->delete();
     }
 }
@@ -1789,11 +1789,11 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
 /**
  * Handles creating actions for events.
  *
- * @param \core_calendar\event $event
+ * @param calendar_event $event
  * @param \core_calendar\action_factory $factory
  * @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
  */
-function mod_workshop_core_calendar_provide_event_action(\core_calendar\event $event,
+function mod_workshop_core_calendar_provide_event_action(calendar_event $event,
                                                          \core_calendar\action_factory $factory) {
 
     $cm = get_fast_modinfo($event->courseid)->instances['workshop'][$event->instance];
index 439b41f..9c745a7 100644 (file)
@@ -131,7 +131,7 @@ class mod_workshop_lib_testcase extends advanced_testcase {
      * @param int $courseid The course id.
      * @param int $instanceid The workshop id.
      * @param string $eventtype The event type. eg. WORKSHOP_EVENT_TYPE_OPEN.
-     * @return bool|\core_calendar\event
+     * @return bool|calendar_event
      */
     private function create_action_event($courseid, $instanceid, $eventtype) {
         $event = new stdClass();
@@ -143,6 +143,6 @@ class mod_workshop_lib_testcase extends advanced_testcase {
         $event->eventtype = $eventtype;
         $event->timestart = time();
 
-        return \core_calendar\event::create($event);
+        return calendar_event::create($event);
     }
 }