Skip to content

Commit

Permalink
Handle filter xAPI statements on students correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
torinfo committed Apr 1, 2024
1 parent 0a8b551 commit b1f11fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lti_launch.php
Expand Up @@ -72,7 +72,8 @@
//DONE: get all emails of current users add to array
// https://gitlab.tor.nl/xerte-dashboard/dashboard/-/blob/master/index.php line 80
$xerte_toolkits_site->lti_users = array();
foreach ($nrps->members as $member){
foreach ($nrps->members as $i => $member){
if ($member->status == 'Active' && in_array('Learner', $member->roles))
$xerte_toolkits_site->lti_users[] = sha1('mailto:'.$member->email);
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/xerte/play.php
Expand Up @@ -396,7 +396,7 @@ function show_template_page($row, $datafile="", $xapi_enabled = false)
{
$tracking .= " var lti_users = '" . str_replace("'", "\'", implode(",",$xerte_toolkits_site->lti_users)) . "';\n";
} else {
$tracking .= " var lti_users = 'is empty';\n";
$tracking .= " var lti_users = '';\n";
}
//DONE if lti_users is set create js varaible
}
Expand Down
39 changes: 27 additions & 12 deletions modules/xerte/xAPI/xttracking_xapi.js
Expand Up @@ -1876,6 +1876,23 @@ async function httpGetStatements(url, query)
}
}

function getMboxSha1(statement)
{
if (statement.actor == undefined) {
if (statement.actor.mbox != undefined) {
return toSHA1(statement.actor.mbox);
} else if (statement.actor.mbox_sha1sum != undefined) {
return statement.actor.mbox_sha1sum;
}
else {
return null;
}
}
else {
return null;
}
}

async function getStatementsFromDB(q, one)
{
let search = {};
Expand All @@ -1887,6 +1904,11 @@ async function getStatementsFromDB(q, one)
} else {
limit = 5000;
}
if (q['filter_current_users'] != undefined) {
const lti_user_list = lti_users.split(',');
search['actor'] = lti_user_list;
delete q['filter_current_users'];
}
let query = 'statements=1&realtime=1&query=' + JSON.stringify(search) + '&limit=' + limit + '&offset=0';
let statements = [];
do
Expand Down Expand Up @@ -1953,10 +1975,9 @@ function getStatements(q, one, callback)
|| tmp.statements[x].context.extensions["http://xerte.org.uk/lti_context_id"] != context_id)) {
continue;
}
//todo add check if statemettns are from current users if userlist > 0

if (filter_current_users){
if (!lti_user_list.includes(tmp.statements[x].actor.mbox.split(':')[1])) {
//todo add check if statements are from current users if userlist > 0
if (filter_current_users == 'true'){
if (!lti_user_list.includes(getMboxSha1(tmp.statements[x]))) {
continue;
}
}
Expand Down Expand Up @@ -1992,14 +2013,8 @@ function getStatements(q, one, callback)

if (filter_current_users == 'true'){
//done also check for field mbox_sha1sum (has of mailto:mail@mail.nl)
if (body.statements[x].actor.mbox !== undefined) {
if (!lti_user_list.includes(toSHA1(body.statements[x].actor.mbox))) {
continue;
}
} else {
if (!lti_user_list.includes(body.statements[x].actor.mbox_sha1sum)) {
continue;
}
if (!lti_user_list.includes(getMboxSha1(body.statements[x]))) {
continue;
}
}
statements.push(body.statements[x]);
Expand Down

0 comments on commit b1f11fd

Please sign in to comment.