Skip to content

Commit b5e699f

Browse files
BrendanHalleyryasmi
authored andcommitted
feat(Totara): Adds \totara_program\event\program_assigned event. (#583 - Thanks @BrendanHalley)
1 parent 4f05469 commit b5e699f

File tree

9 files changed

+232
-5
lines changed

9 files changed

+232
-5
lines changed

classes/log/store.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ public function process_events(array $events) {
9191
$loginfo = function ($message = '') {
9292
debugging($message, DEBUG_DEVELOPER);
9393
};
94+
9495
$handlerconfig = [
9596
'log_error' => $logerror,
9697
'log_info' => $loginfo,
9798
'transformer' => [
98-
'source_url' => 'http://moodle.org',
99-
'source_name' => 'Moodle',
100-
'source_version' => $CFG->release,
10199
'source_lang' => 'en',
102100
'send_mbox' => $this->get_config('mbox', false),
103101
'send_response_choices' => $this->get_config('sendresponsechoices', false),
@@ -120,6 +118,23 @@ public function process_events(array $events) {
120118
'lrs_resend_failed_batches' => $this->get_config('resendfailedbatches', false),
121119
],
122120
];
121+
122+
if (isset($CFG->totara_release)) {
123+
$source = [
124+
'source_url' => 'http://totaralearning.com',
125+
'source_name' => 'Totara Learn',
126+
'source_version' => $CFG->totara_version
127+
];
128+
} else {
129+
$source = [
130+
'source_url' => 'http://moodle.org',
131+
'source_name' => 'Moodle',
132+
'source_version' => $CFG->release
133+
];
134+
}
135+
136+
$handlerconfig['transformer'] = array_merge($handlerconfig['transformer'], $source);
137+
123138
$loadedevents = \src\handler($handlerconfig, $events);
124139
return $loadedevents;
125140
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace src\transformer\events\totara_program;
18+
19+
defined('MOODLE_INTERNAL') || die();
20+
21+
use src\transformer\utils as utils;
22+
23+
function program_assigned(array $config, \stdClass $event) {
24+
$repo = $config['repo'];
25+
$user = $repo->read_record_by_id('user', $event->userid);
26+
$program = $repo->read_record_by_id('prog', $event->objectid);
27+
$lang = $config['source_lang'];
28+
29+
return[[
30+
'actor' => utils\get_user($config, $user),
31+
'verb' => [
32+
'id' => 'http://activitystrea.ms/schema/1.0/assign',
33+
'display' => [
34+
$lang => 'assigned'
35+
],
36+
],
37+
'object' => utils\totara\program($config, $program, $lang),
38+
'timestamp' => utils\get_event_timestamp($event),
39+
'context' => [
40+
'platform' => $config['source_name'],
41+
'language' => $lang,
42+
'extensions' => utils\extensions\base($config, $event),
43+
'contextActivities' => [
44+
'grouping' => [
45+
utils\get_activity\site($config)
46+
],
47+
'category' => [
48+
utils\get_activity\source($config)
49+
]
50+
],
51+
]
52+
]];
53+
54+
}

src/transformer/get_event_function_map.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
defined('MOODLE_INTERNAL') || die();
1919

2020
function get_event_function_map() {
21-
return [
21+
$availableevents = [
2222
'\core\event\course_completed' => 'core\course_completed',
2323
'\core\event\course_viewed' => 'core\course_viewed',
2424
'\core\event\user_created' => 'core\user_created',
@@ -63,5 +63,12 @@ function get_event_function_map() {
6363
'\mod_url\event\course_module_viewed' => 'mod_url\course_module_viewed',
6464
'\mod_wiki\event\course_module_viewed' => 'all\course_module_viewed',
6565
'\mod_workshop\event\course_module_viewed' => 'all\course_module_viewed',
66+
'\totara_program\event\program_assigned' => 'totara_program\program_assigned'
6667
];
68+
69+
$environmentevents = class_exists("report_eventlist_list_generator") ? array_keys(\report_eventlist_list_generator::get_all_events_list(false)) : array_keys($availableevents);
70+
71+
return array_filter($availableevents, function($k) use ($environmentevents) {
72+
return in_array($k, $environmentevents);
73+
}, ARRAY_FILTER_USE_KEY);
6774
}

src/transformer/utils/extensions/base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace src\transformer\utils\extensions;
1818
defined('MOODLE_INTERNAL') || die();
1919

20-
function base(array $config, \stdClass $event, $course) {
20+
function base(array $config, \stdClass $event, $course=null) {
2121
return array_merge(
2222
info($config, $event),
2323
jisc($config, $event, $course)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace src\transformer\utils\totara;
18+
defined('MOODLE_INTERNAL') || die();
19+
20+
function program(array $config, \stdClass $program, $lang) {
21+
$programname = $program->fullname ? $program->fullname : 'A Totara program';
22+
23+
$object = [
24+
'id' => $config['app_url'].'/totara/program/view.php?id='.$program->id,
25+
'definition' => [
26+
'type' => 'http://id.tincanapi.com/activitytype/lms/program',
27+
'name' => [
28+
$lang => $programname,
29+
],
30+
],
31+
];
32+
33+
return $object;
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"user": [
3+
{
4+
"id": 1,
5+
"firstname": "test_fullname",
6+
"email": "[email protected]"
7+
}
8+
],
9+
"course": [
10+
{
11+
"id": 1,
12+
"fullname": "test_name",
13+
"lang": "en"
14+
}
15+
],
16+
"prog": [
17+
{
18+
"id": 1,
19+
"fullname": "test_name"
20+
}
21+
]
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": 1,
3+
"userid": 1,
4+
"timecreated": 1560399491,
5+
"objecttable": "prog_assignment",
6+
"objectid": 1,
7+
"eventname": "\\totara_program\\event\\program_assigned"
8+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[
2+
{
3+
"actor": {
4+
"name": "test_fullname",
5+
"account": {
6+
"homePage": "http:\/\/www.example.org",
7+
"name": "1"
8+
}
9+
},
10+
"verb": {
11+
"id": "http:\/\/activitystrea.ms\/schema\/1.0\/assign",
12+
"display": {
13+
"en": "assigned"
14+
}
15+
},
16+
"object": {
17+
"id": "http:\/\/www.example.org\/totara\/program\/view.php?id=1",
18+
"definition": {
19+
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/program",
20+
"name": {
21+
"en": "test_name"
22+
}
23+
}
24+
},
25+
"timestamp": "2019-06-13T05:18:11+01:00",
26+
"context": {
27+
"platform": "Moodle",
28+
"language": "en",
29+
"extensions": {
30+
"http:\/\/lrs.learninglocker.net\/define\/extensions\/info": {
31+
"http:\/\/moodle.org": "1.0.0",
32+
"https:\/\/github.com\/xAPI-vle\/moodle-logstore_xapi": "0.0.0-development",
33+
"event_name": "\\totara_program\\event\\program_assigned",
34+
"event_function": "\\src\\transformer\\events\\totara_program\\program_assigned"
35+
}
36+
},
37+
"contextActivities": {
38+
"grouping": [
39+
{
40+
"id": "http:\/\/www.example.org",
41+
"definition": {
42+
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms",
43+
"name": {
44+
"en": "test_name"
45+
}
46+
}
47+
}
48+
],
49+
"category": [
50+
{
51+
"id": "http:\/\/moodle.org",
52+
"definition": {
53+
"type": "http:\/\/id.tincanapi.com\/activitytype\/source",
54+
"name": {
55+
"en": "Moodle"
56+
}
57+
}
58+
}
59+
]
60+
}
61+
}
62+
}
63+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace tests\totara_program\program_assigned\existing_program;
18+
defined('MOODLE_INTERNAL') || die();
19+
20+
class test extends \tests\xapi_test_case {
21+
protected function get_test_dir() {
22+
return __DIR__;
23+
}
24+
}

0 commit comments

Comments
 (0)