mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-55902 my: Add additional information to dashboard reset events
* Add $private and $pagetype information to the 'other' parameter of the dashboard(s) reset events.
This commit is contained in:
parent
919b9dfabd
commit
14d6c1cf79
@ -30,6 +30,13 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* 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
|
||||
|
@ -30,6 +30,13 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*
|
||||
* 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
|
||||
|
16
my/lib.php
16
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();
|
||||
}
|
||||
|
@ -99,7 +99,19 @@ class dashboard_events_testcase extends advanced_testcase {
|
||||
// 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 @@ class dashboard_events_testcase extends advanced_testcase {
|
||||
// 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']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user