Commit e1cd93ce authored by Mark Nelson's avatar Mark Nelson Committed by Dan Poltawski
Browse files

MDL-58423 core_calendar: moved \core_calendar\event class

Part of MDL-55611 epic.
parent 1dc764a6
......@@ -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.
......
This diff is collapsed.
......@@ -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) {
......
......@@ -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);
......
......@@ -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);
}
}
......
......@@ -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
......
......@@ -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');
}
......
......@@ -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)) {
......
This diff is collapsed.
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
}
}
......@@ -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);
}
}
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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.
......
......@@ -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);
}
}
......
......@@ -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
......
......@@ -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);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment