MDL-40915 events: Add events for calendar actions

Added a calendar_event_created
 Added a calendar_event_updated
 Added a calendar_event_deleted
This commit is contained in:
Ankit Agarwal
2014-03-21 16:33:19 +08:00
parent 9b8555fbea
commit 451c0e9e6a
4 changed files with 311 additions and 0 deletions
+3
View File
@@ -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';
@@ -0,0 +1,109 @@
<?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/>.
/**
* Calendar event created event.
*
* @package core
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
* @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 <[email protected]>
* @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&amp;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();
}
}
@@ -0,0 +1,90 @@
<?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/>.
/**
* Calendar event deleted event.
*
* @package core
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
* @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 <[email protected]>
* @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();
}
}
@@ -0,0 +1,109 @@
<?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/>.
/**
* Calendar event updated event.
*
* @package core
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
* @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 <[email protected]>
* @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&amp;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();
}
}