From b435a3f0a7ff0ee770040380bb25ce2d33159694 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Thu, 13 Feb 2020 09:39:15 +1100 Subject: [PATCH] Improved wording and links for all 3 outage events --- classes/dml/outagedb.php | 38 +++++++++++++++++++++++++------- classes/event/outage_created.php | 5 ++--- classes/event/outage_deleted.php | 5 ++--- classes/event/outage_updated.php | 5 ++--- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/classes/dml/outagedb.php b/classes/dml/outagedb.php index 32aa4fc..f5c6331 100644 --- a/classes/dml/outagedb.php +++ b/classes/dml/outagedb.php @@ -117,19 +117,32 @@ class outagedb { $outage->createdby = $USER->id; // Then create it, log it and adjust its id. $outage->id = $DB->insert_record('auth_outage', $outage, true); - outage_created::create( - ['objectid' => $outage->id, 'other' => (array)$outage] - )->trigger(); + + $other = (array) $outage; + $other['title'] = $outage->get_title(); + $event = outage_created::create([ + 'objectid' => $outage->id, + 'other' => $other, + ]); + $event->add_record_snapshot('auth_outage', (object)(array) $outage); + $event->trigger(); + // Create calendar entry. calendar::create($outage); } else { // Remove the createdby field so it does not get updated. unset($outage->createdby); $DB->update_record('auth_outage', $outage); - // Log it. - outage_updated::create( - ['objectid' => $outage->id, 'other' => (array)$outage] - )->trigger(); + + $other = (array) $outage; + $other['title'] = $outage->get_title(); + $event = outage_updated::create([ + 'objectid' => $outage->id, + 'other' => $other, + ]); + $event->add_record_snapshot('auth_outage', (object)(array) $outage); + $event->trigger(); + // Update calendar entry. calendar::update($outage); } @@ -156,7 +169,16 @@ class outagedb { // Log it. $previous = $DB->get_record('auth_outage', ['id' => $id], '*', MUST_EXIST); - $event = outage_deleted::create(['objectid' => $id, 'other' => (array)$previous]); + + $outage = new outage($previous); + + $other = (array) $outage; + $other['title'] = $outage->get_title(); + $event = outage_deleted::create([ + 'objectid' => $id, + 'other' => $other, + ]); + $event->add_record_snapshot('auth_outage', $previous); $event->trigger(); diff --git a/classes/event/outage_created.php b/classes/event/outage_created.php index 922668d..d2593e3 100644 --- a/classes/event/outage_created.php +++ b/classes/event/outage_created.php @@ -45,8 +45,7 @@ class outage_created extends base { * @return string */ public function get_description() { - return "The user with the id '{$this->userid}' created a new outage title '{$this->other['title']}' ". - " with id '{$this->other['id']}'."; + return "The user with the id '{$this->userid}' created outage {$this->other['id']} '{$this->other['title']}'"; } /** @@ -54,7 +53,7 @@ class outage_created extends base { * @return moodle_url */ public function get_url() { - return new moodle_url('/auth/outage/list.php#auth_outage_id_'.$this->other['id']); + return new moodle_url('/auth/outage/edit.php', ['edit' => $this->other['id']]); } /** diff --git a/classes/event/outage_deleted.php b/classes/event/outage_deleted.php index 2234e62..663c7f4 100644 --- a/classes/event/outage_deleted.php +++ b/classes/event/outage_deleted.php @@ -44,8 +44,7 @@ class outage_deleted extends base { * @return string */ public function get_description() { - return "The user with the id '{$this->userid}' deleted the outage titled '{$this->other['title']}' ". - "with id '{$this->other['id']}'."; + return "The user with the id '{$this->userid}' deleted outage {$this->other['id']} '{$this->other['title']}'"; } /** @@ -53,7 +52,7 @@ class outage_deleted extends base { * @return moodle_url */ public function get_url() { - return new moodle_url('/auth/outage/list.php#auth_outage_id_'.$this->other['id']); + return new moodle_url('/auth/outage/manage.php'); } /** diff --git a/classes/event/outage_updated.php b/classes/event/outage_updated.php index d0739bd..06feda7 100644 --- a/classes/event/outage_updated.php +++ b/classes/event/outage_updated.php @@ -45,8 +45,7 @@ class outage_updated extends base { * @return string */ public function get_description() { - return "The user with the id '{$this->userid}' updated the outage title '{$this->other['title']}' ". - "with id '{$this->other['id']}'."; + return "The user with the id '{$this->userid}' updated outage {$this->other['id']} '{$this->other['title']}'"; } /** @@ -54,7 +53,7 @@ class outage_updated extends base { * @return moodle_url */ public function get_url() { - return new moodle_url('/auth/outage/list.php'); + return new moodle_url('/auth/outage/edit.php', ['edit' => $this->other['id']]); } /**