Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
10 / 10
CRAP
100.00% covered (success)
100.00%
1 / 1
ImportResultInput
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
10 / 10
14
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getDeliveryExecutionId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isSendAgs
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addOutcome
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOutcomes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasOutcomes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResponses
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fromJson
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
5
 jsonSerialize
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2023 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\taoResultServer\models\Import\Input;
24
25use JsonSerializable;
26
27class ImportResultInput implements JsonSerializable
28{
29    private string $deliveryExecutionId;
30    private bool $sendAgs;
31    private array $outcomes;
32    private array $responses;
33
34    public function __construct(string $deliveryExecutionId, bool $sendAgs)
35    {
36        $this->deliveryExecutionId = $deliveryExecutionId;
37        $this->sendAgs = $sendAgs;
38        $this->outcomes = [];
39        $this->responses = [];
40    }
41
42    public function getDeliveryExecutionId(): string
43    {
44        return $this->deliveryExecutionId;
45    }
46
47    public function isSendAgs(): bool
48    {
49        return $this->sendAgs;
50    }
51
52    public function addOutcome(string $itemId, string $outcomeId, float $outcomeValue): void
53    {
54        $this->outcomes[$itemId][$outcomeId] = $outcomeValue;
55    }
56
57    public function addResponse(string $itemId, string $responseId, array $values): void
58    {
59        $this->responses[$itemId][$responseId] = $values;
60    }
61
62    /**
63     * [
64     *    'itemId' => [
65     *        'outcomeId' => 'outcomeValue'
66     *    ]
67     * ]
68     *
69     * @return array
70     */
71    public function getOutcomes(): array
72    {
73        return $this->outcomes;
74    }
75
76    public function hasOutcomes(): bool
77    {
78        return count($this->outcomes) > 0;
79    }
80
81    /**
82     * [
83     *    'itemId' => [
84     *        'responseId' => [
85     *            'correctResponse' => true
86     *        ]
87     *    ]
88     * ]
89     *
90     * @return array
91     */
92    public function getResponses(): array
93    {
94        return $this->responses;
95    }
96
97    public static function fromJson(array $json): self
98    {
99        $new = new self($json['deliveryExecutionId'], $json['sendAgs']);
100
101        foreach ($json['outcomes'] as $itemId => $values) {
102            foreach ($values as $outcomeId => $outcomeValue) {
103                $new->addOutcome($itemId, $outcomeId, $outcomeValue);
104            }
105        }
106
107        foreach ($json['responses'] as $itemId => $values) {
108            foreach ($values as $responseId => $responseValues) {
109                $new->addResponse(
110                    $itemId,
111                    $responseId,
112                    $responseValues
113                );
114            }
115        }
116
117        return $new;
118    }
119
120    public function jsonSerialize(): array
121    {
122        return [
123            'deliveryExecutionId' => $this->deliveryExecutionId,
124            'sendAgs' => $this->sendAgs,
125            'outcomes' => $this->outcomes,
126            'responses' => $this->responses,
127        ];
128    }
129}