mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 09:56:38 +02:00
MDL-47162 core_message: Add course id to message eventdata
This commit is contained in:
parent
577bd70d38
commit
cc350fd9c8
34 changed files with 345 additions and 76 deletions
|
@ -33,6 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
|||
* Extra information about event.
|
||||
*
|
||||
* - int messageid: the id of the message.
|
||||
* - int courseid: the id of the related course.
|
||||
* }
|
||||
*
|
||||
* @package core
|
||||
|
@ -46,9 +47,10 @@ class message_sent extends base {
|
|||
* @param int $userfromid
|
||||
* @param int $usertoid
|
||||
* @param int $messageid
|
||||
* @param int|null $courseid
|
||||
* @return message_sent
|
||||
*/
|
||||
public static function create_from_ids($userfromid, $usertoid, $messageid) {
|
||||
public static function create_from_ids($userfromid, $usertoid, $messageid, $courseid = null) {
|
||||
// We may be sending a message from the 'noreply' address, which means we are not actually sending a
|
||||
// message from a valid user. In this case, we will set the userid to 0.
|
||||
// Check if the userid is valid.
|
||||
|
@ -56,6 +58,10 @@ class message_sent extends base {
|
|||
$userfromid = 0;
|
||||
}
|
||||
|
||||
if (is_null($courseid)) {
|
||||
$courseid = SITEID;
|
||||
}
|
||||
|
||||
$event = self::create(array(
|
||||
'userid' => $userfromid,
|
||||
'context' => \context_system::instance(),
|
||||
|
@ -64,7 +70,8 @@ class message_sent extends base {
|
|||
// In earlier versions it can either be the id in the 'message_read' or 'message' table.
|
||||
// Now it is always the id from 'message' table. Please note that the record is still moved
|
||||
// to the 'message_read' table later when message marked as read.
|
||||
'messageid' => $messageid
|
||||
'messageid' => $messageid,
|
||||
'courseid' => $courseid
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -143,6 +150,10 @@ class message_sent extends base {
|
|||
if (!isset($this->other['messageid'])) {
|
||||
throw new \coding_exception('The \'messageid\' value must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['courseid'])) {
|
||||
debugging('The \'courseid\' value must be set in other.', DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_objectid_mapping() {
|
||||
|
@ -155,6 +166,7 @@ class message_sent extends base {
|
|||
$othermapped = array();
|
||||
// The messages table could vary for older events - so cannot be mapped.
|
||||
$othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
$othermapped['courseid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED);
|
||||
return $othermapped;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue