Merge branch 'w19_MDL-43557_m27_cleanup' of git://github.com/skodak/moodle

This commit is contained in:
Marina Glancy
2014-04-30 15:12:56 +08:00
6 changed files with 43 additions and 15 deletions
+1 -11
View File
@@ -161,17 +161,7 @@ class completion_completion extends data_object {
// 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;
+1 -1
View File
@@ -1813,7 +1813,7 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals($course->id, $event->courseid);
$this->assertEquals($coursecontext->id, $event->contextid);
$this->assertEquals($section->section, $event->other['sectionnum']);
$expecteddesc = 'Course ' . $event->courseid . ' section ' . $event->other['sectionnum'] . ' updated by user ' . $event->userid;
$expecteddesc = "The user with the id '{$event->userid}' updated the section with the number '{$event->other['sectionnum']}' for the course with the id '{$event->courseid}'";
$this->assertEquals($expecteddesc, $event->get_description());
$url = new moodle_url('/course/editsection.php', array('id' => $event->objectid));
$this->assertEquals($url, $event->get_url());
+38 -1
View File
@@ -29,12 +29,37 @@ defined('MOODLE_INTERNAL') || die();
/**
* 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.
@@ -60,7 +85,7 @@ class course_completed extends base {
* @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'.";
}
/**
@@ -89,4 +114,16 @@ class course_completed extends base {
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'].
}
}
@@ -59,7 +59,7 @@ class attempt_becameoverdue extends \core\event\base {
* @return string
*/
public function get_description() {
return "Attempt with the id '$this->objectid' for the user with the id '$this->relateduserid' became overdue.";
}
/**
+1
View File
@@ -138,6 +138,7 @@ class mod_quiz_events_testcase extends advanced_testcase {
$this->assertEquals('quiz_attempts', $event->objecttable);
$this->assertEquals($quizobj->get_context(), $event->get_context());
$this->assertEquals($attempt->userid, $event->relateduserid);
$this->assertNotEmpty($event->get_description());
// Submitterid should be the user, but as we are in PHP Unit, CLI_SCRIPT is set to true which sets null in submitterid.
$this->assertEquals(null, $event->other['submitterid']);
$this->assertEquals('quiz_attempt_overdue', $event->get_legacy_eventname());
+1 -1
View File
@@ -189,7 +189,7 @@ if (is_null($assessment->grade) and !$assessmenteditable) {
if (count((array)$coredata) > 1 ) {
$DB->update_record('workshop_assessments', $coredata);
$params = array(
'relateduserid' => $assessment->authorid,
'relateduserid' => $submission->authorid,
'objectid' => $assessment->id,
'context' => $workshop->context,
'other' => array(