MDL-48142 core_badge: bug fixes on badge awarded event class

This commit is contained in:
Simey Lameze
2015-02-19 12:32:36 +08:00
parent 483cfd763d
commit 4ae5ecbeef
2 changed files with 39 additions and 11 deletions
+7 -4
View File
@@ -399,10 +399,13 @@ class badge {
if ($result) {
// Trigger badge awarded event.
$context = context_system::instance();
$event = \core\event\badge_awarded::create(array('context' => $context, 'objectid' => $result,
'courseid' => $this->courseid ? $this->courseid : 0, 'relateduserid' => $userid));
$event->trigger();
$eventdata = array (
'context' => $this->get_context(),
'objectid' => $this->id,
'relateduserid' => $userid,
'other' => array('expiredate' => $issued->dateexpire, 'badgeissuedid' => $result)
);
\core\event\badge_awarded::create($eventdata)->trigger();
// Lock the badge, so that its criteria could not be changed any more.
if ($this->status == BADGE_STATUS_ACTIVE) {
+32 -7
View File
@@ -17,8 +17,15 @@
/**
* Badge awarded event.
*
* @property-read array $other {
* Extra information about event.
*
* - int expiredate: Badge expire timestamp.
* - int badgeissuedid: Badge issued ID.
* }
*
* @package core
* @copyright 2014 James Ballard
* @copyright 2015 James Ballard
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -29,8 +36,8 @@ defined('MOODLE_INTERNAL') || die();
* Event triggered after a badge is awarded to a user.
*
* @package core
* @since Moodle 2.7
* @copyright 2014 James Ballard
* @since Moodle 2.9
* @copyright 2015 James Ballard
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class badge_awarded extends base {
@@ -39,9 +46,9 @@ class badge_awarded extends base {
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'badge_issued';
$this->data['objecttable'] = 'badge';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
@@ -59,7 +66,7 @@ class badge_awarded extends base {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' was awarded the badge with id '$this->objectid'.";
return "The user with the id '$this->relateduserid' has been awarded the badge with id '".$this->objectid."'.";
}
/**
@@ -67,6 +74,24 @@ class badge_awarded extends base {
* @return \moodle_url
*/
public function get_url() {
return null;
return new \moodle_url('/badges/overview.php', array('id' => $this->objectid));
}
/**
* Custom validations.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->objectid)) {
throw new \coding_exception('The \'objectid\' must be set.');
}
}
}