forked from adlnet/moodle-logstore_xapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Transform for the course module created 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\core; | ||
|
||
use src\transformer\utils as utils; | ||
|
||
/** | ||
* Transformer for course module created event. | ||
* | ||
* @param array $config The transformer config settings. | ||
* @param \stdClass $event The event to be transformed. | ||
* @return array | ||
*/ | ||
function course_module_created(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
$user = $repo->read_record_by_id('user', $event->userid); | ||
$course = $repo->read_record_by_id('course', $event->courseid); | ||
$lang = utils\get_course_lang($course); | ||
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid); | ||
|
||
return [[ | ||
'actor' => utils\get_user($config, $user), | ||
'verb' => [ | ||
'id' => 'http://activitystrea.ms/create', | ||
'display' => [ | ||
$lang => 'Created' | ||
], | ||
], | ||
'object' => utils\get_activity\course_module( | ||
$config, | ||
$course, | ||
$event->contextinstanceid | ||
), | ||
'context' => [ | ||
'extensions' => utils\extensions\base($config, $event, null), | ||
'contextActivities' => [ | ||
'parent' => [ | ||
utils\get_activity\course_section($config, $course, $coursemodule->section), | ||
utils\get_activity\course($config, $course), | ||
], | ||
'category' => [ | ||
utils\get_activity\site($config), | ||
], | ||
], | ||
] | ||
]]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...core/course_module_created/creating_new_course_module/creating_new_course_module_test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\core\course_module_created\creating_new_course_module; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
|
||
require_once($CFG->dirroot . '/admin/tool/log/store/xapi/tests/xapi_test_case.php'); | ||
|
||
/** | ||
* Unit test for course module created event. | ||
* | ||
* @package logstore_xapi | ||
* @copyright Milt Reder <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class creating_new_course_module_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 "core"; | ||
} | ||
|
||
/** | ||
* Retrieve the plugin name being tested. | ||
* | ||
* @return string | ||
*/ | ||
protected function get_plugin_name() { | ||
return "course"; | ||
} | ||
|
||
/** | ||
* Appease auto-detecting of test cases. xapi_test_case has default test cases. | ||
* | ||
* @covers ::attempt_submitted | ||
* @return void | ||
*/ | ||
public function test_init() { | ||
|
||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/core/course_module_created/creating_new_course_module/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"user": [ | ||
{ | ||
"id": 1, | ||
"firstname": "test_fullname", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"course": [ | ||
{ | ||
"id": 1, | ||
"fullname": "test_name", | ||
"lang": "en" | ||
} | ||
], | ||
"course_sections": [ | ||
{ | ||
"id": 1, | ||
"course": 1 | ||
} | ||
], | ||
"course_modules": [ | ||
{ | ||
"id": 1, | ||
"course": 1, | ||
"module": 1, | ||
"instance": 1, | ||
"section": 1 | ||
} | ||
], | ||
"modules": [ | ||
{ | ||
"id": 1, | ||
"name": "book" | ||
} | ||
], | ||
"book": [ | ||
{ | ||
"id": 1, | ||
"name": "test_book_name" | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/core/course_module_created/creating_new_course_module/event.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": 1, | ||
"objecttable": "course_modules", | ||
"timecreated": 1433946701, | ||
"objectid": 1, | ||
"courseid": 1, | ||
"eventname": "\\core\\event\\course_module_created", | ||
"userid": 1, | ||
"contextinstanceid": 1 | ||
} |
70 changes: 70 additions & 0 deletions
70
tests/core/course_module_created/creating_new_course_module/statements.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[ | ||
{ | ||
"actor": { | ||
"account": { | ||
"homePage": "http://www.example.org", | ||
"name": "1" | ||
}, | ||
"name": "test_fullname" | ||
}, | ||
"verb": { | ||
"id": "http://activitystrea.ms/create", | ||
"display": { | ||
"en": "Created" | ||
} | ||
}, | ||
"object": { | ||
"id": "http://www.example.org/mod/book/view.php?id=1", | ||
"definition": { | ||
"type": "http://id.tincanapi.com/activitytype/book", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
}, | ||
"context": { | ||
"contextActivities": { | ||
"parent": [ | ||
{ | ||
"id": "http://www.example.org/course/section.php?id=1", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { | ||
"en": "test_name Section 1" | ||
}, | ||
"type": "http://id.tincanapi.com/activitytype/section" | ||
} | ||
}, | ||
{ | ||
"id": "http://www.example.org/course/view.php?id=1", | ||
"definition": { | ||
"type": "https://w3id.org/xapi/cmi5/activitytype/course", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
} | ||
], | ||
"category": [ | ||
{ | ||
"id": "http://www.example.org", | ||
"definition": { | ||
"type": "http://id.tincanapi.com/activitytype/lms", | ||
"name": { | ||
"en": "test_name" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"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": "\\core\\event\\course_module_created", | ||
"event_function": "\\src\\transformer\\events\\core\\course_module_created" | ||
} | ||
} | ||
} | ||
} | ||
] |