diff --git a/lib/classes/event/dashboard_reset.php b/lib/classes/event/dashboard_reset.php index 76a10c246e9c9..cfeaacfeac2b3 100644 --- a/lib/classes/event/dashboard_reset.php +++ b/lib/classes/event/dashboard_reset.php @@ -30,6 +30,13 @@ * * Class for event to be triggered when a dashboard is reset. * + * @property-read array $other { + * Extra information about event. + * + * - string private: Either MY_PAGE_PRIVATE or MY_PAGE_PUBLIC. + * - string pagetype: Either my-index or user-profile. + * } + * * @package core * @since Moodle 3.2 * @copyright 2016 Stephen Bourget diff --git a/lib/classes/event/dashboards_reset.php b/lib/classes/event/dashboards_reset.php index 43b2c647ef68d..d9df07b4926b3 100644 --- a/lib/classes/event/dashboards_reset.php +++ b/lib/classes/event/dashboards_reset.php @@ -30,6 +30,13 @@ * * Class for event to be triggered when all user dashboards are reset. * + * @property-read array $other { + * Extra information about event. + * + * - string private: Either MY_PAGE_PRIVATE or MY_PAGE_PUBLIC. + * - string pagetype: Either my-index or user-profile. + * } + * * @package core * @since Moodle 3.2 * @copyright 2016 Stephen Bourget diff --git a/my/lib.php b/my/lib.php index d458139a28692..be8beb9151b83 100644 --- a/my/lib.php +++ b/my/lib.php @@ -135,7 +135,13 @@ function my_reset_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') } // Trigger dashboard has been reset event. - $eventparams = array('context' => context_user::instance($userid)); + $eventparams = array( + 'context' => context_user::instance($userid), + 'other' => array( + 'private' => $private, + 'pagetype' => $pagetype, + ), + ); $event = \core\event\dashboard_reset::create($eventparams); $event->trigger(); return $systempage; @@ -182,7 +188,13 @@ function my_reset_page_for_all_users($private = MY_PAGE_PRIVATE, $pagetype = 'my $transaction->allow_commit(); // Trigger dashboard has been reset event. - $eventparams = array('context' => context_system::instance()); + $eventparams = array( + 'context' => context_system::instance(), + 'other' => array( + 'private' => $private, + 'pagetype' => $pagetype, + ), + ); $event = \core\event\dashboards_reset::create($eventparams); $event->trigger(); } diff --git a/my/tests/events_test.php b/my/tests/events_test.php index f7892f66a7727..3fe006a23f684 100644 --- a/my/tests/events_test.php +++ b/my/tests/events_test.php @@ -99,7 +99,19 @@ public function test_dashboard_reset() { // Check that the event data is valid. $this->assertInstanceOf('\core\event\dashboard_reset', $event); $this->assertEquals($user->id, $event->userid); + $this->assertEquals(MY_PAGE_PRIVATE, $event->other['private']); + $this->assertEquals('my-index', $event->other['pagetype']); $this->assertDebuggingNotCalled(); + + // Reset the dashboard with private parameter is set to MY_PAGE_PUBLIC and pagetype set to 'user-profile'. + $sink = $this->redirectEvents(); + my_reset_page($user->id, MY_PAGE_PUBLIC, 'user-profile'); + + // Trigger and capture the event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertEquals(MY_PAGE_PUBLIC, $event->other['private']); + $this->assertEquals('user-profile', $event->other['pagetype']); } /** @@ -124,6 +136,18 @@ public function test_dashboards_reset() { // Check that the event data is valid. $this->assertInstanceOf('\core\event\dashboards_reset', $event); $this->assertEquals($USER->id, $event->userid); + $this->assertEquals(MY_PAGE_PRIVATE, $event->other['private']); + $this->assertEquals('my-index', $event->other['pagetype']); $this->assertDebuggingNotCalled(); + + // Reset the dashboards with private parameter is set to MY_PAGE_PUBLIC and pagetype set to 'user-profile'. + $sink = $this->redirectEvents(); + my_reset_page_for_all_users(MY_PAGE_PUBLIC, 'user-profile'); + + // Trigger and capture the event. + $events = $sink->get_events(); + $event = reset($events); + $this->assertEquals(MY_PAGE_PUBLIC, $event->other['private']); + $this->assertEquals('user-profile', $event->other['pagetype']); } }