Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

main/exercise/annotation_user.php (1 issue)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
session_cache_limiter('none');
5
6
require_once __DIR__.'/../inc/global.inc.php';
7
8
$questionId = isset($_GET['question_id']) ? (int) $_GET['question_id'] : 0;
9
$exerciseId = isset($_GET['exe_id']) ? (int) $_GET['exe_id'] : 0;
10
$courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
11
$courseInfo = api_get_course_info_by_id($courseId);
12
13
if (empty($courseInfo)) {
14
    return '';
15
}
16
17
$objQuestion = Question::read($questionId, $courseInfo);
18
$documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
19
$picturePath = $documentPath.'/images';
20
$pictureSize = getimagesize($picturePath.'/'.$objQuestion->getPictureFilename());
21
$pictureWidth = $pictureSize[0];
22
$pictureHeight = $pictureSize[1];
23
24
$data = [
25
    'use' => 'user',
26
    'image' => [
27
        'path' => $objQuestion->selectPicturePath(),
28
        'width' => $pictureSize[0],
29
        'height' => $pictureSize[1],
30
    ],
31
    'answers' => [
32
        'paths' => [],
33
        'texts' => [],
34
    ],
35
];
36
37
$attemptList = Event::getAllExerciseEventByExeId($exerciseId);
0 ignored issues
show
The method getAllExerciseEventByExeId() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
$attemptList = Event::/** @scrutinizer ignore-call */ getAllExerciseEventByExeId($exerciseId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
39
if (!empty($attemptList) && isset($attemptList[$questionId])) {
40
    $questionAttempt = $attemptList[$questionId][0];
41
    if (!empty($questionAttempt['answer'])) {
42
        $answers = explode('|', $questionAttempt['answer']);
43
        foreach ($answers as $answer) {
44
            $parts = explode(')(', $answer);
45
            $type = array_shift($parts);
46
47
            switch ($type) {
48
                case 'P':
49
                    $points = [];
50
                    foreach ($parts as $partPoint) {
51
                        $points[] = Geometry::decodePoint($partPoint);
52
                    }
53
                    $data['answers']['paths'][] = $points;
54
                    break;
55
                case 'T':
56
                    $text = [
57
                        'text' => array_shift($parts),
58
                    ];
59
                    $data['answers']['texts'][] = $text + Geometry::decodePoint($parts[0]);
60
                    break;
61
            }
62
        }
63
    }
64
}
65
66
header('Content-Type: application/json');
67
68
echo json_encode($data);
69