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.
* notes * pr feedback * note-object * note_object util fn * remove double * fix phpdoc * moved course note to get_activity ns * style and convention * a little more style --------- Co-authored-by: Milton Reder <[email protected]>
- Loading branch information
1 parent
fe77291
commit fdfa74c
Showing
17 changed files
with
825 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,75 @@ | ||
<?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 fn for note_created event | ||
* | ||
* @package logstore_xapi | ||
* @copyright Daniel Bell <[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; | ||
use src\transformer\utils\get_activity as activity; | ||
|
||
/** | ||
* Transformer fn for note_created event | ||
* | ||
* @param array $config The transformer config settings. | ||
* @param \stdClass $event The event to be transformed. | ||
* @return array | ||
*/ | ||
|
||
function note_created(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
$note = $repo->read_record_by_id('post', $event->objectid); | ||
$actor = $repo->read_record_by_id('user', $event->userid); | ||
$subject = $repo->read_record_by_id('user', $event->relateduserid); | ||
$course = (isset($event->courseid) && $event->courseid != 0) | ||
? $repo->read_record_by_id('course', $event->courseid) | ||
: null; | ||
$lang = is_null($course) | ||
? $config['source_lang'] | ||
: utils\get_course_lang($course); | ||
|
||
$statement = [ | ||
'actor' => utils\get_user($config,$actor), | ||
'verb' => [ | ||
'id' => 'http://activitystrea.ms/create', | ||
'display' => [ | ||
'en' => 'Created' | ||
] | ||
], | ||
'object' => activity\course_note($config, $lang, $subject, $note), | ||
'context' => [ | ||
'language' => $lang, | ||
'contextActivities' => [ | ||
'category' => [ | ||
activity\site($config) | ||
], | ||
], | ||
'extensions' => utils\extensions\base($config, $event, $course) | ||
]]; | ||
|
||
if ($course){ | ||
$statement = utils\add_parent($config, $statement, $course); | ||
} | ||
|
||
return [$statement]; | ||
} |
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,74 @@ | ||
<?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 fn for note_updated event | ||
* | ||
* @package logstore_xapi | ||
* @copyright Daniel Bell <[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; | ||
use src\transformer\utils\get_activity as activity; | ||
|
||
/** | ||
* Transformer fn for note_updated event | ||
* | ||
* @param array $config The transformer config settings. | ||
* @param \stdClass $event The event to be transformed. | ||
* @return array | ||
*/ | ||
|
||
function note_updated(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
$note = $repo->read_record_by_id('post', $event->objectid); | ||
$user = $repo->read_record_by_id('user', $event->userid); | ||
$subject = $repo->read_record_by_id('user', $event->relateduserid); | ||
$course = (isset($event->courseid) && $event->courseid != 0) | ||
? $repo->read_record_by_id('course', $event->courseid) | ||
: null; | ||
$lang = is_null($course) | ||
? $config['source_lang'] | ||
: utils\get_course_lang($course); | ||
|
||
$statement = [ | ||
'actor' => utils\get_user($config, $user), | ||
'verb' => ['id' => 'http://activitystrea.ms/update', | ||
'display' => [ | ||
'en' => 'Updated' | ||
] | ||
], | ||
'object' => activity\course_note($config, $lang, $subject, $note), | ||
'context' => [ | ||
'language' => $lang, | ||
'contextActivities' => [ | ||
'category' => [ | ||
activity\site($config) | ||
], | ||
], | ||
'extensions' => utils\extensions\base($config, $event, $course) | ||
]]; | ||
|
||
if ($course){ | ||
$statement = utils\add_parent($config, $statement, $course); | ||
} | ||
|
||
return [$statement]; | ||
} |
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,94 @@ | ||
<?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 fn for notess_viewed event | ||
* | ||
* @package logstore_xapi | ||
* @copyright Daniel Bell <[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; | ||
use src\transformer\utils\get_activity as activity; | ||
|
||
/** | ||
* Transformer fn for notess_viewed event | ||
* | ||
* @param array $config The transformer config settings. | ||
* @param \stdClass $event The event to be transformed. | ||
* @return array | ||
*/ | ||
|
||
function notes_viewed(array $config, \stdClass $event) { | ||
$repo = $config['repo']; | ||
|
||
//all three here may not exist | ||
$user=$repo->read_record_by_id('user', $event->userid); | ||
$subject=$repo->read_record_by_id('user', $event->relateduserid); | ||
$course = (isset($event->courseid) && $event->courseid != 0) | ||
? $repo->read_record_by_id('course', $event->courseid) | ||
: null; | ||
$lang = is_null($course) | ||
? $config['source_lang'] | ||
: utils\get_course_lang($course); | ||
|
||
$statement = [ | ||
'actor' => utils\get_user($config,$user), | ||
'verb' => ['id' => 'http://id.tincanapi.com/verb/viewed', | ||
'display' => [ | ||
'en' => 'Viewed' | ||
] | ||
], | ||
'object' => [ | ||
'id' => $config['app_url'].'/notes/index.php', | ||
'definition' => [ | ||
'name' => [ | ||
$lang => 'Notes' | ||
], | ||
'type' => 'https://w3id.org/xapi/acrossx/activities/webpage', | ||
'extensions' => [ | ||
"https://xapi.edlm/profiles/edlm-lms/concepts/activity-extensions/note-subject" | ||
=> utils\get_user($config,$subject) | ||
] | ||
], | ||
], | ||
'context' => [ | ||
'language' => $lang, | ||
'contextActivities' => [ | ||
'category' => [ | ||
activity\site($config) | ||
], | ||
], | ||
'extensions' => | ||
array_merge( | ||
utils\extensions\base($config, $event, $course), | ||
[ | ||
'https://xapi.edlm/profiles/edlm-lms/concepts/context-extensions/note-subject-scope' | ||
=> utils\get_user($config, $subject)]) | ||
|
||
] | ||
]; | ||
|
||
if ($course){ | ||
$statement = utils\add_parent($config,$statement,$course); | ||
} | ||
|
||
return [$statement]; | ||
} |
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
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,52 @@ | ||
<?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 utility for cleaning HTML from strings. | ||
* | ||
* @package logstore_xapi | ||
* @copyright Daniel Bell <[email protected]> | ||
* Milt Reder <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace src\transformer\utils\get_activity; | ||
use src\transformer\utils as utils; | ||
|
||
/** | ||
* Transformer utility for generating note object for note_created and note_updated events | ||
* | ||
* @param array $config | ||
* @param string $lang | ||
* @param array $subject | ||
* @param array $note | ||
* @return object | ||
*/ | ||
function course_note($config, $lang, $subject, $note) { | ||
return [ | ||
'id' => $config['app_url'].'/notes/view.php?id='.$note->id, | ||
'definition' => [ | ||
'name' => [$lang => utils\get_string_html_removed($note->subject)], | ||
'type' => 'http://activitystrea.ms/note', | ||
'description' => [$lang => utils\get_string_html_removed($note->content)], | ||
'extensions' => [ | ||
"https://xapi.edlm/profiles/edlm-lms/concepts/activity-extensions/note-type" => "course", | ||
"https://xapi.edlm/profiles/edlm-lms/concepts/activity-extensions/note-subject" => | ||
utils\get_user($config,$subject) | ||
] | ||
] | ||
]; | ||
} |
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,23 @@ | ||
{ | ||
"post": [ | ||
{ | ||
"id": 1, | ||
"subject": "no subject", | ||
"content": "here is a note" | ||
} | ||
], | ||
"user": [ | ||
{ | ||
"id": 1, | ||
"email": "[email protected]", | ||
"firstname": "note_author_firstname", | ||
"lastname": "note_author_lastname" | ||
}, | ||
{ | ||
"id": 2, | ||
"email": "[email protected]", | ||
"firstname": "note_subject_firstname", | ||
"lastname": "note_subject_lastname" | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"courseid": 1, | ||
"eventname": "\\core\\event\\note_created", | ||
"id": 1, | ||
"objectid": 1, | ||
"objecttable": "post", | ||
"timecreated": 1433946701, | ||
"userid": 1, | ||
"relateduserid": 2 | ||
} |
Oops, something went wrong.