Skip to content

Commit

Permalink
feat(Totara): Adds \totara_program\event\program_assigned event. (#583
Browse files Browse the repository at this point in the history
 - Thanks @BrendanHalley)
  • Loading branch information
BrendanHalley authored and ryasmi committed Jun 18, 2019
1 parent 4f05469 commit b5e699f
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 5 deletions.
21 changes: 18 additions & 3 deletions classes/log/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ public function process_events(array $events) {
$loginfo = function ($message = '') {
debugging($message, DEBUG_DEVELOPER);
};

$handlerconfig = [
'log_error' => $logerror,
'log_info' => $loginfo,
'transformer' => [
'source_url' => 'http://moodle.org',
'source_name' => 'Moodle',
'source_version' => $CFG->release,
'source_lang' => 'en',
'send_mbox' => $this->get_config('mbox', false),
'send_response_choices' => $this->get_config('sendresponsechoices', false),
Expand All @@ -120,6 +118,23 @@ public function process_events(array $events) {
'lrs_resend_failed_batches' => $this->get_config('resendfailedbatches', false),
],
];

if (isset($CFG->totara_release)) {
$source = [
'source_url' => 'http://totaralearning.com',
'source_name' => 'Totara Learn',
'source_version' => $CFG->totara_version
];
} else {
$source = [
'source_url' => 'http://moodle.org',
'source_name' => 'Moodle',
'source_version' => $CFG->release
];
}

$handlerconfig['transformer'] = array_merge($handlerconfig['transformer'], $source);

$loadedevents = \src\handler($handlerconfig, $events);
return $loadedevents;
}
Expand Down
54 changes: 54 additions & 0 deletions src/transformer/events/totara_program/program_assigned.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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 src\transformer\events\totara_program;

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

use src\transformer\utils as utils;

function program_assigned(array $config, \stdClass $event) {
$repo = $config['repo'];
$user = $repo->read_record_by_id('user', $event->userid);
$program = $repo->read_record_by_id('prog', $event->objectid);
$lang = $config['source_lang'];

return[[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://activitystrea.ms/schema/1.0/assign',
'display' => [
$lang => 'assigned'
],
],
'object' => utils\totara\program($config, $program, $lang),
'timestamp' => utils\get_event_timestamp($event),
'context' => [
'platform' => $config['source_name'],
'language' => $lang,
'extensions' => utils\extensions\base($config, $event),
'contextActivities' => [
'grouping' => [
utils\get_activity\site($config)
],
'category' => [
utils\get_activity\source($config)
]
],
]
]];

}
9 changes: 8 additions & 1 deletion src/transformer/get_event_function_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
defined('MOODLE_INTERNAL') || die();

function get_event_function_map() {
return [
$availableevents = [
'\core\event\course_completed' => 'core\course_completed',
'\core\event\course_viewed' => 'core\course_viewed',
'\core\event\user_created' => 'core\user_created',
Expand Down Expand Up @@ -63,5 +63,12 @@ function get_event_function_map() {
'\mod_url\event\course_module_viewed' => 'mod_url\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'
];

$environmentevents = class_exists("report_eventlist_list_generator") ? array_keys(\report_eventlist_list_generator::get_all_events_list(false)) : array_keys($availableevents);

return array_filter($availableevents, function($k) use ($environmentevents) {
return in_array($k, $environmentevents);
}, ARRAY_FILTER_USE_KEY);
}
2 changes: 1 addition & 1 deletion src/transformer/utils/extensions/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace src\transformer\utils\extensions;
defined('MOODLE_INTERNAL') || die();

function base(array $config, \stdClass $event, $course) {
function base(array $config, \stdClass $event, $course=null) {
return array_merge(
info($config, $event),
jisc($config, $event, $course)
Expand Down
34 changes: 34 additions & 0 deletions src/transformer/utils/totara/program.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 src\transformer\utils\totara;
defined('MOODLE_INTERNAL') || die();

function program(array $config, \stdClass $program, $lang) {
$programname = $program->fullname ? $program->fullname : 'A Totara program';

$object = [
'id' => $config['app_url'].'/totara/program/view.php?id='.$program->id,
'definition' => [
'type' => 'http://id.tincanapi.com/activitytype/lms/program',
'name' => [
$lang => $programname,
],
],
];

return $object;
}
22 changes: 22 additions & 0 deletions tests/totara_program/program_assigned/existing_program/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"user": [
{
"id": 1,
"firstname": "test_fullname",
"email": "[email protected]"
}
],
"course": [
{
"id": 1,
"fullname": "test_name",
"lang": "en"
}
],
"prog": [
{
"id": 1,
"fullname": "test_name"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": 1,
"userid": 1,
"timecreated": 1560399491,
"objecttable": "prog_assignment",
"objectid": 1,
"eventname": "\\totara_program\\event\\program_assigned"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
{
"actor": {
"name": "test_fullname",
"account": {
"homePage": "http:\/\/www.example.org",
"name": "1"
}
},
"verb": {
"id": "http:\/\/activitystrea.ms\/schema\/1.0\/assign",
"display": {
"en": "assigned"
}
},
"object": {
"id": "http:\/\/www.example.org\/totara\/program\/view.php?id=1",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/program",
"name": {
"en": "test_name"
}
}
},
"timestamp": "2019-06-13T05:18:11+01:00",
"context": {
"platform": "Moodle",
"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": "\\totara_program\\event\\program_assigned",
"event_function": "\\src\\transformer\\events\\totara_program\\program_assigned"
}
},
"contextActivities": {
"grouping": [
{
"id": "http:\/\/www.example.org",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms",
"name": {
"en": "test_name"
}
}
}
],
"category": [
{
"id": "http:\/\/moodle.org",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/source",
"name": {
"en": "Moodle"
}
}
}
]
}
}
}
]
24 changes: 24 additions & 0 deletions tests/totara_program/program_assigned/existing_program/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 tests\totara_program\program_assigned\existing_program;
defined('MOODLE_INTERNAL') || die();

class test extends \tests\xapi_test_case {
protected function get_test_dir() {
return __DIR__;
}
}

0 comments on commit b5e699f

Please sign in to comment.