Skip to content

Commit

Permalink
note_object util fn
Browse files Browse the repository at this point in the history
  • Loading branch information
invaliduser committed Nov 15, 2024
1 parent 21c0e47 commit 077b32f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 64 deletions.
16 changes: 2 additions & 14 deletions src/transformer/events/core/note_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
function note_created(array $config, \stdClass $event) {
global $CFG;
$repo = $config['repo'];
$note = read_record_by_id('post', $event->objectid);
$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);
Expand All @@ -53,19 +53,7 @@ function note_created(array $config, \stdClass $event) {
'verb' => ['id' => 'http://activitystrea.ms/create',
'display' => ['en' => 'Created']
],
'object' => [
'id' => $config['app_url'].'/notes/view.php?id='.$event->id,
'definition' => [
'name' => [$lang => utils\get_string_html_removed($note->subject)],
'description' => [$lang => utils\get_string_html_removed($note->content)],
'type' => 'http://activitystrea.ms/note',
'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)
]
],
],
'object' => utils\note_object($config, $lang, $subject, $note),
'context' => [
'language' => $lang,
'contextActivities' => [
Expand Down
64 changes: 26 additions & 38 deletions src/transformer/events/core/note_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,34 @@
*/

function note_updated(array $config, \stdClass $event) {
global $CFG;
$repo = $config['repo'];
$note = read_record_by_id('post', $event->objectid);
global $CFG;
$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);
$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' => [
'id' => $config['app_url'].'/course/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)
]
]
],
'context' => [
'language' => $lang,
'contextActivities' => [
'category' => [activity\site($config)],
],
'extensions' => utils\extensions\base($config, $event, $course)
]];
$statement = [
'actor' => utils\get_user($config,$user),
'verb' => ['id' => 'http://activitystrea.ms/update',
'display' => ['en' => 'Updated']
],
'object' => utils\note_object($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);
}
if ($course){
$statement = utils\add_parent($config,$statement,$course);
}

return [$statement];
return [$statement];
}
24 changes: 19 additions & 5 deletions src/transformer/utils/note_object.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,24 @@
/**
* Transformer utility for generating note object for note_created and note_updated events
*
* @param null|string $string The string to clean.
* @return string
* @param array $config
* @param array $subject
* @param string $lang
* @param array $note
* @return object
*/
function note_object(?string $string) {


function note_object($config, $lang, $subject, $note) {
return [
'id' => $config['app_url'].'/notes/view.php?id='.$note->id,
'definition' => [
'name' => [$lang => get_string_html_removed($note->subject)],
'type' => 'http://activitystrea.ms/note',
'description' => [$lang => 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" =>
get_user($config,$subject)
]
]
];
}
4 changes: 2 additions & 2 deletions tests/core/note_created/user_created_note/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "http://id.tincanapi.com/activitytype/lms"
},
Expand All @@ -52,7 +52,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "https://w3id.org/xapi/cmi5/activitytype/course"
},
Expand Down
6 changes: 3 additions & 3 deletions tests/core/note_updated/user_updated_note/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"object": {
"id": "http://www.example.org/course/view.php?id=1",
"id": "http://www.example.org/notes/view.php?id=1",
"definition": {
"name": {
"en": "a note title"
Expand All @@ -41,7 +41,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "http://id.tincanapi.com/activitytype/lms"
},
Expand All @@ -52,7 +52,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "https://w3id.org/xapi/cmi5/activitytype/course"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/core/notes_viewed/user_viewed_notes/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "http://id.tincanapi.com/activitytype/lms"
},
Expand All @@ -48,7 +48,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "https://w3id.org/xapi/cmi5/activitytype/course"
},
Expand Down

0 comments on commit 077b32f

Please sign in to comment.