MDL-39846 sample conversion of role assignment events
This commit is contained in:
+15
-3
@@ -1685,7 +1685,11 @@ function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0,
|
||||
reload_all_capabilities();
|
||||
}
|
||||
|
||||
events_trigger('role_assigned', $ra);
|
||||
$event = \core\event\role_assigned::create(
|
||||
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
|
||||
'extra'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_cached_record('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
|
||||
return $ra->id;
|
||||
}
|
||||
@@ -1769,8 +1773,12 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
|
||||
if (!empty($USER->id) && $USER->id == $ra->userid) {
|
||||
reload_all_capabilities();
|
||||
}
|
||||
$event = \core\event\role_unassigned::create(
|
||||
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
|
||||
'extra'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_cached_record('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
}
|
||||
events_trigger('role_unassigned', $ra);
|
||||
}
|
||||
unset($ras);
|
||||
|
||||
@@ -1796,7 +1804,11 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
|
||||
if (!empty($USER->id) && $USER->id == $ra->userid) {
|
||||
reload_all_capabilities();
|
||||
}
|
||||
events_trigger('role_unassigned', $ra);
|
||||
$event = \core\event\role_unassigned::create(
|
||||
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
|
||||
'extra'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_cached_record('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\event;
|
||||
|
||||
/**
|
||||
* Role assigned event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
class role_assigned extends base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 1; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this event replace legacy event?
|
||||
*
|
||||
* @return null|string legacy event name
|
||||
*/
|
||||
public function get_legacy_eventname() {
|
||||
return 'role_assigned';
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data if get_legacy_eventname() is not empty.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_legacy_eventdata() {
|
||||
return $this->get_cached_record('role_assignments', $this->data['extra']['id']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\event;
|
||||
|
||||
/**
|
||||
* Role unassigned event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
class role_unassigned extends base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = 1; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this event replace legacy event?
|
||||
*
|
||||
* @return null|string legacy event name
|
||||
*/
|
||||
public function get_legacy_eventname() {
|
||||
return 'role_unassigned';
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data if get_legacy_eventname() is not empty.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_legacy_eventdata() {
|
||||
return $this->get_cached_record('role_assignments', $this->data['extra']['id']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user