Skip to content

Commit

Permalink
notes (#52)
Browse files Browse the repository at this point in the history
* 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
invaliduser and milt authored Nov 25, 2024
1 parent fe77291 commit fdfa74c
Show file tree
Hide file tree
Showing 17 changed files with 825 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/transformer/events/core/note_created.php
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];
}
74 changes: 74 additions & 0 deletions src/transformer/events/core/note_updated.php
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];
}
94 changes: 94 additions & 0 deletions src/transformer/events/core/notes_viewed.php
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];
}
3 changes: 3 additions & 0 deletions src/transformer/get_event_function_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ function get_event_function_map() {
'\core\event\group_message_sent' => 'core\group_message_sent',
'\core\event\group_member_added' => 'core\group_member_added',
'\core\event\group_member_removed' => 'core\group_member_removed',
'\core\event\note_created' => 'core\note_created',
'\core\event\note_updated' => 'core\note_updated',
'\core\event\notes_viewed' => 'core\notes_viewed',
'\core\event\user_created' => 'core\user_created',
'\core\event\user_enrolment_created' => 'core\user_enrolment_created',
'\core\event\user_enrolment_deleted' => 'core\user_enrolment_deleted',
Expand Down
52 changes: 52 additions & 0 deletions src/transformer/utils/get_activity/course_note.php
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)
]
]
];
}
23 changes: 23 additions & 0 deletions tests/core/note_created/user_created_note/data.json
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"
}
]
}
10 changes: 10 additions & 0 deletions tests/core/note_created/user_created_note/event.json
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
}
Loading

0 comments on commit fdfa74c

Please sign in to comment.