Skip to content
Snippets Groups Projects
Commit 3cfa1456 authored by Frode Petterson's avatar Frode Petterson
Browse files

Reverted logging of xAPI statments

The code needs a bit more testing and tuning before it can be included.
parent 9fc13601
No related branches found
No related tags found
No related merge requests found
...@@ -251,37 +251,6 @@ switch($action) { ...@@ -251,37 +251,6 @@ switch($action) {
$file->printResult(); $file->printResult();
break; break;
case 'logxapievent':
// Trigger a Moodle log event for each xAPI statement
// that is dispatched by the H5P (hvp) object.
if (!\H5PCore::validToken('logxapievent', required_param('token', PARAM_RAW))) {
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp'));
exit;
}
$hvpid = optional_param('hvpid', null, PARAM_INT);
$courseid = optional_param('courseid', null, PARAM_INT);
$jsonxapistatement = optional_param('xapistatement', null, PARAM_RAW);
$xapistatement = json_decode($jsonxapistatement, true);
$context = \context_module::instance($hvpid);
$event = \mod_hvp\event\hvp_xapi::create(array(
'objectid' => $hvpid,
'context' => $context,
'other' => array('statement' => $xapistatement['data']['statement']),
'courseid' => $courseid
));
$event->trigger();
// Debugging...
if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
$msg = "xAPI '" . $xapistatement['data']['statement']['verb']['display']['en-US'] . "' statement dispatched";
\H5PCore::ajaxSuccess($msg);
http_response_code(200);
}
break;
/* /*
* Throw error if AJAX isnt handeled * Throw error if AJAX isnt handeled
*/ */
......
define(["jquery"],function(a){return{init:function(b){0!==b.debug&&console.log("Module hvp xAPI event dispatcher initialising"),H5P.externalDispatcher.on("xAPI",function(c){a.post(M.cfg.wwwroot+"/mod/hvp/ajax.php",{token:b.token,action:"logxapievent",hvpid:b.hvpid,courseid:b.courseid,xapistatement:JSON.stringify(c)},function(a){0!==b.debug&&console.log('Result : "'+a.data+'" status='+a.success)})})}}});
\ No newline at end of file
// Capture H5P (hvp) dispatched xAPI statement,
// And send them (ajax) to Moodle log by triggering a Moodle log event.
define(['jquery'], function ($) {
/*jshint -W117 */
return {
init: function (params) {
if (params.debug !== 0) {
console.log('Module hvp xAPI event dispatcher initialising');
}
H5P.externalDispatcher.on('xAPI', function (event) {
$.post(M.cfg.wwwroot + '/mod/hvp/ajax.php', {
'token': params.token,
'action': 'logxapievent',
'hvpid': params.hvpid,
'courseid': params.courseid,
'xapistatement': JSON.stringify(event)
}, function (data) {
if (params.debug !== 0) {
console.log('Result : "' + data.data + '" status=' + data.success);
}
});
});
}
};
});
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mod_hvp xapi statement event.
*
* @package mod_hvp
* @copyright @copyright 2016 Joubel AS <contact@joubel.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_hvp\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_hvp xapi statement event class.
*
* @package mod_hvp
* @copyright @copyright 2016 Joubel AS <contact@joubel.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class hvp_xapi extends \core\event\base
{
protected function init()
{
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'hvp';
}
/*
protected function validate_data() {
$this->data['action'] .= '_' . $this->data['other']->data->statement->verb->display->{'en-US'};
}
*/
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url()
{
return new \moodle_url('/mod/hvp/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description()
{
$verb = $this->data['other']->data->statement->verb->display->{'en-US'};
return "The user with id '$this->userid' triggered an xAPI '$verb' statement " .
"on H5P activity with instance id '$this->objectid' ";
}
}
{
"name": "moodle-mod_hvp"
}
\ No newline at end of file
...@@ -135,11 +135,6 @@ if ($embedtype === 'div') { ...@@ -135,11 +135,6 @@ if ($embedtype === 'div') {
// Print JavaScript settings to page. // Print JavaScript settings to page.
$PAGE->requires->data_for_js('H5PIntegration', $settings, true); $PAGE->requires->data_for_js('H5PIntegration', $settings, true);
// H5P JS xAPI event listener & Moodle event log dispatcher.
$jsparams = array('hvpid' => $id, 'courseid' => $course->id,
'debug' => $CFG->debug, 'token' => \H5PCore::createToken('logxapievent'));
$PAGE->requires->js_call_amd('mod_hvp/xapi-stmt-dispatcher', 'init', array($jsparams));
// Print page HTML. // Print page HTML.
echo $OUTPUT->header(); echo $OUTPUT->header();
echo '<div class="clearer"></div>'; echo '<div class="clearer"></div>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment