Skip to content
Snippets Groups Projects
Commit e44cdd7d authored by Andrew Downes's avatar Andrew Downes Committed by Ryan Smith
Browse files

feat: Adds statement for `\mod_book\event\chapter_viewed`. (#370 - Thanks @garemoko)

parent 29ae19b2
No related branches found
No related tags found
No related merge requests found
<?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\mod_book;
defined('MOODLE_INTERNAL') || die();
use src\transformer\utils as utils;
function chapter_viewed(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);
$chapter = $repo->read_record_by_id('book_chapters', $event->objectid);
$lang = utils\get_course_lang($course);
$statement = [
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://id.tincanapi.com/verb/viewed',
'display' => [
$lang => 'viewed'
]
],
'object' => utils\get_activity\book_chapter($config, $course, $chapter, $event->contextinstanceid),
'timestamp' => utils\get_event_timestamp($event),
'context' => [
'platform' => $config['source_name'],
'language' => $lang,
'extensions' => [
utils\INFO_EXTENSION => utils\get_info($config, $event),
],
'contextActivities' => [
'grouping' => [
utils\get_activity\site($config),
utils\get_activity\course($config, $course),
utils\get_activity\course_module(
$config,
$course,
$event->contextinstanceid,
'http://id.tincanapi.com/activitytype/book'
)
],
'category' => [
utils\get_activity\source($config),
]
]
]
];
if ($chapter->subchapter !== 0) {
$parentchapter = $repo->read_record_by_id('book_chapters', $chapter->subchapter);
$statement['context']['contextActivities']['parent'] = [
utils\get_activity\book_chapter($config, $course, $parentchapter, $event->contextinstanceid)
];
}
return [$statement];
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ function get_event_function_map() {
'\mod_assign\event\assessable_submitted' => 'mod_assign\assignment_submitted',
'\mod_assign\event\submission_graded' => 'mod_assign\assignment_graded',
'\mod_book\event\course_module_viewed' => 'mod_book\course_module_viewed',
'\mod_book\event\chapter_viewed' => 'mod_book\chapter_viewed',
'\mod_chat\event\course_module_viewed' => 'mod_chat\course_module_viewed',
'\mod_choice\event\course_module_viewed' => 'all\course_module_viewed',
'\mod_data\event\course_module_viewed' => 'all\course_module_viewed',
......
<?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\get_activity;
defined('MOODLE_INTERNAL') || die();
use src\transformer\utils as utils;
function book_chapter(array $config, \stdClass $course, \stdClass $chapter, $cmid) {
$courselang = utils\get_course_lang($course);
$url = $config['app_url'].'/mod/book/view.php?id=' . $cmid . '&chapterid=' . $chapter->id;
$definition = [
'type' => 'http://id.tincanapi.com/activitytype/chapter'
];
if (property_exists($chapter, 'title')) {
$definition['name'] = [];
$definition['name'][$courselang] = $chapter->title;
}
if (property_exists($chapter, 'content')) {
$definition['description'] = [
$courselang => utils\get_string_html_removed($chapter->content)
];
}
return [
'id' => $url,
'definition' => $definition
];
}
{
"user": [
{
"id": 1,
"firstname": "test_fullname",
"email": "test@test.com"
}
],
"course": [
{
"id": 1,
"fullname": "test_name",
"lang": "en"
}
],
"course_modules": [
{
"id": 1,
"course": 1,
"module": 1,
"instance": 1
}
],
"modules": [
{
"id": 1,
"name": "book"
}
],
"book": [
{
"id": 1,
"name": "test_book_name"
}
],
"book_chapters": [
{
"id": 1,
"bookid": 1,
"pagenum": 1,
"subchapter": 0,
"title": "test_parent_name",
"content": "<p>test_parent_content</p>"
},
{
"id": 2,
"bookid": 1,
"pagenum": 2,
"subchapter": 1,
"title": "test_book_chapter_title",
"content": "<p>test_book_chapter_content</p>"
}
]
}
\ No newline at end of file
{
"id": 1,
"userid": 1,
"courseid": 1,
"timecreated": 1433946701,
"objecttable": "book_chapters",
"objectid": 2,
"contextinstanceid": 1,
"eventname": "\\mod_book\\event\\chapter_viewed"
}
\ No newline at end of file
[
{
"actor": {
"name": "test_fullname",
"account": {
"homePage": "http:\/\/www.example.org",
"name": "1"
}
},
"verb": {
"id": "http:\/\/id.tincanapi.com\/verb\/viewed",
"display": {
"en": "viewed"
}
},
"object": {
"id": "http:\/\/www.example.org\/mod\/book\/view.php?id=1&chapterid=2",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/chapter",
"name": {
"en": "test_book_chapter_title"
},
"description": {
"en": "test_book_chapter_content"
}
}
},
"timestamp": "2015-06-10T15:31:41+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": "\\mod_book\\event\\chapter_viewed",
"event_function": "\\src\\transformer\\events\\mod_book\\chapter_viewed"
}
},
"contextActivities": {
"grouping": [
{
"id": "http:\/\/www.example.org",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms",
"name": {
"en": "test_name"
}
}
},
{
"id": "http:\/\/www.example.org\/course\/view.php?id=1",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/lms\/course",
"name": {
"en": "test_name"
}
}
},
{
"id": "http:\/\/www.example.org\/mod\/book\/view.php?id=1",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/book",
"name": {
"en": "test_book_name"
}
}
}
],
"category": [
{
"id": "http:\/\/moodle.org",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/source",
"name": {
"en": "Moodle"
}
}
}
],
"parent": [
{
"id": "http:\/\/www.example.org\/mod\/book\/view.php?id=1&chapterid=1",
"definition": {
"type": "http:\/\/id.tincanapi.com\/activitytype\/chapter",
"name": {
"en": "test_parent_name"
},
"description": {
"en": "test_parent_content"
}
}
}
]
}
}
}
]
\ No newline at end of file
<?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\mod_book\chapter_viewed\existing_module;
defined('MOODLE_INTERNAL') || die();
class test extends \tests\xapi_test_case {
protected function get_test_dir() {
return __DIR__;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment