Skip to content

Commit

Permalink
assignment feedback viewed
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Oct 23, 2024
1 parent 59e3372 commit bd99198
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/transformer/events/mod_assign/feedback_viewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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 assignment feedback viewed event.
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
*
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace src\transformer\events\mod_assign;

use src\transformer\utils as utils;

/**
* Transformer fn for assignment feedback viewed event.
*
* @param array $config The transformer config settings.
* @param \stdClass $event The event to be transformed.
* @return array
*/

function feedback_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);
$lang = utils\get_course_lang($course);

$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$module = $repo->read_record_by_id('modules', $coursemodule->module);
$instance = $repo->read_record_by_id($module->name, $coursemodule->instance);
$instancename = property_exists($instance, 'name') ? $instance->name : $module->name;

$grade = $repo->read_record_by_id('assign_grades', $event->objectid);
$grader = $repo->read_record_by_id('user', $grade->grader);

return [[
'actor' => utils\get_user($config, $user),
'verb' => [
'id' => 'http://id.tincanapi.com/verb/viewed',
'display' => [
$lang => 'Viewed'
],
],
'object' => [
'id' => $config['app_url']
. '/mod/assign/view.php?id='
. $event->contextinstanceid
. '#feedback',
'objectType' => 'Activity',
'definition' => [
'type' => 'https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/feedback',
'name' => [
$lang => $instancename . ' Feedback'
]
]
],
'context' => [
'language' => $lang,
'instructor' => utils\get_user($config, $grader),
'extensions' => utils\extensions\base($config, $event, $course),
'contextActivities' => [
'parent' => utils\context_activities\get_parent(
$config,
$event->contextinstanceid,
true
),
'category' => [
utils\get_activity\site($config),
],
],
],
]];
}
1 change: 1 addition & 0 deletions src/transformer/get_event_function_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function get_event_function_map() {
'\core\event\course_module_completion_updated' => 'core\course_module_completion_updated',
'\mod_assign\event\assessable_submitted' => 'mod_assign\assignment_submitted',
'\mod_assign\event\submission_graded' => 'mod_assign\assignment_graded',
'\mod_assign\event\feedback_viewed' => 'mod_assign\feedback_viewed',
'\mod_bigbluebuttonbn\event\activity_viewed' => 'mod_bigbluebuttonbn\activity_viewed',
'\mod_bigbluebuttonbn\event\activity_management_viewed' => 'mod_bigbluebuttonbn\activity_management_viewed',
'\mod_bigbluebuttonbn\event\live_session_event' => 'mod_bigbluebuttonbn\live_session',
Expand Down
32 changes: 32 additions & 0 deletions tests/mod_assign/feedback_viewed/user_viewed_feedback/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"assign_grades": [
{
"id": 1,
"grader": 2
}
],
"user": [
{
"id": 1,
"firstname": "test_fullname1",
"email": "[email protected]"
},
{
"id": 2,
"firstname": "test_fullname2",
"email": "[email protected]"
}
],
"modules": [
{
"id": 1,
"name": "assign"
}
],
"assign": [
{
"id": 1,
"name": "test_name"
}
]
}
10 changes: 10 additions & 0 deletions tests/mod_assign/feedback_viewed/user_viewed_feedback/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"courseid": 1,
"eventname": "\\mod_assign\\event\\feedback_viewed",
"id": 1,
"objectid": 1,
"objecttable": "assign_grades",
"timecreated": 1433946701,
"userid": 1,
"contextinstanceid": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[
{
"actor": {
"name": "test_fullname1",
"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/assign/view.php?id=1#feedback",
"objectType": "Activity",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/feedback",
"name": {
"en": "test_name Feedback"
}
}
},
"context": {
"instructor": {
"name": "test_fullname2",
"account": {
"homePage": "http://www.example.org",
"name": "2"
}
},
"contextActivities": {
"parent": [
{
"id": "http://www.example.org/mod/assign/view.php?id=1",
"definition": {
"type": "https://xapi.edlm/profiles/edlm-lms/concepts/activity-types/assignment",
"name": {
"en": "test_name"
}
}
},
{
"id": "http://www.example.org/course/section.php?id=1",
"objectType": "Activity",
"definition": {
"name": {
"en": "test_name Section 0"
},
"type": "http://id.tincanapi.com/activitytype/section"
}
},
{
"id": "http://www.example.org/course/view.php?id=1",
"definition": {
"type": "https://w3id.org/xapi/cmi5/activitytype/course",
"name": {
"en": "test_name"
}
}
}
],
"category": [
{
"id": "http://www.example.org",
"definition": {
"type": "http://id.tincanapi.com/activitytype/lms",
"name": {
"en": "test_name"
}
}
}
]
},
"extensions": {
"http://lrs.learninglocker.net/define/extensions/info": {
"event_function": "\\src\\transformer\\events\\mod_assign\\feedback_viewed",
"event_name": "\\mod_assign\\event\\feedback_viewed",
"http://moodle.org": "1.0.0",
"https://github.com/xAPI-vle/moodle-logstore_xapi": "0.0.0-development"
}
},
"language": "en"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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 logstore_xapi\mod_assign\feedback_viewed\user_viewed_feedback;

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->dirroot . '/admin/tool/log/store/xapi/tests/xapi_test_case.php');

/**
* Unit test for feedback_viewed event
*
* @package logstore_xapi
* @copyright Milt Reder <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_viewed_feedback_test extends \logstore_xapi\xapi_test_case {

/**
* Retrieve the directory of the unit test.
*
* @return string
*/
protected function get_test_dir() {
return __DIR__;
}

/**
* Retrieve the plugin type being tested.
*
* @return string
*/
protected function get_plugin_type() {
return "core";
}

/**
* Retrieve the plugin name being tested.
*
* @return string
*/
protected function get_plugin_name() {
return "mod_assign";
}

/**
* Appease auto-detecting of test cases. xapi_test_case has default test cases.
*
* @covers ::attempt_submitted
* @return void
*/
public function test_init() {

}
}

0 comments on commit bd99198

Please sign in to comment.