Skip to content

Commit

Permalink
Merge pull request #16 from talis/event-logging
Browse files Browse the repository at this point in the history
Update for Moodle 3.0
  • Loading branch information
timhodson authored Jun 15, 2016
2 parents b87aebe + a01f4cf commit e40ef24
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 12 deletions.
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ php:
- 5.6

env:
- MOODLE_BRANCH=MOODLE_28_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_26_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_27_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_28_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_29_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_29_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_30_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_30_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_26_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_27_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_28_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_29_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_30_STABLE DB=pgsql

matrix:
fast_finish: true
include:
- php: 7.0
env: MOODLE_BRANCH=MOODLE_30_STABLE DB=pgsql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace aspirelists\event;

defined('MOODLE_INTERNAL' || die);
/**
* Class aspire_lists_launch
* Provides a hook into the Moodle Event system for logging events.
* This class implements the key functions needed to provide compatibility with https://docs.moodle.org/dev/Event_2
* This class represents the event of a user launching an aspire list LTI link.
* @package aspirelists\event
*/
class aspire_lists_launch extends \core\event\base {
/** @var array */
var $legacy_log_data;

protected function init() {
$this->data['objecttable'] = 'aspirelists';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['crud'] = 'r';
}

public static function get_name() {
return get_string('eventAspireLaunch', 'aspirelists');
}

public function get_description() {
return "The user with id {$this->userid} Launched an LTI link with id {$this->objectid}.";
}

public function get_legacy_logdata() {
return $this->legacy_log_data;
}

/**
* easily set our old add_to_log data
* @param array $data
*/
public function set_legacy_logdata(array $data) {
$this->legacy_log_data = $data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace aspirelists\event;
defined('MOODLE_INTERNAL' || die);

/**
* Class course_module_viewed
* This provides an extension to the core course_module_viewed event to easily set legacy log data.
* @package aspirelists\event
*/
class course_module_viewed extends \core\event\course_module_viewed {
/** @var array */
var $legacy_log_data;

protected function init() {
$this->data['objecttable'] = 'aspirelists';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['crud'] = 'r';
parent::init();
}

public function get_legacy_logdata() {
return $this->legacy_log_data;
}

/**
* easily set our old add_to_log data
* @param array $data
*/
public function set_legacy_logdata(array $data) {
$this->legacy_log_data = $data;
}
}
4 changes: 4 additions & 0 deletions 2.x-activity-module/mod/aspirelists/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@ function xmldb_aspirelists_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2016051100, 'aspirelists');
}

if ($oldversion < 2016061400){
upgrade_mod_savepoint(true, 2016061400, 'aspirelists');
}

}
2 changes: 2 additions & 0 deletions 2.x-activity-module/mod/aspirelists/lang/en/aspirelists.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
$string['modulename'] = 'Course Resource List';
$string['pluginname'] = 'Course Resource List';

$string['eventAspireLaunch'] = 'Talis Aspire Launch Event';

$string['pluginadministration'] = 'Course resource list administration';


Expand Down
18 changes: 16 additions & 2 deletions 2.x-activity-module/mod/aspirelists/launch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_once($CFG->dirroot.'/mod/aspirelists/lib.php');
require_once($CFG->dirroot.'/mod/lti/lib.php');
require_once($CFG->dirroot.'/mod/lti/locallib.php');
require_once($CFG->dirroot.'/mod/aspirelists/classes/event/aspirelists_launch.php');

