From 451c0e9e6a50e0fe5ce56c29d5e2a74a9c7da1e5 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 21 Mar 2014 10:36:09 +0800 Subject: [PATCH] MDL-40915 events: Add events for calendar actions Added a calendar_event_created Added a calendar_event_updated Added a calendar_event_deleted --- lang/en/calendar.php | 3 + lib/classes/event/calendar_event_created.php | 109 +++++++++++++++++++ lib/classes/event/calendar_event_deleted.php | 90 +++++++++++++++ lib/classes/event/calendar_event_updated.php | 109 +++++++++++++++++++ 4 files changed, 311 insertions(+) create mode 100644 lib/classes/event/calendar_event_created.php create mode 100644 lib/classes/event/calendar_event_deleted.php create mode 100644 lib/classes/event/calendar_event_updated.php diff --git a/lang/en/calendar.php b/lang/en/calendar.php index 5d081149358..e29095cf5e7 100644 --- a/lang/en/calendar.php +++ b/lang/en/calendar.php @@ -91,6 +91,9 @@ $string['eventsrelatedtocourses'] = 'Events related to courses'; $string['eventstarttime'] = 'Start time'; $string['eventtime'] = 'Time'; $string['eventview'] = 'Event details'; +$string['eventcalendareventcreated'] = 'Calendar event created'; +$string['eventcalendareventupdated'] = 'Calendar event updated'; +$string['eventcalendareventdeleted'] = 'Calendar event deleted'; $string['expired'] = 'Expired'; $string['explain_site_timeformat'] = 'You can choose to see times in either 12 or 24 hour format for the whole site. If you choose "default", then the format will be automatically chosen according to the language you use in the site. This setting can be overridden by user preferences.'; $string['export'] = 'Export'; diff --git a/lib/classes/event/calendar_event_created.php b/lib/classes/event/calendar_event_created.php new file mode 100644 index 00000000000..b9b83a66023 --- /dev/null +++ b/lib/classes/event/calendar_event_created.php @@ -0,0 +1,109 @@ +. + +/** + * Calendar event created event. + * + * @package core + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Calendar event created event. + * + * @property-read array $other Extra information about the event. + * -int timestart: timestamp for event time start. + * -string name: Name of the event. + * -int repeatid: Id of the parent event if present, else 0. + * + * @package core + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class calendar_event_created extends base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = 'event'; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventcalendareventcreated', 'core_calendar'); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "An event '" . s($this->other['name']) . "' was created by user with id {$this->userid}"; + } + + /** + * Returns relevant URL. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/calendar/view.php', array('view' => 'day', 'time' => $this->other['timestart']), + 'event_' . $this->objectid); + } + + /** + * Replace legacy add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'calendar', 'add', 'event.php?action=edit&id=' . $this->objectid , $this->other['name']); + } + + /** + * custom validations + * + * Throw \coding_exception notice in case of any problems. + */ + protected function validate_data() { + if (!isset($this->other['repeatid'])) { + throw new \coding_exception("Field other['repeatid'] must be set"); + } + if (empty($this->other['name'])) { + throw new \coding_exception("Field other['name'] cannot be empty"); + } + if (empty($this->other['timestart'])) { + throw new \coding_exception("Field other['timestart'] cannot be empty"); + } + + parent::validate_data(); + } +} diff --git a/lib/classes/event/calendar_event_deleted.php b/lib/classes/event/calendar_event_deleted.php new file mode 100644 index 00000000000..329aed5691f --- /dev/null +++ b/lib/classes/event/calendar_event_deleted.php @@ -0,0 +1,90 @@ +. + +/** + * Calendar event deleted event. + * + * @package core + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Calendar event deleted event. + * + * @property-read array $other Extra information about the event. + * -int timestart: timestamp for event time start. + * -string name: Name of the event. + * -int repeatid: Id of the parent event if present, else 0. + * + * @package core + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class calendar_event_deleted extends base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'd'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = 'event'; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventcalendareventdeleted', 'core_calendar'); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "An event '" . s($this->other['name']) . "' was deleted by user with id {$this->userid}"; + } + + /** + * custom validations + * + * Throw \coding_exception notice in case of any problems. + */ + protected function validate_data() { + if (!isset($this->other['repeatid'])) { + throw new \coding_exception("Field other['repeatid'] must be set"); + } + if (empty($this->other['name'])) { + throw new \coding_exception("Field other['name'] cannot be empty"); + } + if (empty($this->other['timestart'])) { + throw new \coding_exception("Field other['timestart'] cannot be empty"); + } + + parent::validate_data(); + } +} diff --git a/lib/classes/event/calendar_event_updated.php b/lib/classes/event/calendar_event_updated.php new file mode 100644 index 00000000000..ffab5b9f78b --- /dev/null +++ b/lib/classes/event/calendar_event_updated.php @@ -0,0 +1,109 @@ +. + +/** + * Calendar event updated event. + * + * @package core + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Calendar event updated event. + * + * @property-read array $other Extra information about the event. + * -int timestart: timestamp for event time start. + * -string name: Name of the event. + * -int repeatid: Id of the parent event if present, else 0. + * + * @package core + * @copyright 2014 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class calendar_event_updated extends base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = 'event'; + } + + /** + * Returns localised general event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventcalendareventupdated', 'core_calendar'); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "An event '" . s($this->other['name']) . "' was updated by user with id {$this->userid}"; + } + + /** + * Returns relevant URL. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/calendar/event.php', array('action' => 'edit', 'id' => $this->objectid)); + } + + /** + * Replace legacy add_to_log() statement. + * + * @return array of parameters to be passed to legacy add_to_log() function. + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'calendar', 'edit', 'event.php?action=edit&id=' . $this->objectid , + $this->other['name']); + } + + /** + * custom validations + * + * Throw \coding_exception notice in case of any problems. + */ + protected function validate_data() { + if (!isset($this->other['repeatid'])) { + throw new \coding_exception("Field other['repeatid'] must be set"); + } + if (empty($this->other['name'])) { + throw new \coding_exception("Field other['name'] cannot be empty"); + } + if (empty($this->other['timestart'])) { + throw new \coding_exception("Field other['timestart'] cannot be empty"); + } + + parent::validate_data(); + } +}