Skip to content

Commit

Permalink
added support for filtering of current students in moodle.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoBoer authored and torinfo committed Apr 1, 2024
1 parent b6b0668 commit c7c4873
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
17 changes: 16 additions & 1 deletion config.php
Expand Up @@ -185,7 +185,22 @@
$dir = opendir(dirname(__FILE__) . "/modules/");

// I'm not sure why we allow this path to be set via the DB. It'd make more sense to fix it to dirname(__FILE__), which will cope with the site moving.
$xerte_toolkits_site->root_file_path = dirname(__FILE__) . '/';
$xerte_toolkits_site->root_file_path = realpath(__DIR__) . '/';
$xerte_toolkits_site->import_path = realpath(__DIR__) . '/import/';

// Try to get site_url in the same way
$host = $_SERVER['SERVER_NAME'];
$scheme = (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : false) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ? 'https://' : 'http://';
// get subdir from $xerte_toolkits_site->site_url path stored in Db
$subdir = '/';
$subdir_pos = strpos($xerte_toolkits_site->site_url, '/', 8);
if ($subdir_pos !== false)
{
$subdir = substr($xerte_toolkits_site->site_url, $subdir_pos);
}
$site_url = $scheme . $host . $subdir;

$xerte_toolkits_site->site_url = $site_url;

$learning_objects = new StdClass();

Expand Down
13 changes: 6 additions & 7 deletions lti_launch.php
Expand Up @@ -42,16 +42,14 @@

if (isset($_GET["template_id"])) {
$id = $_GET["template_id"];
_debug("HERE?1");
}
else if(isset($_POST["template_id"]))
{
$id = $_POST["template_id"];
// Hack for the rest of Xerte
$_GET['template_id'] = $id;
_debug("HERE?2");
}
_debug("HERE3");
_debug("test123");
if(is_numeric($id) || $id == null)
{
$tsugi_enabled = true;
Expand All @@ -71,11 +69,12 @@
if ($islti13) {
$msg = array();
$nrps = $LAUNCH->context->loadNamesAndRoles(false, $msg);
//TODO: get all emails of current users add to array
//DONE: get all emails of current users add to array
// https://gitlab.tor.nl/xerte-dashboard/dashboard/-/blob/master/index.php line 80
//add as $xerte_toolkits_site->lti_users =
_debug("pls" . print_r($nrps, true));
_debug("msg" . print_r($msg, true));
$xerte_toolkits_site->lti_users = array();
foreach ($nrps->members as $member){
$xerte_toolkits_site->lti_users[] = sha1('mailto:'.$member->email);
}
}

if ($id == null)
Expand Down
Expand Up @@ -677,9 +677,14 @@
var date = moment(endDate).add(1, "days").toISOString();
q["until"] = date;
}
//todo check if current or all users
// if set add current users to q

//todo not like this add indicator to q if only current users.
let current_users = interaction.getAttribute("contextUsersFilter")
if (current_users == 'true') {
q["filter_current_users"] = current_users;
} else {
q["filter_current_users"] = 'false';
}
//debugger
/*
queryStatements(
lrsEndpoint + '/api/connection/statement',
Expand Down Expand Up @@ -1054,7 +1059,7 @@
};

this.init = function () {

//debugger;
var loadFiles = true;
for (var i = 0; i < x_pageInfo.length; i++) {
if (
Expand Down Expand Up @@ -1403,7 +1408,7 @@
}
} else if (interactionType == "opinionclasses") {
// check open question special options

//debugger;
var verb = "http://adlnet.gov/expapi/verbs/answered";
if (interaction.data != null) {
var url = getUrl(xerteurl, xertelo, xertelabel, opinionClass);
Expand Down Expand Up @@ -3786,7 +3791,7 @@
jsonData = jsonData.filter(function (x) {
return x != undefined;
});

//debugger;
div = $(
"#" + escapeUrl(url, type, interactionIndex) + " .graph-container"
);
Expand Down Expand Up @@ -4550,6 +4555,7 @@
$("p").css("font-size", "14px");
$("ul").css("font-size", "14px");
adaptiveContent.sizeChanged();
//debugger;

await new Promise(resolve => setTimeout(resolve, 1500));
let opt = {
Expand Down
6 changes: 4 additions & 2 deletions modules/xerte/play.php
Expand Up @@ -394,9 +394,11 @@ function show_template_page($row, $datafile="", $xapi_enabled = false)
}
if (isset($xerte_toolkits_site->lti_users))
{
$tracking .= " var lti_users = '" . str_replace("'", "\'", $xerte_toolkits_site->lti_users) . "';\n";
$tracking .= " var lti_users = '" . str_replace("'", "\'", implode(",",$xerte_toolkits_site->lti_users)) . "';\n";
} else {
$tracking .= " var lti_users = 'is empty';\n";
}
//todo if lti_users is set create js varaible
//DONE if lti_users is set create js varaible
}
$tracking .= "</script>\n";
//$tracking .= "var lti_context_id = '1390'; var lti_context_name = 'Don Bosco College';\n</script>\n";
Expand Down
29 changes: 29 additions & 0 deletions modules/xerte/xAPI/xttracking_xapi.js
Expand Up @@ -1922,6 +1922,10 @@ function getStatements(q, one, callback)
context_id = q['lti_context_id'];
delete q['lti_context_id'];
}
if (q['filter_current_users'] != undefined) {
filter_current_users = q['filter_current_users'];
delete q['filter_current_users'];
}
$.each(q, function (i, value) {
search[i] = value;
});
Expand All @@ -1931,8 +1935,10 @@ function getStatements(q, one, callback)
search['limit'] = 1000;
}
var statements = [];

if (callback == null) {
var tmp = ADL.XAPIWrapper.getStatements(search);
var lti_user_list = lti_users.split(',');
for (x = 0; x < tmp.statements.length; x++) {
if (group != ""
&& (tmp.statements[x].context.team == undefined
Expand All @@ -1948,13 +1954,21 @@ function getStatements(q, one, callback)
continue;
}
//todo add check if statemettns are from current users if userlist > 0
debugger
if (filter_current_users){
if (!lti_user_list.includes(tmp.statements[x].actor.mbox.split(':')[1])) {
continue;
}
}
statements.push(tmp.statements[x]);
}
return statements;
} else {
debugger;
ADL.XAPIWrapper.getStatements(search, null,
function getmorestatements(err, res, body) {
var lastSubmit = null;
var lti_user_list = lti_users.split(',');

for (x = 0; x < body.statements.length; x++) {
//if (sr.statements[x].actor.mbox == userEMail && lastSubmit == null) {
Expand All @@ -1975,6 +1989,19 @@ function getStatements(q, one, callback)
|| body.statements[x].context.extensions["http://xerte.org.uk/lti_context_id"] != context_id)) {
continue;
}
debugger;
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;
}
}
}
statements.push(body.statements[x]);
}
//stringObjects.push(lastSubmit);
Expand All @@ -1991,6 +2018,7 @@ function getStatements(q, one, callback)
}
);
}
debugger;
}
}

Expand Down Expand Up @@ -2062,6 +2090,7 @@ function XTInitialise(category) {
if (typeof studentidmode != "undefined" && typeof studentidmode == 'string') {
studentidmode = parseInt(studentidmode);
}
debugger
if (typeof studentidmode == "undefined" || (studentidmode <= 0 && studentidmode > 3)) {
// set actor to global group
actor = {
Expand Down

0 comments on commit c7c4873

Please sign in to comment.