Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 26
CRAP
0.00% covered (danger)
0.00%
0 / 1
StorageAggregation
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 26
1892
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 getOneImplementation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllImplementations
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVariables
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVariable
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTestTaker
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDelivery
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllCallIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllTestTakerIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllDeliveryIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 spawnResult
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 storeRelatedTestTaker
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 storeRelatedDelivery
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 storeItemVariable
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 storeItemVariables
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 storeTestVariable
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 storeTestVariables
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 configure
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getVariableProperty
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRelatedItemCallIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRelatedTestCallIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getResultByDelivery
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 countResultByDelivery
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDeliveryVariables
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 deleteResult
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
20
 deleteDeliveryExecutionData
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
20
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) 2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\taoResultServer\models\classes\implementation;
23
24use oat\taoDelivery\model\execution\Delete\DeliveryExecutionDeleteRequest;
25use taoResultServer_models_classes_Variable;
26use oat\taoResultServer\models\classes\ResultManagement  as StorageManage;
27use taoResultServer_models_classes_ReadableResultStorage as StorageRead;
28use taoResultServer_models_classes_WritableResultStorage as StorageWrite;
29
30class StorageAggregation implements
31    StorageRead,
32    StorageWrite,
33    StorageManage
34{
35    private $implementations = [];
36
37    public function __construct($implementations)
38    {
39        $interfaces = class_implements($this);
40        foreach ($interfaces as $interface) {
41            $this->implementations[$interface] = [];
42        }
43        foreach ($implementations as $impl) {
44            foreach (array_intersect($interfaces, class_implements($impl)) as $interface) {
45                $this->implementations[$interface][] = $impl;
46            }
47        }
48    }
49
50
51    protected function getOneImplementation($interface)
52    {
53        return reset($this->implementations[$interface]);
54    }
55
56    protected function getAllImplementations($interface)
57    {
58        return $this->implementations[$interface];
59    }
60
61    // read interface
62
63    public function getVariables($callId)
64    {
65        return $this->getOneImplementation(StorageRead::class)->getVariables($callId);
66    }
67
68    public function getVariable($callId, $variableIdentifier)
69    {
70        return $this->getOneImplementation(StorageRead::class)->getVariable($callId, $variableIdentifier);
71    }
72
73    public function getTestTaker($deliveryResultIdentifier)
74    {
75        return $this->getOneImplementation(StorageRead::class)->getTestTaker($deliveryResultIdentifier);
76    }
77
78    public function getDelivery($deliveryResultIdentifier)
79    {
80        return $this->getOneImplementation(StorageRead::class)->getDelivery($deliveryResultIdentifier);
81    }
82
83    public function getAllCallIds()
84    {
85        return $this->getOneImplementation(StorageRead::class)->getAllCallIds();
86    }
87
88    public function getAllTestTakerIds()
89    {
90        return $this->getOneImplementation(StorageRead::class)->getAllTestTakerIds();
91    }
92
93    public function getAllDeliveryIds()
94    {
95        return $this->getOneImplementation(StorageRead::class)->getAllDeliveryIds();
96    }
97
98    // write interface
99
100    /**
101     * Not sure how multiple engines are supposed to handle this
102     */
103    public function spawnResult()
104    {
105        $result = null;
106        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
107            $result = $impl->spawnResult();
108        }
109        return $result;
110    }
111
112    public function storeRelatedTestTaker($deliveryResultIdentifier, $testTakerIdentifier)
113    {
114        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
115            $impl->storeRelatedTestTaker($deliveryResultIdentifier, $testTakerIdentifier);
116        }
117    }
118
119    public function storeRelatedDelivery($deliveryResultIdentifier, $deliveryIdentifier)
120    {
121        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
122            $impl->storeRelatedDelivery($deliveryResultIdentifier, $deliveryIdentifier);
123        }
124    }
125
126    public function storeItemVariable(
127        $deliveryResultIdentifier,
128        $test,
129        $item,
130        taoResultServer_models_classes_Variable $itemVariable,
131        $callIdItem
132    ) {
133        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
134            $impl->storeItemVariable($deliveryResultIdentifier, $test, $item, $itemVariable, $callIdItem);
135        }
136    }
137
138    public function storeItemVariables($deliveryResultIdentifier, $test, $item, array $itemVariables, $callIdItem)
139    {
140        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
141            $impl->storeItemVariables($deliveryResultIdentifier, $test, $item, $itemVariables, $callIdItem);
142        }
143    }
144
145    public function storeTestVariable(
146        $deliveryResultIdentifier,
147        $test,
148        taoResultServer_models_classes_Variable $testVariable,
149        $callIdTest
150    ) {
151        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
152            $impl->storeTestVariable($deliveryResultIdentifier, $test, $testVariable, $callIdTest);
153        }
154    }
155
156    public function storeTestVariables($deliveryResultIdentifier, $test, array $testVariables, $callIdTest)
157    {
158        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
159            $impl->storeTestVariables($deliveryResultIdentifier, $test, $testVariables, $callIdTest);
160        }
161    }
162
163    public function configure($callOptions = [])
164    {
165        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
166            $success = $impl->configure($callOptions);
167        }
168    }
169
170    // manage interface
171
172    public function getVariableProperty($variableId, $property)
173    {
174        return $this->getOneImplementation(StorageManage::class)->getVariableProperty($variableId, $property);
175    }
176
177    public function getRelatedItemCallIds($deliveryResultIdentifier)
178    {
179        return $this->getOneImplementation(StorageManage::class)->getRelatedItemCallIds($deliveryResultIdentifier);
180    }
181
182    public function getRelatedTestCallIds($deliveryResultIdentifier)
183    {
184        return $this->getOneImplementation(StorageManage::class)->getRelatedTestCallIds($deliveryResultIdentifier);
185    }
186
187    public function getResultByDelivery($delivery, $options = [])
188    {
189        return $this->getOneImplementation(StorageManage::class)->getResultByDelivery($delivery, $options = []);
190    }
191
192    public function countResultByDelivery($delivery)
193    {
194        return $this->getOneImplementation(StorageManage::class)->countResultByDelivery($delivery);
195    }
196
197    public function getDeliveryVariables($delivery)
198    {
199        return $this->getOneImplementation(StorageManage::class)->getDeliveryVariables($delivery);
200    }
201
202    public function deleteResult($deliveryResultIdentifier)
203    {
204        $success = null;
205        foreach ($this->getAllImplementations(StorageManage::class) as $impl) {
206            $success = $impl->deleteResult($deliveryResultIdentifier) && ($success === true || is_null($success));
207        }
208        return $success === true;
209    }
210
211    /**
212     * @inheritdoc
213     */
214    public function deleteDeliveryExecutionData(DeliveryExecutionDeleteRequest $request)
215    {
216        $success = null;
217        /** @var \oat\taoDelivery\model\execution\Delete\DeliveryExecutionDelete $impl */
218        foreach ($this->getAllImplementations(StorageManage::class) as $impl) {
219            $success = $impl->deleteDeliveryExecutionData($request) && ($success === true || is_null($success));
220        }
221        return $success === true;
222    }
223}