Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
24 / 48 |
|
33.33% |
4 / 12 |
CRAP | |
0.00% |
0 / 1 |
| TestCategoryPreset | |
50.00% |
24 / 48 |
|
33.33% |
4 / 12 |
110.50 | |
0.00% |
0 / 1 |
| __construct | |
68.42% |
13 / 19 |
|
0.00% |
0 / 1 |
16.53 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getQtiCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAltCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOrder | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPluginId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFeatureFlag | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| fromArray | |
70.00% |
7 / 10 |
|
0.00% |
0 / 1 |
4.43 | |||
| 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-2024 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiTest\models; |
| 23 | |
| 24 | use JsonSerializable; |
| 25 | use common_exception_InconsistentData; |
| 26 | |
| 27 | /** |
| 28 | * A POPO that represents a test category preset |
| 29 | * |
| 30 | * @author Christophe Noël <christophe@taotesting.com> |
| 31 | */ |
| 32 | class TestCategoryPreset implements JsonSerializable |
| 33 | { |
| 34 | private string $id; |
| 35 | |
| 36 | /** |
| 37 | * Short preset name |
| 38 | */ |
| 39 | private string $label; |
| 40 | |
| 41 | /** |
| 42 | * The actual qti category that will end up in the QTI markup |
| 43 | */ |
| 44 | private string $qtiCategory; |
| 45 | |
| 46 | /** |
| 47 | * The other possible qti categories that would activate the preset |
| 48 | */ |
| 49 | private array $altCategories = []; |
| 50 | |
| 51 | /** |
| 52 | * What is the category purpose |
| 53 | */ |
| 54 | private string $description = ''; |
| 55 | |
| 56 | /** |
| 57 | * To sort the categories |
| 58 | */ |
| 59 | private int $order = 0; |
| 60 | |
| 61 | /** |
| 62 | * Related plugin that the preset depends on |
| 63 | */ |
| 64 | private string $pluginId = ''; |
| 65 | |
| 66 | /** |
| 67 | * The name of a config flag, the preset will be deactivated based on this optional value. |
| 68 | */ |
| 69 | private string $featureFlag = ''; |
| 70 | |
| 71 | |
| 72 | public function __construct(string $id, string $label, string $qtiCategory, array $data = []) |
| 73 | { |
| 74 | if (! is_string($id) || empty($id)) { |
| 75 | throw new common_exception_InconsistentData('The category preset needs an id'); |
| 76 | } |
| 77 | if (! is_string($label) || empty($label)) { |
| 78 | throw new common_exception_InconsistentData('The category preset needs a label'); |
| 79 | } |
| 80 | if (! is_string($qtiCategory) || empty($qtiCategory)) { |
| 81 | throw new common_exception_InconsistentData('The category preset needs a qti category'); |
| 82 | } |
| 83 | |
| 84 | $this->id = (string) $id; |
| 85 | $this->label = (string) $label; |
| 86 | $this->qtiCategory = (string) $qtiCategory; |
| 87 | |
| 88 | if (isset($data['description'])) { |
| 89 | $this->description = (string) $data['description']; |
| 90 | } |
| 91 | if (isset($data['order'])) { |
| 92 | $this->order = (int) $data['order']; |
| 93 | } |
| 94 | if (isset($data['pluginId'])) { |
| 95 | $this->pluginId = (string) $data['pluginId']; |
| 96 | } |
| 97 | if (isset($data['featureFlag'])) { |
| 98 | $this->featureFlag = (string) $data['featureFlag']; |
| 99 | } |
| 100 | if (isset($data['altCategories'])) { |
| 101 | $this->altCategories = array_map('strval', $data['altCategories']); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | public function getId(): string |
| 106 | { |
| 107 | return $this->id; |
| 108 | } |
| 109 | |
| 110 | public function getLabel(): string |
| 111 | { |
| 112 | return $this->label; |
| 113 | } |
| 114 | |
| 115 | public function getQtiCategory(): string |
| 116 | { |
| 117 | return $this->qtiCategory; |
| 118 | } |
| 119 | |
| 120 | public function getAltCategory(): array |
| 121 | { |
| 122 | return $this->altCategories; |
| 123 | } |
| 124 | |
| 125 | public function getDescription(): string |
| 126 | { |
| 127 | return $this->description; |
| 128 | } |
| 129 | |
| 130 | public function getOrder(): int |
| 131 | { |
| 132 | return $this->order; |
| 133 | } |
| 134 | |
| 135 | public function getPluginId(): string |
| 136 | { |
| 137 | return $this->pluginId; |
| 138 | } |
| 139 | |
| 140 | public function getFeatureFlag(): string |
| 141 | { |
| 142 | return $this->featureFlag; |
| 143 | } |
| 144 | |
| 145 | public function jsonSerialize(): array |
| 146 | { |
| 147 | return $this->toArray(); |
| 148 | } |
| 149 | |
| 150 | public function toArray(): array |
| 151 | { |
| 152 | return [ |
| 153 | 'id' => $this->id, |
| 154 | 'label' => $this->label, |
| 155 | 'qtiCategory' => $this->qtiCategory, |
| 156 | 'altCategories' => $this->altCategories, |
| 157 | 'description' => $this->description, |
| 158 | 'order' => $this->order, |
| 159 | 'pluginId' => $this->pluginId, |
| 160 | 'featureFlag' => $this->featureFlag |
| 161 | ]; |
| 162 | } |
| 163 | |
| 164 | public static function fromArray(array $data): TestCategoryPreset |
| 165 | { |
| 166 | if (!isset($data['id']) || !isset($data['label']) || !isset($data['qtiCategory'])) { |
| 167 | throw new common_exception_InconsistentData( |
| 168 | 'The test category preset requires an id, a label and a qtiCategory' |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | return new self( |
| 173 | $data['id'], |
| 174 | $data['label'], |
| 175 | $data['qtiCategory'], |
| 176 | $data |
| 177 | ); |
| 178 | } |
| 179 | } |