Skip to content

Commit

Permalink
MDL-43557 fix BC issue in \core\event\course_completed and incorrect …
Browse files Browse the repository at this point in the history
…description
  • Loading branch information
skodak committed Apr 30, 2014
1 parent 3373120 commit 8b233bd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
12 changes: 1 addition & 11 deletions completion/completion_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,7 @@ public function mark_complete($timecomplete = null) {
// Save record.
if ($result = $this->_save()) {
$data = $this->get_record_data();
$event = \core\event\course_completed::create(
array(
'objectid' => $data->id,
'userid' => $USER->id,
'relateduserid' => $data->userid,
'context' => context_course::instance($data->course),
'courseid' => $data->course
)
);
$event->add_record_snapshot('course_completions', $data);
$event->trigger();
\core\event\course_completed::create_from_completion($data)->trigger();
}

return $result;
Expand Down
39 changes: 38 additions & 1 deletion lib/classes/event/course_completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,37 @@
/**
* Course completed event class.
*
* @property-read int $relateduserid user who completed the course
* @property-read array $other {
* Extra information about event.
*
* - int relateduserid: deprecated since 2.7, please use property relateduserid
* }
*
* @package core
* @since Moodle 2.6
* @copyright 2013 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_completed extends base {
/**
* Create event from course_completion record.
* @param \stdClass $completion
* @return course_completed
*/
public static function create_from_completion(\stdClass $completion) {
$event = self::create(
array(
'objectid' => $completion->id,
'relateduserid' => $completion->userid,
'context' => \context_course::instance($completion->course),
'courseid' => $completion->course,
'other' => array('relateduserid' => $completion->userid), // Deprecated since 2.7, please use property relateduserid.
)
);
$event->add_record_snapshot('course_completions', $completion);
return $event;
}

/**
* Initialise required event data properties.
Expand All @@ -60,7 +85,7 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "The course with the id '$this->courseid' was completed by the user with the id '$this->userid'.";
return "The course with the id '$this->courseid' was completed for the user with the id '$this->relateduserid'.";
}

/**
Expand Down Expand Up @@ -89,4 +114,16 @@ public static function get_legacy_eventname() {
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('course_completions', $this->objectid);
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();

// TODO: MDL-45319 add validation of relateduserid and other['relateduserid'].
}
}

0 comments on commit 8b233bd

Please sign in to comment.