Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| VariableStorableCollection | |
0.00% |
0 / 42 |
|
0.00% |
0 / 6 |
210 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| createTestVariableCollection | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| createItemVariableCollection | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| createFromArray | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| getIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toStorableArray | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2017 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoResultServer\models\Collection; |
| 22 | |
| 23 | use oat\taoResultServer\models\Entity\ItemVariableStorable; |
| 24 | use oat\taoResultServer\models\Entity\TestVariableStorable; |
| 25 | use oat\taoResultServer\models\Entity\VariableStorable; |
| 26 | |
| 27 | class VariableStorableCollection |
| 28 | { |
| 29 | /** @var string */ |
| 30 | private $identifier; |
| 31 | |
| 32 | /** @var \oat\taoResultServer\models\Entity\VariableStorable[] */ |
| 33 | private $variables = []; |
| 34 | |
| 35 | /** |
| 36 | * @param $identifier |
| 37 | * @param \oat\taoResultServer\models\Entity\VariableStorable[] $variables |
| 38 | */ |
| 39 | public function __construct($identifier, array $variables) |
| 40 | { |
| 41 | $this->identifier = $identifier; |
| 42 | $this->variables = $variables; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param $callIdTest |
| 47 | * @param $deliveryResultIdentifier |
| 48 | * @param $testIdentifier |
| 49 | * @param \taoResultServer_models_classes_Variable[] $testVariables |
| 50 | * |
| 51 | * @return VariableStorableCollection |
| 52 | */ |
| 53 | public static function createTestVariableCollection( |
| 54 | $callIdTest, |
| 55 | $deliveryResultIdentifier, |
| 56 | $testIdentifier, |
| 57 | array $testVariables |
| 58 | ) { |
| 59 | $storableVariables = []; |
| 60 | |
| 61 | foreach ($testVariables as $testVariable) { |
| 62 | if (!($testVariable->isSetEpoch())) { |
| 63 | $testVariable->setEpoch(microtime()); |
| 64 | } |
| 65 | |
| 66 | $storableVariables[] = new TestVariableStorable( |
| 67 | $deliveryResultIdentifier, |
| 68 | $testIdentifier, |
| 69 | $testVariable, |
| 70 | $callIdTest |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | return new self($callIdTest, $storableVariables); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @param $callIdItem |
| 79 | * @param $item |
| 80 | * @param $deliveryResultIdentifier |
| 81 | * @param $testIdentifier |
| 82 | * @param \taoResultServer_models_classes_Variable[] $testVariables |
| 83 | * |
| 84 | * @return VariableStorableCollection |
| 85 | */ |
| 86 | public static function createItemVariableCollection( |
| 87 | $callIdItem, |
| 88 | $item, |
| 89 | $deliveryResultIdentifier, |
| 90 | $testIdentifier, |
| 91 | array $testVariables |
| 92 | ) { |
| 93 | $storableVariables = []; |
| 94 | |
| 95 | foreach ($testVariables as $testVariable) { |
| 96 | if (!($testVariable->isSetEpoch())) { |
| 97 | $testVariable->setEpoch(microtime()); |
| 98 | } |
| 99 | |
| 100 | $storableVariables[] = new ItemVariableStorable( |
| 101 | $deliveryResultIdentifier, |
| 102 | $testIdentifier, |
| 103 | $testVariable, |
| 104 | $item, |
| 105 | $callIdItem |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | return new self($callIdItem, $storableVariables); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @param $deliveryResultIdentifier |
| 114 | * @param array $variables |
| 115 | * @return VariableStorableCollection |
| 116 | */ |
| 117 | public static function createFromArray($deliveryResultIdentifier, array $variables) |
| 118 | { |
| 119 | $storableVariables = []; |
| 120 | |
| 121 | foreach ($variables as $variable) { |
| 122 | $variable = json_decode($variable, true); |
| 123 | if (isset($variable['callIdTest'])) { |
| 124 | $variableObj = TestVariableStorable::createFromArray($variable); |
| 125 | } elseif (isset($variable['callIdItem'])) { |
| 126 | $variableObj = ItemVariableStorable::createFromArray($variable); |
| 127 | } else { |
| 128 | continue; |
| 129 | } |
| 130 | |
| 131 | $storableVariables[] = $variableObj; |
| 132 | } |
| 133 | |
| 134 | return new self($deliveryResultIdentifier, $storableVariables); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * @return string |
| 139 | */ |
| 140 | public function getIdentifier() |
| 141 | { |
| 142 | return $this->identifier; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @return array |
| 147 | */ |
| 148 | public function toStorableArray() |
| 149 | { |
| 150 | $data = []; |
| 151 | |
| 152 | foreach ($this->variables as $variable) { |
| 153 | $data[$variable->getIdentifier()] = json_encode([ |
| 154 | $variable |
| 155 | ]); |
| 156 | } |
| 157 | |
| 158 | return $data; |
| 159 | } |
| 160 | } |