mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-40915-master' of git://github.com/ankitagarwal/moodle
This commit is contained in:
commit
e9e3431ad9
@ -2165,7 +2165,7 @@ class calendar_event {
|
||||
* @return bool event updated
|
||||
*/
|
||||
public function update($data, $checkcapability=true) {
|
||||
global $CFG, $DB, $USER;
|
||||
global $DB, $USER;
|
||||
|
||||
foreach ($data as $key=>$value) {
|
||||
$this->properties->$key = $value;
|
||||
@ -2174,6 +2174,17 @@ class calendar_event {
|
||||
$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) {
|
||||
@ -2239,7 +2250,10 @@ class calendar_event {
|
||||
}
|
||||
|
||||
// Log the event entry.
|
||||
add_to_log($this->properties->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$this->properties->id, $this->properties->name);
|
||||
$eventargs['objectid'] = $this->properties->id;
|
||||
$eventargs['context'] = $this->properties->context;
|
||||
$event = \core\event\calendar_event_created::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
$repeatedids = array();
|
||||
|
||||
@ -2267,8 +2281,12 @@ class calendar_event {
|
||||
}
|
||||
|
||||
$repeatedids[] = $eventcopyid;
|
||||
// Log the event entry.
|
||||
add_to_log($eventcopy->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventcopyid, $eventcopy->name);
|
||||
|
||||
// Trigger an event.
|
||||
$eventargs['objectid'] = $eventcopyid;
|
||||
$eventargs['other']['timestart'] = $eventcopy->timestart;
|
||||
$event = \core\event\calendar_event_created::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2322,13 +2340,22 @@ class calendar_event {
|
||||
}
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Log the event update.
|
||||
add_to_log($this->properties->courseid, 'calendar', 'edit all', 'event.php?action=edit&id='.$this->properties->id, $this->properties->name);
|
||||
// Trigger an update event for each of the calendar event.
|
||||
$events = $DB->get_records('event', array('repeatid' => $event->repeatid), '', 'id,timestart');
|
||||
foreach ($events as $event) {
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
} else {
|
||||
$DB->update_record('event', $this->properties);
|
||||
$event = calendar_event::load($this->properties->id);
|
||||
$this->properties = $event->properties();
|
||||
add_to_log($this->properties->courseid, 'calendar', 'edit', 'event.php?action=edit&id='.$this->properties->id, $this->properties->name);
|
||||
|
||||
// Trigger an update event.
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
// Hook for tracking event updates
|
||||
@ -2356,10 +2383,23 @@ class calendar_event {
|
||||
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);
|
||||
@ -2367,8 +2407,14 @@ class calendar_event {
|
||||
$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 the event_update hook.
|
||||
// For each of the returned events trigger the event_update hook and an update event.
|
||||
foreach ($events as $event) {
|
||||
// Trigger an event for the update.
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
self::calendar_event_hook('update_event', array($event, false));
|
||||
}
|
||||
}
|
||||
|
389
calendar/tests/event_test.php
Normal file
389
calendar/tests/event_test.php
Normal file
@ -0,0 +1,389 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* This file contains the class that handles testing of the calendar events.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2014 Ankit Agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/tests/externallib_test.php');
|
||||
|
||||
/**
|
||||
* This file contains the class that handles testing of the calendar events.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2014 Ankit Agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* The test user.
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* The test course.
|
||||
*/
|
||||
private $course;
|
||||
|
||||
/**
|
||||
* Test set up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
global $USER;
|
||||
// The user we are going to test this on.
|
||||
$this->setAdminUser();
|
||||
$this->user = $USER;
|
||||
$this->course = self::getDataGenerator()->create_course();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for calendar_event_created event.
|
||||
*/
|
||||
public function test_calendar_event_created() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Catch the events.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
// Create a calendar event.
|
||||
$record = new stdClass();
|
||||
$record->courseid = 0;
|
||||
$time = time();
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('event', $this->user->id, 'user', 0, $time,
|
||||
$record); // User event.
|
||||
|
||||
// Capture the event.
|
||||
$events = $sink->get_events();
|
||||
$sink->clear();
|
||||
|
||||
// Validate the event.
|
||||
$event = $events[0];
|
||||
$this->assertInstanceOf('\core\event\calendar_event_created', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals(0, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
$expectedlog = array(0, 'calendar', 'add', 'event.php?action=edit&id=' . $calevent->id , $calevent->name);
|
||||
$other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'event');
|
||||
$this->assertEquals($other, $event->other);
|
||||
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
// Now we create a repeated course event.
|
||||
$record = new stdClass();
|
||||
$record->courseid = $this->course->id;
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('course', $this->user->id, 'course', 10, $time,
|
||||
$record);
|
||||
$events = $sink->get_events();
|
||||
$sink->close();
|
||||
|
||||
$this->assertEquals(10, count($events));
|
||||
foreach ($events as $event) {
|
||||
$this->assertInstanceOf('\core\event\calendar_event_created', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals($this->course->id, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to calendar_event_created event.
|
||||
*/
|
||||
public function test_calendar_event_created_validations() {
|
||||
$this->resetAfterTest();
|
||||
$context = context_user::instance($this->user->id);
|
||||
|
||||
// Test not setting other['repeatid'].
|
||||
try {
|
||||
\core\event\calendar_event_created::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'timestart' => time(),
|
||||
'name' => 'event'
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_created to be triggered without
|
||||
other['repeatid']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['repeatid'] must be set", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting other['name'].
|
||||
try {
|
||||
\core\event\calendar_event_created::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'repeatid' => 0,
|
||||
'timestart' => time(),
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_created to be triggered without
|
||||
other['name']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting other['timestart'].
|
||||
try {
|
||||
\core\event\calendar_event_created::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'name' => 'event',
|
||||
'repeatid' => 0,
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
|
||||
other['timestart']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['timestart'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for calendar_event_updated event.
|
||||
*/
|
||||
public function test_calendar_event_updated() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a calendar event.
|
||||
$record = new stdClass();
|
||||
$record->courseid = 0;
|
||||
$time = time();
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('event', $this->user->id, 'user', 0, $time,
|
||||
$record); // User event.
|
||||
|
||||
// Catch the events.
|
||||
$sink = $this->redirectEvents();
|
||||
$prop = new stdClass();
|
||||
$prop->name = 'new event';
|
||||
$calevent->update($prop); // Update calender event.
|
||||
// Capture the event.
|
||||
$events = $sink->get_events();
|
||||
|
||||
// Validate the event.
|
||||
$event = $events[0];
|
||||
$this->assertInstanceOf('\core\event\calendar_event_updated', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals(0, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
$expectedlog = array(0, 'calendar', 'edit', 'event.php?action=edit&id=' . $calevent->id , $calevent->name);
|
||||
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||
$other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'new event');
|
||||
$this->assertEquals($other, $event->other);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
// Now we create a repeated course event and update it.
|
||||
$record = new stdClass();
|
||||
$record->courseid = $this->course->id;
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('course', $this->user->id, 'course', 10, time(),
|
||||
$record);
|
||||
|
||||
$sink->clear();
|
||||
$prop = new stdClass();
|
||||
$prop->name = 'new event';
|
||||
$prop->repeateditall = true;
|
||||
$calevent->update($prop); // Update calender event.
|
||||
$events = $sink->get_events();
|
||||
$sink->close();
|
||||
|
||||
$this->assertEquals(10, count($events));
|
||||
foreach ($events as $event) {
|
||||
$this->assertInstanceOf('\core\event\calendar_event_updated', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals($this->course->id, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to calendar_event_created event.
|
||||
*/
|
||||
public function test_calendar_event_updated_validations() {
|
||||
$this->resetAfterTest();
|
||||
$context = context_user::instance($this->user->id);
|
||||
|
||||
// Test not setting other['repeatid'].
|
||||
try {
|
||||
\core\event\calendar_event_updated::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'timestart' => time(),
|
||||
'name' => 'event'
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_updated to be triggered without
|
||||
other['repeatid']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['repeatid'] must be set", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting other['name'].
|
||||
try {
|
||||
\core\event\calendar_event_updated::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'repeatid' => 0,
|
||||
'timestart' => time(),
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_updated to be triggered without
|
||||
other['name']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting other['timestart'].
|
||||
try {
|
||||
\core\event\calendar_event_updated::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'name' => 'event',
|
||||
'repeatid' => 0,
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
|
||||
other['timestart']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['timestart'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for calendar_event_deleted event.
|
||||
*/
|
||||
public function test_calendar_event_deleted() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a calendar event.
|
||||
$record = new stdClass();
|
||||
$record->courseid = 0;
|
||||
$record->repeatid = 0;
|
||||
$time = time();
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('event', $this->user->id, 'user', 0, $time,
|
||||
$record); // User event.
|
||||
$dbrecord = $DB->get_record('event', array('id' => $calevent->id), '*', MUST_EXIST);
|
||||
|
||||
// Catch the events.
|
||||
$sink = $this->redirectEvents();
|
||||
$calevent->delete(false);
|
||||
$events = $sink->get_events();
|
||||
|
||||
// Validate the event.
|
||||
$event = $events[0];
|
||||
$this->assertInstanceOf('\core\event\calendar_event_deleted', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals(0, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
$other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'event');
|
||||
$this->assertEquals($other, $event->other);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertEquals($dbrecord, $event->get_record_snapshot('event', $event->objectid));
|
||||
|
||||
// Now we create a repeated course event and delete it.
|
||||
$record = new stdClass();
|
||||
$record->courseid = $this->course->id;
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('course', $this->user->id, 'course', 10, time(),
|
||||
$record);
|
||||
|
||||
$sink->clear();
|
||||
$prop = new stdClass();
|
||||
$prop->name = 'new event';
|
||||
$prop->repeateditall = true;
|
||||
$calevent->delete(true);
|
||||
$events = $sink->get_events();
|
||||
$sink->close();
|
||||
|
||||
$this->assertEquals(10, count($events));
|
||||
foreach ($events as $event) {
|
||||
$this->assertInstanceOf('\core\event\calendar_event_deleted', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals($this->course->id, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to calendar_event_deleted event.
|
||||
*/
|
||||
public function test_calendar_event_deleted_validations() {
|
||||
$this->resetAfterTest();
|
||||
$context = context_user::instance($this->user->id);
|
||||
|
||||
// Test not setting other['repeatid'].
|
||||
try {
|
||||
\core\event\calendar_event_deleted::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'timestart' => time(),
|
||||
'name' => 'event'
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
|
||||
other['repeatid']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['repeatid'] must be set", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting other['name'].
|
||||
try {
|
||||
\core\event\calendar_event_deleted::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'repeatid' => 0,
|
||||
'timestart' => time(),
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
|
||||
other['name']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting other['timestart'].
|
||||
try {
|
||||
\core\event\calendar_event_deleted::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => 2,
|
||||
'other' => array(
|
||||
'name' => 'event',
|
||||
'repeatid' => 0,
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
|
||||
other['timestart']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['timestart'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -97,7 +97,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (empty($prop->courseid)) {
|
||||
if (!isset($prop->courseid)) {
|
||||
$prop->courseid = $SITE->id;
|
||||
}
|
||||
$event = new calendar_event($prop);
|
||||
|
@ -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';
|
||||
|
109
lib/classes/event/calendar_event_created.php
Normal file
109
lib/classes/event/calendar_event_created.php
Normal file
@ -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 <ankit.agrr@gmail.com>
|
||||
* @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 <ankit.agrr@gmail.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
90
lib/classes/event/calendar_event_deleted.php
Normal file
90
lib/classes/event/calendar_event_deleted.php
Normal file
@ -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 <ankit.agrr@gmail.com>
|
||||
* @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 <ankit.agrr@gmail.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
109
lib/classes/event/calendar_event_updated.php
Normal file
109
lib/classes/event/calendar_event_updated.php
Normal file
@ -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 <ankit.agrr@gmail.com>
|
||||
* @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 <ankit.agrr@gmail.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user