Skip to content

Commit

Permalink
MDL-55902 my: Add additional information to dashboard reset events
Browse files Browse the repository at this point in the history
* Add $private and $pagetype information to the 'other' parameter of
the dashboard(s) reset events.
  • Loading branch information
LukeCarrier authored and junpataleta committed Oct 24, 2016
1 parent 919b9df commit 14d6c1c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/classes/event/dashboard_reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/classes/event/dashboards_reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions my/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
24 changes: 24 additions & 0 deletions my/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand All @@ -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']);
}
}

0 comments on commit 14d6c1c

Please sign in to comment.