Skip to content

Commit

Permalink
badge viewed and update
Browse files Browse the repository at this point in the history
  • Loading branch information
invaliduser committed Nov 12, 2024
1 parent e249e0e commit 8ea3bd8
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 69 deletions.
21 changes: 2 additions & 19 deletions src/transformer/events/core/badge_awarded.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
* Transform for badge awarded event.
*
* @package logstore_xapi
* @copyright Jerret Fowler <[email protected]>
* Ryan Smith <https://www.linkedin.com/in/ryan-smith-uk/>
* David Pesce <[email protected]>
* @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;

/**
Expand Down Expand Up @@ -56,8 +53,6 @@ function badge_awarded(array $config, \stdClass $event) {

$manual = $repo->read_record_by_id('badge_manual_award', $issuedid);
$awarder = $manual ? (utils\get_user($config, $repo->read_record_by_id('user', $manual->issuerid))) : 'System';
$badgetype = [1 => "Global", 2 => "Course"][$badge->type];


$statement = [[
'actor' => $actor,
Expand All @@ -66,19 +61,7 @@ function badge_awarded(array $config, \stdClass $event) {
'display' => [
'en' => 'Achieved'
]],
'object' => [
'id' => $config['app_url'].'/badges/overview.php?id='.$event->objectid,
'objectType' => 'Activity',
'definition' => [
'name' => [$lang => $badge->name],
'description' => [$lang => $badge->description],
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/badge',
'extensions' => [
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-type' => $badgetype,
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-version' => $badge->version
]
],
],
'object' => utils\badge_object($config, $lang, $badge),
'result' => [
'response' => $badge->message
],
Expand Down
15 changes: 1 addition & 14 deletions src/transformer/events/core/badge_revoked.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function badge_revoked(array $config, \stdClass $event) {
$revoker = utils\get_user($config, $repo->read_record_by_id('user', $event->userid));
$course = $badge->courseid ? $repo->read_record_by_id('course', $badge->courseid) : null;
$lang = $badge->language ?? 'en';
$badgetype = [1 => "Global", 2 => "Course"][$badge->type];

$statement = [[
'actor' => utils\get_user($config, $recipient),
Expand All @@ -51,19 +50,7 @@ function badge_revoked(array $config, \stdClass $event) {
'en' => 'Forfeited'
],
],
'object' => [
'id' => $config['app_url'].'/badges/overview.php?id='.$event->objectid,
'objectType' => 'Activity',
'definition' => [
'name' => [$lang => $badge->name],
'description' => [$lang => $badge->description],
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/badge',
'extensions' => [
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-type' => $badgetype,
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-version' => $badge->version
]
]
],
'object' => utils\badge_object($config, $lang, $badge),
'context' => [
'language'=>$lang,
'instructor' =>$revoker,
Expand Down
15 changes: 1 addition & 14 deletions src/transformer/events/core/badge_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
* @package logstore_xapi
* @copyright Daniel Bell <[email protected]>
*
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -40,7 +39,6 @@ function badge_viewed(array $config, \stdClass $event) {
global $CFG;
$repo = $config['repo'];
$badge = $repo->read_record_by_id('badge', $event->objectid);
$badgetype = [1 => "Global", 2 => "Course"][$badge->type];

//all three here may not exist
$user=$repo->read_record_by_id('user',$event->userid);
Expand All @@ -54,18 +52,7 @@ function badge_viewed(array $config, \stdClass $event) {
'verb' => ['id' => 'http://id.tincanapi.com/verb/viewed',
'display' => ['en' => 'Viewed']
],
'object' => [
'id' => $config['app_url'].'/badges/overview.php?id='.$badge->id,
'definition' => [
'name' => [$lang =>$badge->name],
'description' => [$lang => $badge->description],
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/badge',
'extensions' => [
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-type' => $badgetype,
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-version' => $badge->version
]
],
],
'object' => utils\badge_object($config, $lang, $badge),
'context' => [
'language' => $lang,
'contextActivities' => [
Expand Down
51 changes: 51 additions & 0 deletions src/transformer/utils/badge_object.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace src\transformer\utils;

/**
* Utility for creating badge objects for badge events
*
* @param array $config site config
* @param string $lang site config
* @param array $badge The badge associative array
* @return object
*/

function badge_object($config, $lang, $badge) {
$badgetype = [1 => "Global", 2 => "Course"][$badge->type];

return [
'id' => $config['app_url'].'/badges/overview.php?id='.$badge->id,
'definition' => [
'name' => [$lang =>$badge->name],
'description' => [$lang => $badge->description],
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/badge',
'extensions' => [
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-type' => $badgetype,
'https://xapi.edlm/profiles/edlm-lms/v1/concepts/activity-extensions/badge-version' => $badge->version
]
]
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"object": {
"id": "http://www.example.org/badges/overview.php?id=1",
"objectType": "Activity",
"definition": {
"name": {
"en": "test_badgename"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"object": {
"id": "http://www.example.org/badges/overview.php?id=1",
"objectType": "Activity",
"definition": {
"name": {
"en": "test_badgename"
Expand Down
16 changes: 0 additions & 16 deletions tests/core/badge_viewed/user_viewed_badge/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,5 @@
"version": "1.0",
"type": 1
}
],
"course": [
{
"fullname": "test_course_name",
"id": 1,
"lang": "en",
"summary": "test_course_summary"
}
],
"user": [
{
"email": "[email protected]",
"firstname": "badge_viewer_firstname",
"id": 1,
"lastname": "badge_viewer_lastname"
}
]
}
6 changes: 3 additions & 3 deletions tests/core/badge_viewed/user_viewed_badge/statements.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homePage": "http://www.example.org",
"name": "1"
},
"name": "badge_viewer_firstname badge_viewer_lastname"
"name": "test_fullname"
},
"verb": {
"id": "http://id.tincanapi.com/verb/viewed",
Expand Down Expand Up @@ -35,7 +35,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "http://id.tincanapi.com/activitytype/lms"
},
Expand All @@ -46,7 +46,7 @@
{
"definition": {
"name": {
"en": "test_course_name"
"en": "test_name"
},
"type": "https://w3id.org/xapi/cmi5/activitytype/course"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function get_plugin_name() {
/**
* Appease auto-detecting of test cases. xapi_test_case has default test cases.
*
* @covers ::attempt_submitted
* @covers ::badge_viewed
* @return void
*/
public function test_init() {
Expand Down

0 comments on commit 8ea3bd8

Please sign in to comment.