|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
use Chamilo\CoreBundle\Entity\GradebookEvaluation; |
|
5
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class ImsLtiReplaceServiceRequest. |
|
9
|
|
|
*/ |
|
10
|
|
|
class ImsLtiServiceReplaceRequest extends ImsLtiServiceRequest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* ImsLtiReplaceServiceRequest constructor. |
|
14
|
|
|
* |
|
15
|
|
|
* @param SimpleXMLElement $xml |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(SimpleXMLElement $xml) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($xml); |
|
20
|
|
|
|
|
21
|
|
|
$this->responseType = ImsLtiServiceResponse::TYPE_DELETE; |
|
22
|
|
|
$this->xmlRequest = $this->xmlRequest->replaceResultRequest; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function processBody() |
|
26
|
|
|
{ |
|
27
|
|
|
$resultRecord = $this->xmlRequest->resultRecord; |
|
28
|
|
|
$sourcedId = (string) $resultRecord->sourcedGUID->sourcedId; |
|
29
|
|
|
$resultScore = (float) $resultRecord->result->resultScore->textString; |
|
30
|
|
|
|
|
31
|
|
|
if (0 > $resultScore || 1 < $resultScore) { |
|
32
|
|
|
$this->statusInfo |
|
33
|
|
|
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_WARNING) |
|
34
|
|
|
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
|
35
|
|
|
|
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$sourcedParts = explode(':', $sourcedId); |
|
40
|
|
|
|
|
41
|
|
|
$em = Database::getManager(); |
|
42
|
|
|
/** @var GradebookEvaluation $evaluation */ |
|
43
|
|
|
$evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts[0]); |
|
44
|
|
|
/** @var User $user */ |
|
45
|
|
|
$user = $em->find('ChamiloUserBundle:User', $sourcedParts[1]); |
|
46
|
|
|
|
|
47
|
|
|
if (empty($evaluation) || empty($user)) { |
|
48
|
|
|
$this->statusInfo |
|
49
|
|
|
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
|
50
|
|
|
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
|
51
|
|
|
|
|
52
|
|
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$score = $evaluation->getMax() * $resultScore; |
|
56
|
|
|
|
|
57
|
|
|
$results = Result::load(null, $user->getId(), $evaluation->getId()); |
|
58
|
|
|
|
|
59
|
|
|
if (empty($results)) { |
|
60
|
|
|
$result = new Result(); |
|
61
|
|
|
$result->set_evaluation_id($evaluation->getId()); |
|
62
|
|
|
$result->set_user_id($user->getId()); |
|
63
|
|
|
$result->set_score($score); |
|
64
|
|
|
$result->add(); |
|
65
|
|
|
} else { |
|
66
|
|
|
/** @var Result $result */ |
|
67
|
|
|
$result = $results[0]; |
|
68
|
|
|
$result->addResultLog($user->getId(), $evaluation->getId()); |
|
69
|
|
|
$result->set_score($score); |
|
70
|
|
|
$result->save(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->statusInfo |
|
74
|
|
|
->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
|
75
|
|
|
->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_SUCCESS) |
|
76
|
|
|
->setDescription( |
|
77
|
|
|
sprintf( |
|
78
|
|
|
get_plugin_lang('ScoreForXUserIsYScore', 'ImsLtiPlugin'), |
|
79
|
|
|
$user->getId(), |
|
80
|
|
|
$resultScore |
|
81
|
|
|
) |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|