From 7e8a9b5ccb3544784766bd16ef8cfe42e04c3dae Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 4 Jul 2021 22:30:09 -0500 Subject: [PATCH] Plugin : Improve lti provider , feedbacks from PR --- plugin/lti_provider/assets/css/style.css | 0 plugin/lti_provider/web/api/ags/results.json | 1 - plugin/lti_provider/web/api/score.php | 56 ++++++++++++-------- plugin/lti_provider/web/api/scoreboard.php | 47 +++++++++++----- plugin/lti_provider/web/static/breakout.js | 4 +- 5 files changed, 69 insertions(+), 39 deletions(-) delete mode 100644 plugin/lti_provider/assets/css/style.css delete mode 100755 plugin/lti_provider/web/api/ags/results.json diff --git a/plugin/lti_provider/assets/css/style.css b/plugin/lti_provider/assets/css/style.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/plugin/lti_provider/web/api/ags/results.json b/plugin/lti_provider/web/api/ags/results.json deleted file mode 100755 index 1787425736..0000000000 --- a/plugin/lti_provider/web/api/ags/results.json +++ /dev/null @@ -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"}}} \ No newline at end of file diff --git a/plugin/lti_provider/web/api/score.php b/plugin/lti_provider/web/api/score.php index 9715208d53..2738b0776e 100644 --- a/plugin/lti_provider/web/api/score.php +++ b/plugin/lti_provider/web/api/score.php @@ -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); -if (file_exists($dataFile)) { - @chmod($dataFile, 0775); -} -file_put_contents($dataFile, json_encode($data)); -echo '{"success" : true}'; -?> + +$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); + +echo '{"success" : true}'; \ No newline at end of file diff --git a/plugin/lti_provider/web/api/scoreboard.php b/plugin/lti_provider/web/api/scoreboard.php index 3b1444cd3e..f575279c08 100644 --- a/plugin/lti_provider/web/api/scoreboard.php +++ b/plugin/lti_provider/web/api/scoreboard.php @@ -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); -?> +echo json_encode($scoreboard); \ No newline at end of file diff --git a/plugin/lti_provider/web/static/breakout.js b/plugin/lti_provider/web/static/breakout.js index 23948b6975..e2d7cbb3d3 100644 --- a/plugin/lti_provider/web/static/breakout.js +++ b/plugin/lti_provider/web/static/breakout.js @@ -439,9 +439,9 @@ var endGame = function() { var refreshScoreBoard = function() { var scores = JSON.parse(this.responseText); console.log(scores); - var output = 'NameScoreTime'; + var output = 'ScoreTimeName'; for (var i = 0; i < scores.length; i++) { - output += '' + scores[i].name + '' + scores[i].score + '' + scores[i].time + ''; + output += '' + scores[i].score + '' + scores[i].time + 's' + scores[i].name + ''; } document.getElementById("leadertable").innerHTML = output; }