Skip to content

Commit d83dd23

Browse files
authored
Merge pull request #11339 from surlabs/trunk_LTI_lpfixes
[FIX] LTI: Fix LTI 1.3 learning progress via outcomes service (Missing file)
2 parents 648abab + 5040d00 commit d83dd23

1 file changed

Lines changed: 41 additions & 26 deletions

File tree

components/ILIAS/LTIConsumer/classes/class.ilLTIConsumerGradeServiceScores.php

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ protected function checkScore(string $requestData, int $objId): int
9595
return 404;
9696
}
9797

98+
ilObjLTIConsumer::getLogger()->dump($score);
99+
98100
if (empty($score) ||
99101
!isset($score->userId) ||
100102
!isset($score->gradingProgress) ||
@@ -110,17 +112,15 @@ protected function checkScore(string $requestData, int $objId): int
110112
throw new Exception('Incorrect score received', 400);
111113
return 400;
112114
}
113-
//Achtung Ggfs. Timestamp prüfen falls schon was ankam
115+
114116
if (!isset($score->scoreMaximum)) {
115117
$score->scoreMaximum = 1;
116118
}
117-
if (isset($score->scoreGiven)) {
118-
if ($score->gradingProgress != 'FullyGraded') {
119-
$score->scoreGiven = null;
120-
}
119+
if (!isset($score->scoreGiven)) {
120+
$score->scoreGiven = 0;
121121
}
122+
122123
$result = (float) $score->scoreGiven / (float) $score->scoreMaximum;
123-
ilObjLTIConsumer::getLogger()->info("result: " . $result);
124124

125125
$ltiObjRes = new ilLTIConsumerResultService();
126126

@@ -131,33 +131,48 @@ protected function checkScore(string $requestData, int $objId): int
131131
return 404;
132132
}
133133

134-
if ($result >= $ltiObjRes->getMasteryScore()) {
135-
$lp_status = ilLPStatus::LP_STATUS_COMPLETED_NUM;
136-
} else {
134+
$lp_status = ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM;
135+
136+
if ($score->activityProgress === 'InProgress') {
137137
$lp_status = ilLPStatus::LP_STATUS_IN_PROGRESS_NUM;
138+
} elseif ($score->activityProgress === 'Completed' && $score->gradingProgress === 'FullyGraded') {
139+
if ($result >= $ltiObjRes->getMasteryScore()) {
140+
$lp_status = ilLPStatus::LP_STATUS_COMPLETED_NUM;
141+
} else {
142+
$lp_status = ilLPStatus::LP_STATUS_IN_PROGRESS_NUM;
143+
}
144+
} elseif ($score->activityProgress === 'Completed' && $score->gradingProgress === 'Failed') {
145+
$lp_status = ilLPStatus::LP_STATUS_FAILED_NUM;
138146
}
147+
139148
$lp_percentage = (int) round(100 * $result);
140149

150+
ilObjLTIConsumer::getLogger()->info("lp_status: $lp_status, lp_percentage: $lp_percentage, result: $result, mastery_score: " . $ltiObjRes->getMasteryScore());
151+
141152
$consRes = ilLTIConsumerResult::getByKeys($objId, $userId, false);
142153
if (empty($consRes)) {
143-
ilObjLTIConsumer::getLogger()->info("lti_consumer_results_id not found!");
144-
// throw new Exception('lti_consumer_results_id not found!', 404);
145-
// return 404;
146-
}
147-
if (!isset($consRes->id)) {
148-
$consRes->id = $DIC->database()->nextId('lti_consumer_results');
154+
$DIC->database()->insert(
155+
'lti_consumer_results',
156+
array(
157+
'id' => array('integer', $DIC->database()->nextId('lti_consumer_results')),
158+
'obj_id' => array('integer', $objId),
159+
'usr_id' => array('integer', $userId),
160+
'result' => array('float', $result)
161+
)
162+
);
163+
} else {
164+
$DIC->database()->replace(
165+
'lti_consumer_results',
166+
array(
167+
'id' => array('integer', $consRes->id)
168+
),
169+
array(
170+
'obj_id' => array('integer', $objId),
171+
'usr_id' => array('integer', $userId),
172+
'result' => array('float', $result)
173+
)
174+
);
149175
}
150-
$DIC->database()->replace(
151-
'lti_consumer_results',
152-
array(
153-
'id' => array('integer', $consRes->id)
154-
),
155-
array(
156-
'obj_id' => array('integer', $objId),
157-
'usr_id' => array('integer', $userId),
158-
'result' => array('float', $result)
159-
)
160-
);
161176

162177
ilLPStatus::writeStatus($objId, $userId, $lp_status, $lp_percentage, true);
163178

0 commit comments

Comments
 (0)