MDL-33606 course: Adding section info to course_viewed log
Also changing references to section id to section number, that it is what it really is.
This commit is contained in:
+1
-1
@@ -288,7 +288,7 @@
|
||||
// anything after that point.
|
||||
$eventdata = array('context' => context_course::instance($course->id));
|
||||
if (!empty($section) && (int)$section == $section) {
|
||||
$eventdata['other'] = array('coursesectionid' => $section);
|
||||
$eventdata['other'] = array('coursesectionnumber' => $section);
|
||||
}
|
||||
$event = \core\event\course_viewed::create($eventdata);
|
||||
$event->trigger();
|
||||
|
||||
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @property-read array $other {
|
||||
* Extra information about the event.
|
||||
*
|
||||
* - int coursesectionid: (optional) The course section ID.
|
||||
* - int coursesectionnumber: (optional) The course section number.
|
||||
* }
|
||||
*
|
||||
* @package core
|
||||
@@ -59,7 +59,17 @@ class course_viewed extends base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the course with id '$this->courseid'.";
|
||||
|
||||
// We keep compatibility with 2.7 and 2.8 other['coursesectionid'].
|
||||
$sectionstr = '';
|
||||
if (!empty($this->other['coursesectionnumber'])) {
|
||||
$sectionstr = "section number '{$this->other['coursesectionnumber']}' of the ";
|
||||
} else if (!empty($this->other['coursesectionid'])) {
|
||||
$sectionstr = "section number '{$this->other['coursesectionid']}' of the ";
|
||||
}
|
||||
$description = "The user with id '$this->userid' viewed the " . $sectionstr . "course with id '$this->courseid'.";
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,13 +88,17 @@ class course_viewed extends base {
|
||||
*/
|
||||
public function get_url() {
|
||||
global $CFG;
|
||||
$sectionid = null;
|
||||
if (isset($this->other['coursesectionid'])) {
|
||||
$sectionid = $this->other['coursesectionid'];
|
||||
|
||||
// We keep compatibility with 2.7 and 2.8 other['coursesectionid'].
|
||||
$sectionnumber = null;
|
||||
if (isset($this->other['coursesectionnumber'])) {
|
||||
$sectionnumber = $this->other['coursesectionnumber'];
|
||||
} else if (isset($this->other['coursesectionid'])) {
|
||||
$sectionnumber = $this->other['coursesectionid'];
|
||||
}
|
||||
require_once($CFG->dirroot . '/course/lib.php');
|
||||
try {
|
||||
return course_get_url($this->courseid, $sectionid);
|
||||
return course_get_url($this->courseid, $sectionnumber);
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
@@ -101,9 +115,15 @@ class course_viewed extends base {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($this->other['coursesectionid'])) {
|
||||
return array($this->courseid, 'course', 'view section', 'view.php?id=' . $this->courseid . '&sectionid='
|
||||
. $this->other['coursesectionid'], $this->other['coursesectionid']);
|
||||
// We keep compatibility with 2.7 and 2.8 other['coursesectionid'].
|
||||
if (isset($this->other['coursesectionnumber']) || isset($this->other['coursesectionid'])) {
|
||||
if (isset($this->other['coursesectionnumber'])) {
|
||||
$sectionnumber = $this->other['coursesectionnumber'];
|
||||
} else {
|
||||
$sectionnumber = $this->other['coursesectionid'];
|
||||
}
|
||||
return array($this->courseid, 'course', 'view section', 'view.php?id=' . $this->courseid . '&section='
|
||||
. $sectionnumber, $sectionnumber);
|
||||
}
|
||||
return array($this->courseid, 'course', 'view', 'view.php?id=' . $this->courseid, $this->courseid);
|
||||
}
|
||||
|
||||
@@ -238,10 +238,10 @@ class core_events_testcase extends advanced_testcase {
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
// Now try with optional parameters.
|
||||
$sectionid = 34;
|
||||
$sectionnumber = 7;
|
||||
$eventparams = array();
|
||||
$eventparams['context'] = $context;
|
||||
$eventparams['other'] = array('coursesectionid' => $sectionid);
|
||||
$eventparams['other'] = array('coursesectionnumber' => $sectionnumber);
|
||||
$event = \core\event\course_viewed::create($eventparams);
|
||||
|
||||
// Trigger and capture the event.
|
||||
@@ -254,8 +254,8 @@ class core_events_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertInstanceOf('\core\event\course_viewed', $event);
|
||||
$this->assertEquals(context_course::instance($course->id), $event->get_context());
|
||||
$expected = array($course->id, 'course', 'view section', 'view.php?id=' . $course->id . '&sectionid='
|
||||
. $sectionid, $sectionid);
|
||||
$expected = array($course->id, 'course', 'view section', 'view.php?id=' . $course->id . '&section='
|
||||
. $sectionnumber, $sectionnumber);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ information provided here is intended especially for developers.
|
||||
additional string parameters.
|
||||
* User settings node and course node in navigation now support callbacks from admin tools.
|
||||
* grade_get_grades() optional parameteres $itemtype, $itemmodule, $iteminstance are now required.
|
||||
* \core\event\course_viewed 'other' argument changes from coursesectionid to coursesectionnumber as it contains the section number.
|
||||
|
||||
DEPRECATIONS:
|
||||
* completion_info->get_incomplete_criteria() is deprecated and will be removed in Moodle 3.0.
|
||||
|
||||
Reference in New Issue
Block a user