mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-57545 core_calendar: trigger update event when toggling visibility
Part of MDL-55611 epic.
This commit is contained in:
parent
10a8ea172b
commit
c45266d115
@ -464,10 +464,12 @@ class event {
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Trigger an update event for each of the calendar event.
|
||||
$events = $DB->get_records('event', array('repeatid' => $event->repeatid), '', 'id,timestart');
|
||||
$events = $DB->get_records('event', array('repeatid' => $event->repeatid), '', 'id, timestart, visible');
|
||||
foreach ($events as $event) {
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$eventargs['other']['visible'] = (bool) $event->visible;
|
||||
$eventargs['other']['visibilitytoggled'] = false;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
@ -477,6 +479,8 @@ class event {
|
||||
$this->properties = $event->properties();
|
||||
|
||||
// Trigger an update event.
|
||||
$eventargs['other']['visible'] = (bool) $this->properties->visible;
|
||||
$eventargs['other']['visibilitytoggled'] = false;
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
@ -530,11 +534,14 @@ class event {
|
||||
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 and an update event.
|
||||
// For each of the returned events trigger an update event.
|
||||
foreach ($events as $event) {
|
||||
// Trigger an event for the update.
|
||||
$eventargs['objectid'] = $event->id;
|
||||
$eventargs['other']['timestart'] = $event->timestart;
|
||||
$eventargs['other']['visible'] = (bool) $event->visible;
|
||||
$eventargs['other']['visibilitytoggled'] = false;
|
||||
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
}
|
||||
@ -684,7 +691,24 @@ class event {
|
||||
}
|
||||
|
||||
// Update the database to reflect this change.
|
||||
return $DB->set_field('event', 'visible', $this->properties->visible, array('id' => $this->properties->id));
|
||||
$success = $DB->set_field('event', 'visible', $this->properties->visible, array('id' => $this->properties->id));
|
||||
|
||||
// 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,
|
||||
'visible' => (bool) $this->properties->visible,
|
||||
'visibilitytoggled' => true
|
||||
)
|
||||
);
|
||||
$event = \core\event\calendar_event_updated::create($eventargs);
|
||||
$event->trigger();
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -192,7 +192,8 @@ class core_calendar_events_testcase extends advanced_testcase {
|
||||
$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');
|
||||
$other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'new event', 'visible' => (bool) $calevent->visible,
|
||||
'visibilitytoggled' => false);
|
||||
$this->assertEquals($other, $event->other);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
@ -219,6 +220,39 @@ class core_calendar_events_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for calendar_event_updated event.
|
||||
*/
|
||||
public function test_calendar_event_updated_toggle_visibility() {
|
||||
global $SITE;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a calendar event.
|
||||
$time = time();
|
||||
$calevent = core_calendar_externallib_testcase::create_calendar_event('Some wickedly awesome event yo!',
|
||||
$this->user->id, 'user', 0, $time);
|
||||
|
||||
// Updated the visibility of the calendar event.
|
||||
$sink = $this->redirectEvents();
|
||||
$calevent->toggle_visibility();
|
||||
$events = $sink->get_events();
|
||||
|
||||
// Validate the calendar_event_updated event.
|
||||
$event = $events[0];
|
||||
$this->assertInstanceOf('\core\event\calendar_event_updated', $event);
|
||||
$this->assertEquals('event', $event->objecttable);
|
||||
$this->assertEquals($SITE->id, $event->courseid);
|
||||
$this->assertEquals($calevent->context, $event->get_context());
|
||||
$expectedlog = array($SITE->id, 'calendar', 'edit', 'event.php?action=edit&id=' . $calevent->id ,
|
||||
$calevent->name);
|
||||
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||
$other = array('repeatid' => 0, 'timestart' => time(), 'name' => 'Some wickedly awesome event yo!',
|
||||
'visible' => (bool) $calevent->visible, 'visibilitytoggled' => true);
|
||||
$this->assertEquals($other, $event->other);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to calendar_event_created event.
|
||||
*/
|
||||
|
@ -35,6 +35,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* - int repeatid: id of the parent event if present, else 0.
|
||||
* - int timestart: timestamp for event time start.
|
||||
* - string name: name of the event.
|
||||
* - bool visible: (optional) Is the calendar event visible?
|
||||
* - bool visibilitytoggled: (optional) Was the visibility changed?
|
||||
* }
|
||||
*
|
||||
* @package core
|
||||
|
Loading…
x
Reference in New Issue
Block a user