1 | <?php |
||
2 | /* For license terms, see /license.txt */ |
||
3 | |||
4 | require_once __DIR__.'/../../../../main/inc/global.inc.php'; |
||
5 | require_once __DIR__.'/../../src/LtiProvider.php'; |
||
6 | |||
7 | $launch = LtiProvider::create()->launch(true, $_REQUEST['launch_id']); |
||
8 | |||
9 | if (!$launch->hasAgs()) { |
||
10 | throw new Exception("Don't have grades!"); |
||
11 | } |
||
12 | |||
13 | if (!isset($_REQUEST['exeId'])) { |
||
14 | throw new Exception("Any Exercise result"); |
||
15 | } |
||
16 | |||
17 | $launchData = $launch->getLaunchData(); |
||
18 | |||
19 | $label = 'Score'; |
||
20 | $courseClient = $launchData['https://purl.imsglobal.org/spec/lti/claim/resource_link']['title']; |
||
21 | if (!empty($courseClient)) { |
||
22 | $label = $courseClient; |
||
23 | } |
||
24 | |||
25 | $exeId = (int) $_REQUEST['exeId']; |
||
26 | $trackInfo = Exercise::get_stat_track_exercise_info_by_exe_id($exeId); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
27 | $score = $trackInfo['exe_result']; |
||
28 | $weight = $trackInfo['exe_weighting']; |
||
29 | $duration = $trackInfo['duration']; |
||
30 | $timestamp = date(DateTime::ISO8601); |
||
31 | |||
32 | $grades = $launch->getAgs(); |
||
33 | $score = Packback\Lti1p3\LtiGrade::new() |
||
34 | ->setScoreGiven($score) |
||
35 | ->setScoreMaximum($weight) |
||
36 | ->setTimestamp($timestamp) |
||
37 | ->setActivityProgress('Completed') |
||
38 | ->setGradingProgress('FullyGraded') |
||
39 | ->setUserId($launch->getLaunchData()['sub']); |
||
40 | |||
41 | |||
42 | $scoreLineitem = Packback\Lti1p3\LtiLineitem::new() |
||
43 | ->setTag('score') |
||
44 | ->setScoreMaximum($weight) |
||
45 | ->setLabel($label) |
||
46 | ->setResourceId($launch->getLaunchData()['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id']); |
||
47 | |||
48 | $grades->putGrade($score, $scoreLineitem); |
||
49 | |||
50 | |||
51 | $time = Packback\Lti1p3\LtiGrade::new() |
||
52 | ->setScoreGiven($duration) |
||
53 | ->setScoreMaximum(999) |
||
54 | ->setTimestamp($timestamp) |
||
55 | ->setActivityProgress('Completed') |
||
56 | ->setGradingProgress('FullyGraded') |
||
57 | ->setUserId($launch->getLaunchData()['sub']); |
||
58 | |||
59 | $timeLineitem = Packback\Lti1p3\LtiLineitem::new() |
||
60 | ->setTag('time') |
||
61 | ->setScoreMaximum(999) |
||
62 | ->setLabel('Time Taken') |
||
63 | ->setResourceId('time'.$launch->getLaunchData()['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id']); |
||
64 | |||
65 | $grades->putGrade($time, $timeLineitem); |
||
66 | |||
67 | echo '{"success" : true}'; |
||
68 |