Skip to content

Commit

Permalink
tool usertours (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
milt authored Nov 20, 2024
1 parent 44cc2c1 commit 9a4570d
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 2 deletions.
63 changes: 63 additions & 0 deletions src/transformer/events/tool_usertours/tour_ended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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/>.

/**
* Transformer for tour ended event.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace src\transformer\events\tool_usertours;

use src\transformer\utils as utils;

/**
* Transformer for tour ended event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/
function tour_ended(array $config, \stdClass $event) {
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->userid);
$lang = $config['source_lang'];

return [[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'https://xapi.edlm/profiles/edlm-lms/concepts/verbs/toured',
'display' => [
'en' => 'Toured'
],
],
'object' => [
'id' => unserialize($event->other)['pageurl'],
'objectType' => 'Activity',
],
'context' => [
'language' => $lang,
'extensions' => utils\extensions\base($config, $event, null),
'contextActivities' => [
'category' => [
utils\get_activity\site($config),
],
],
],
]];
}
4 changes: 2 additions & 2 deletions src/transformer/get_event_function_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ function get_event_function_map() {
'\mod_url\event\course_module_viewed' => 'all\course_module_viewed',
'\mod_wiki\event\course_module_viewed' => 'all\course_module_viewed',
'\mod_workshop\event\course_module_viewed' => 'all\course_module_viewed',
'\totara_program\event\program_assigned' => 'totara_program\program_assigned'

'\totara_program\event\program_assigned' => 'totara_program\program_assigned',
'\tool_usertours\event\tour_ended' => 'tool_usertours\tour_ended'
];

$environmentevents = class_exists("report_eventlist_list_generator") ?
Expand Down
1 change: 1 addition & 0 deletions tests/tool_usertours/tour_ended/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions tests/tool_usertours/tour_ended/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": 1,
"userid": 1,
"timecreated": 1433946701,
"courseid": 1,
"contextinstanceid": 1,
"eventname": "\\tool_usertours\\event\\tour_ended",
"other": "a:3:{s:7:\"pageurl\";s:42:\"http://localhost:8000/course/view.php?id=1\";s:6:\"stepid\";i:7;s:9:\"stepindex\";i:2;}"
}
45 changes: 45 additions & 0 deletions tests/tool_usertours/tour_ended/statements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"actor": {
"name": "test_fullname",
"account": {
"homePage": "http://www.example.org",
"name": "1"
}
},
"verb": {
"id": "https://xapi.edlm/profiles/edlm-lms/concepts/verbs/toured",
"display": {
"en": "Toured"
}
,
"object": {
"id": "http://www.example.org/course/view.php?id=1",
"objectType": "Activity"
},
"context": {
"language": "en",
"extensions": {
"http://lrs.learninglocker.net/define/extensions/info": {
"http://moodle.org": "1.0.0",
"https://github.com/xAPI-vle/moodle-logstore_xapi": "0.0.0-development",
"event_name": "\\tool_usertours\\event\\tour_ended",
"event_function": "\\src\\transformer\\events\\tool_usertours\\tour_ended"
}
},
"contextActivities": {
"category": [
{
"id": "http://www.example.org",
"definition": {
"type": "http://id.tincanapi.com/activitytype/lms",
"name": {
"en": "test_name"
}
}
}
]
}
}
}
]
70 changes: 70 additions & 0 deletions tests/tool_usertours/tour_ended/tour_ended_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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/>.

namespace logstore_xapi\tool_usertours;

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->dirroot . '/admin/tool/log/store/xapi/tests/xapi_test_case.php');

/**
* Unit test for tool_usertours tour_ended event.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tour_ended_test extends \logstore_xapi\xapi_test_case {

/**
* Retrieve the directory of the unit test.
*
* @return string
*/
protected function get_test_dir() {
return __DIR__;
}

/**
* Retrieve the plugin type being tested.
*
* @return string
*/
protected function get_plugin_type() {
return "mod";
}

/**
* Retrieve the plugin name being tested.
*
* @return string
*/
protected function get_plugin_name() {
return "tool_usertours";
}

/**
* Appease auto-detecting of test cases. xapi_test_case has default test cases.
*
* @covers ::tour_ended
* @return void
*/
public function test_init() {

}
}

0 comments on commit 9a4570d

Please sign in to comment.