Plugin : Improve lti provider , feedbacks from PR

pull/3914/head
Christian 4 years ago
parent a0532c5382
commit 7e8a9b5ccb
  1. 0
      plugin/lti_provider/assets/css/style.css
  2. 1
      plugin/lti_provider/web/api/ags/results.json
  3. 54
      plugin/lti_provider/web/api/score.php
  4. 45
      plugin/lti_provider/web/api/scoreboard.php
  5. 4
      plugin/lti_provider/web/static/breakout.js

@ -1 +0,0 @@
{"CURSO02":{"2":{"score":"2","time":"3","name":"Christian"},"3":{"score":"6","time":"10","name":"Miguel"},"4":{"score":"15","time":"20","name":"Rosa Emerita"}},"CURSOBASE":{"1":{"name":"John","score":"4","time":"6"}},"CURSODECHRISTIAN":{"1":{"name":"Doe admin","score":"5","time":"8"}},"CURSO04":{"2":{"name":"Juan","score":"9","time":"16"}},"CURSO05":{"2":{"name":"Juan","score":"15","time":"22"}},"CURSO06":{"2":{"name":"Juan","score":"8","time":"10"}}}

@ -7,33 +7,43 @@ require_once __DIR__ . '/../../src/LtiProvider.php';
$launch = LtiProvider::create()->launch(true, $_REQUEST['launch_id']);
if (!$launch->hasAgs()) {
//throw new Exception("Don't have grades!");
throw new Exception("Don't have grades!");
}
$launchData = $launch->getLaunchData();
$coursecode = $launchData['https://purl.imsglobal.org/spec/lti/claim/context']['label'];
$userid = $launchData['sub'];
$data = array();
$grades = $launch->getAgs();
$dataFile = __DIR__ . '/ags/results.json';
$score = Packback\Lti1p3\LtiGrade::new()
->setScoreGiven($_REQUEST['score'])
->setScoreMaximum(100)
->setTimestamp(date(DateTime::ISO8601))
->setActivityProgress('Completed')
->setGradingProgress('FullyGraded')
->setUserId($launch->getLaunchData()['sub']);
$dataContent = file_get_contents($dataFile);
if (!empty($dataContent)) {
$data = json_decode($dataContent, true);
}
$data[$coursecode][$userid]['name'] = $launchData['given_name'];
if (isset($_REQUEST['score'])) {
$data[$coursecode][$userid]['score'] = $_REQUEST['score'];
}
if (isset($_REQUEST['time'])) {
$data[$coursecode][$userid]['time'] = $_REQUEST['time'];
$scoreLineitem = Packback\Lti1p3\LtiLineitem::new()
->setTag('score')
->setScoreMaximum(100)
->setLabel('Score')
->setResourceId($launch->getLaunchData()['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id']);
}
$grades->putGrade($score, $scoreLineitem);
$time = Packback\Lti1p3\LtiGrade::new()
->setScoreGiven($_REQUEST['time'])
->setScoreMaximum(999)
->setTimestamp(DateTime::ISO8601)
->setActivityProgress('Completed')
->setGradingProgress('FullyGraded')
->setUserId($launch->getLaunchData()['sub']);
$timeLineitem = Packback\Lti1p3\LtiLineitem::new()
->setTag('time')
->setScoreMaximum(999)
->setLabel('Time Taken')
->setResourceId('time'.$launch->getLaunchData()['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id']);
$grades->putGrade($time, $timeLineitem);
if (file_exists($dataFile)) {
@chmod($dataFile, 0775);
}
file_put_contents($dataFile, json_encode($data));
echo '{"success" : true}';
?>

@ -7,24 +7,45 @@ require_once __DIR__ . '/../../src/LtiProvider.php';
$launch = LtiProvider::create()->launch(true, $_REQUEST['launch_id']);
if (!$launch->hasNrps()) {
//throw new Exception("Don't have names and roles!");
throw new Exception("Don't have names and roles!");
}
if (!$launch->hasAgs()) {
//throw new Exception("Don't have grades!");
throw new Exception("Don't have grades!");
}
$launchData = $launch->getLaunchData();
$coursecode = $launchData['https://purl.imsglobal.org/spec/lti/claim/context']['label'];
$ags = $launch->getAgs();
$dataFile = __DIR__ . '/ags/results.json';
$dataContent = file_get_contents($dataFile);
if (!empty($dataContent)) {
$data = json_decode($dataContent, true);
}
$scoreLineitem = Packback\Lti1p3\LtiLineitem::new()
->setTag('score')
->setScoreMaximum(100)
->setLabel('Score')
->setResourceId($launch->getLaunchData()['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id']);
$scores = $ags->getGrades($scoreLineitem);
$timeLineitem = Packback\Lti1p3\LtiLineitem::new()
->setTag('time')
->setScoreMaximum(999)
->setLabel('Time Taken')
->setResourceId('time'.$launch->getLaunchData()['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id']);
$times = $ags->getGrades($timeLineitem);
$members = $launch->getNrps()->getMembers();
$scoreboard = [];
foreach ($data[$coursecode] as $userId => $member) {
$scoreboard[] = array('user_id' => $userId, 'name' => $member['name'], 'score' => $member['score'], 'time' => $member['time']);
foreach ($scores as $score) {
$result = ['score' => $score['resultScore']];
foreach ($times as $time) {
if ($time['userId'] === $score['userId']) {
$result['time'] = $time['resultScore'];
break;
}
}
foreach ($members as $member) {
if ($member['user_id'] === $score['userId']) {
$result['name'] = $member['name'];
break;
}
}
$scoreboard[] = $result;
}
echo json_encode($scoreboard);
?>

@ -439,9 +439,9 @@ var endGame = function() {
var refreshScoreBoard = function() {
var scores = JSON.parse(this.responseText);
console.log(scores);
var output = '<tr><th>Name</th><th>Score</th><th>Time</th></tr>';
var output = '<tr><th>Score</th><th>Time</th><th>Name</th></tr>';
for (var i = 0; i < scores.length; i++) {
output += '<tr><td>' + scores[i].name + '</td><td>' + scores[i].score + '</td><td>' + scores[i].time + '</td></tr>';
output += '<tr><td>' + scores[i].score + '</td><td>' + scores[i].time + 's</td><td>' + scores[i].name + '</td></tr>';
}
document.getElementById("leadertable").innerHTML = output;
}

Loading…
Cancel
Save