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) {
/**
* 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
*/
* 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 {
* 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;
}
/**
* @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."'.";
}
/**
* @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.');
+ }
}
}