// make sure that this launch.php page is not cached by any proxies.
header("Cache-Control: no-cache, must-revalidate");
Expand All @@ -15,8 +16,21 @@
$cm = get_coursemodule_from_id('aspirelists', $id, 0, false, MUST_EXIST);
$list = $DB->get_record('aspirelists', array('id' => $cm->instance), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$context = context_module::instance($cm->id);

add_to_log($course->id, "aspirelists", "launch", "launch.php?id=$cm->id", "$list->id");
if($CFG->version < 2014051200) {
add_to_log($course->id, "aspirelists", "launch", "launch.php?id=$cm->id", "$list->id");
} else {
$event = \aspirelists\event\aspire_lists_launch::create(
array(
'objectid' => $cm->instance,
'context' => $context,
'other' => $list->id
)
);
$event->set_legacy_logdata(array($course->id, "aspirelists", "launch", "launch.php?id=$cm->id", "$list->id"));
$event->trigger();
}

$list->cmid = $cm->id;
aspirelists_add_lti_properties($list);
Expand All @@ -27,4 +41,4 @@
else{
// Moodle 1.x/2.x
lti_view($list);
}
}
11 changes: 7 additions & 4 deletions 2.x-activity-module/mod/aspirelists/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ function aspirelists_add_lti_properties(&$aspirelist)
$aspirelist->instructorchoiceacceptgrades = false;
$aspirelist->instructorchoicesendname = false;
$aspirelist->instructorchoicesendemailaddr = false;
if($CFG->version >= 2015051100 ) { // greater or in Moodle 2.9.
$aspirelist->instructorchoiceallowroster = false;
}
$aspirelist->launchcontainer = null;
$aspirelist->servicesalt = uniqid('', true);
if(function_exists('get_course'))
Expand Down Expand Up @@ -161,11 +164,11 @@ function aspirelists_add_lti_properties(&$aspirelist)
*/
function aspirelists_cm_info_view(cm_info $cm) {
global $CFG,$PAGE;
if ($cm->uservisible && $cm->get_custom_data()) {
if ($cm->uservisible && $cm->customdata) {
// Restore folder object from customdata.
// Note the field 'customdata' is not empty IF AND ONLY IF we display contens inline.
// Otherwise the content is default.
$aspirelist = $cm->get_custom_data();
$aspirelist = $cm->customdata;
$aspirelist->id = (int)$cm->instance;
$aspirelist->course = (int)$cm->course;
$aspirelist->display = ASPIRELISTS_DISPLAY_INLINE;
Expand Down Expand Up @@ -195,11 +198,11 @@ function aspirelists_cm_info_view(cm_info $cm) {
*/
function aspirelists_cm_info_dynamic(cm_info $cm) {
global $CFG;
if ($cm->get_custom_data()) {
if ($cm->customdata) {
// the field 'customdata' is not empty IF AND ONLY IF we display contens inline
require_once($CFG->dirroot . '/mod/aspirelists/load_js.php');
$cm->set_extra_classes('aspirelists_inline_readings_toggle');
$aspirelist = $cm->get_custom_data();
$aspirelist = $cm->customdata;
if(isset($aspirelist->showexpanded) && $aspirelist->showexpanded === '1')
{
$afterLink = get_string('accordion_open', 'aspirelists');
Expand Down
8 changes: 7 additions & 1 deletion 2.x-activity-module/mod/aspirelists/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ function definition() {
$mform->setDefault('name', get_string('default_section_title', 'aspirelists'));
$mform->addRule('name', null, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$this->add_intro_editor(false);

if($CFG->version >= 2015111600 ) { // greater or in Moodle 3.0.
$this->standard_intro_elements(false);
} else {
$this->add_intro_editor(false);
}

$mform->setAdvanced('introeditor');

// Display the label to the right of the checkbox so it looks better & matches rest of the form
Expand Down
3 changes: 2 additions & 1 deletion 2.x-activity-module/mod/aspirelists/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$plugin = new stdClass();
}

$plugin->version = 2016051100; // Version for this plugin - based on the date and then an increment number
$plugin->version = 2016061400; // Version for this plugin - based on the date and then an increment number
$plugin->requires = 2012062507; // See http://docs.moodle.org/dev/Moodle_Versions
$plugin->cron = 0;
$plugin->component = 'mod_aspirelists';
Expand All @@ -26,3 +26,4 @@
$module->component = $plugin->component;
}
}

12 changes: 11 additions & 1 deletion 2.x-activity-module/mod/aspirelists/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
require_once($CFG->dirroot.'/mod/lti/lib.php');
require_once($CFG->dirroot.'/mod/lti/locallib.php');
require_once($CFG->dirroot . '/lib/completionlib.php');
require_once($CFG->dirroot.'/mod/aspirelists/classes/event/course_module_viewed.php');

$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$l = optional_param('l', 0, PARAM_INT); // aspirelists ID
Expand Down Expand Up @@ -90,7 +91,16 @@
$completion = new completion_info($course);
$completion->set_module_viewed($cm);

add_to_log($course->id, "aspirelists", "view", "view.php?id=$cm->id", "$list->id");
$event = \aspirelists\event\course_module_viewed::create(
array(
'objectid' => $PAGE->cm->instance,
'context' => $context,
'other' => $list->id
)
);
$event->add_record_snapshot('course', $PAGE->course);
$event->set_legacy_logdata(array($course->id, "aspirelists", "view", "view.php?id=$cm->id", "$list->id"));
$event->trigger();

$pagetitle = strip_tags($course->shortname.': '.format_string($list->name));
$PAGE->set_title($pagetitle);
Expand Down

0 comments on commit e40ef24

Please sign in to comment.