Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 84 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| ColumnsProvider | |
0.00% |
0 / 84 |
|
0.00% |
0 / 8 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getTestTakerColumns | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
30 | |||
| getDeliveryColumns | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| getDeliveryExecutionColumns | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
| getGradeColumns | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getResponseColumns | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getTraceVariablesColumns | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getAll | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 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 (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoOutcomeUi\model\export; |
| 23 | |
| 24 | use oat\generis\model\GenerisRdf; |
| 25 | use oat\generis\model\OntologyAwareTrait; |
| 26 | use oat\generis\model\OntologyRdf; |
| 27 | use oat\generis\model\OntologyRdfs; |
| 28 | use oat\taoDelivery\model\fields\DeliveryFieldsService; |
| 29 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
| 30 | use oat\taoDeliveryRdf\model\DeliveryContainerService; |
| 31 | use oat\taoOutcomeUi\model\ResultsService; |
| 32 | use oat\taoOutcomeUi\model\table\ContextTypePropertyColumn; |
| 33 | use oat\taoOutcomeUi\model\table\DeliveryExecutionColumn; |
| 34 | use oat\taoOutcomeUi\model\table\DeliveryExecutionDataProvider; |
| 35 | use oat\taoOutcomeUi\model\table\TraceVariableColumn; |
| 36 | use oat\taoOutcomeUi\model\table\TraceVariableDataProvider; |
| 37 | use oat\taoTestTaker\models\TestTakerService; |
| 38 | use oat\taoOutcomeUi\model\table\TestCenterColumn; |
| 39 | |
| 40 | /** |
| 41 | * ColumnsProvider |
| 42 | * |
| 43 | * @author Gyula Szucs <gyula@taotesting.com> |
| 44 | */ |
| 45 | class ColumnsProvider |
| 46 | { |
| 47 | use OntologyAwareTrait; |
| 48 | |
| 49 | private $delivery; |
| 50 | private $resultsService; |
| 51 | |
| 52 | private const TEST_CENTER_PROPERTY_RDF = 'http://www.tao.lu/Ontologies/TAOTestCenter.rdf#member'; |
| 53 | private const TEST_CENTER_ASSIGNMENT_PROPERTY_RDF = 'http://www.tao.lu/Ontologies/TAOTestCenter#UserAssignment'; |
| 54 | |
| 55 | public const LABEL_START_DELIVERY_EXECUTION = 'Start Delivery Execution'; |
| 56 | private const LABEL_ID_DELIVERY_EXECUTION = 'Delivery Execution Id'; |
| 57 | |
| 58 | private const LABEL_TRACE_VARIABLES = 'Trace variables'; |
| 59 | |
| 60 | /** |
| 61 | * Test Taker properties to be exported. |
| 62 | * |
| 63 | * @var array |
| 64 | */ |
| 65 | private $testTakerProperties = [ |
| 66 | OntologyRdfs::RDFS_LABEL, |
| 67 | GenerisRdf::PROPERTY_USER_LOGIN, |
| 68 | GenerisRdf::PROPERTY_USER_FIRSTNAME, |
| 69 | GenerisRdf::PROPERTY_USER_LASTNAME, |
| 70 | GenerisRdf::PROPERTY_USER_MAIL, |
| 71 | GenerisRdf::PROPERTY_USER_UILG |
| 72 | ]; |
| 73 | |
| 74 | /** |
| 75 | * Delivery properties to be exported. |
| 76 | * |
| 77 | * @var array |
| 78 | */ |
| 79 | private $deliveryProperties = [ |
| 80 | OntologyRdfs::RDFS_LABEL, |
| 81 | DeliveryFieldsService::PROPERTY_CUSTOM_LABEL, |
| 82 | DeliveryContainerService::PROPERTY_MAX_EXEC, |
| 83 | DeliveryAssemblyService::PROPERTY_START, |
| 84 | DeliveryAssemblyService::PROPERTY_END, |
| 85 | DeliveryAssemblyService::PROPERTY_DELIVERY_DISPLAY_ORDER_PROP, |
| 86 | DeliveryContainerService::PROPERTY_ACCESS_SETTINGS |
| 87 | ]; |
| 88 | |
| 89 | /** |
| 90 | * @param string|\core_kernel_classes_Resource $delivery |
| 91 | * @param ResultsService $resultsService |
| 92 | * @throws \common_exception_NotFound |
| 93 | */ |
| 94 | public function __construct($delivery, ResultsService $resultsService) |
| 95 | { |
| 96 | $this->delivery = $this->getResource($delivery); |
| 97 | |
| 98 | if (!$this->delivery->exists()) { |
| 99 | throw new \common_exception_NotFound( |
| 100 | 'Results Exporter: delivery "' . $this->delivery->getUri() . '" does not exist.' |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | $this->resultsService = $resultsService; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Get test taker columns to be exported. |
| 109 | * |
| 110 | * @return array |
| 111 | */ |
| 112 | public function getTestTakerColumns() |
| 113 | { |
| 114 | $columns = []; |
| 115 | // add tt ID |
| 116 | $columns[] = [ |
| 117 | 'type' => DeliveryExecutionColumn::class, |
| 118 | 'label' => __('Test Taker ID'), |
| 119 | // for the BE to select test taker from the DeliveryExecution |
| 120 | 'contextId' => ContextTypePropertyColumn::CONTEXT_TYPE_TEST_TAKER, |
| 121 | 'variableIdentifier' => DeliveryExecutionDataProvider::PROP_USER_ID, |
| 122 | // for the FE to show DE property within Test Takers data |
| 123 | 'prop' => 'delivery_execution', |
| 124 | 'contextType' => DeliveryExecutionDataProvider::PROP_USER_ID, |
| 125 | ]; |
| 126 | |
| 127 | // add custom properties, it contains the GROUP property as well |
| 128 | $customProps = $this->getClass(TestTakerService::CLASS_URI_SUBJECT)->getProperties(); |
| 129 | |
| 130 | $testTakerProps = array_merge($this->testTakerProperties, $customProps); |
| 131 | |
| 132 | foreach ($testTakerProps as $property) { |
| 133 | $property = $this->getProperty($property); |
| 134 | |
| 135 | if ($property->getUri() === self::TEST_CENTER_PROPERTY_RDF) { |
| 136 | continue; |
| 137 | } elseif ($property->getUri() === self::TEST_CENTER_ASSIGNMENT_PROPERTY_RDF) { |
| 138 | $col = new TestCenterColumn($property); |
| 139 | } else { |
| 140 | $col = new ContextTypePropertyColumn(ContextTypePropertyColumn::CONTEXT_TYPE_TEST_TAKER, $property); |
| 141 | |
| 142 | if ($property->getUri() === OntologyRdfs::RDFS_LABEL) { |
| 143 | $col->label = __('Test Taker'); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | $columns[] = $col->toArray(); |
| 148 | } |
| 149 | |
| 150 | return $columns; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Get delivery columns to be exported. |
| 155 | * |
| 156 | * @return array |
| 157 | * @throws \RuntimeException |
| 158 | * @throws \core_kernel_persistence_Exception |
| 159 | */ |
| 160 | public function getDeliveryColumns() |
| 161 | { |
| 162 | $columns = []; |
| 163 | |
| 164 | // add custom properties, it contains the group property as well |
| 165 | $customProps = $this |
| 166 | ->getClass($this->delivery->getOnePropertyValue($this->getProperty(OntologyRdf::RDF_TYPE))) |
| 167 | ->getProperties(); |
| 168 | |
| 169 | $deliveryProps = array_merge($this->deliveryProperties, $customProps); |
| 170 | |
| 171 | foreach ($deliveryProps as $property) { |
| 172 | $property = $this->getProperty($property); |
| 173 | $loginCol = new ContextTypePropertyColumn(ContextTypePropertyColumn::CONTEXT_TYPE_DELIVERY, $property); |
| 174 | |
| 175 | if ($property->getUri() == OntologyRdfs::RDFS_LABEL) { |
| 176 | $loginCol->label = __('Delivery'); |
| 177 | } |
| 178 | |
| 179 | $columns[] = $loginCol->toArray(); |
| 180 | } |
| 181 | |
| 182 | return $columns; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Get delivery execution columns to be exported |
| 187 | */ |
| 188 | public function getDeliveryExecutionColumns() |
| 189 | { |
| 190 | return [ |
| 191 | [ |
| 192 | 'type' => DeliveryExecutionColumn::class, |
| 193 | 'label' => self::LABEL_ID_DELIVERY_EXECUTION, |
| 194 | 'contextId' => 'delivery_execution', |
| 195 | 'variableIdentifier' => DeliveryExecutionDataProvider::PROP_DELIVERY_EXECUTION_ID |
| 196 | ], |
| 197 | [ |
| 198 | 'type' => DeliveryExecutionColumn::class, |
| 199 | 'label' => self::LABEL_START_DELIVERY_EXECUTION, |
| 200 | 'contextId' => 'delivery_execution', |
| 201 | 'variableIdentifier' => DeliveryExecutionDataProvider::PROP_STARTED_AT |
| 202 | ], |
| 203 | [ |
| 204 | 'type' => DeliveryExecutionColumn::class, |
| 205 | 'label' => 'End Delivery Execution', |
| 206 | 'contextId' => 'delivery_execution', |
| 207 | 'variableIdentifier' => DeliveryExecutionDataProvider::PROP_FINISHED_AT, |
| 208 | ], |
| 209 | ]; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Returns all grade columns to be exported. |
| 214 | * |
| 215 | * @return array |
| 216 | * @throws \RuntimeException |
| 217 | */ |
| 218 | public function getGradeColumns() |
| 219 | { |
| 220 | return $this->resultsService->getVariableColumns( |
| 221 | $this->delivery, |
| 222 | \taoResultServer_models_classes_OutcomeVariable::class |
| 223 | ); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Returns all response columns to be exported. |
| 228 | * |
| 229 | * @return array |
| 230 | * @throws \RuntimeException |
| 231 | */ |
| 232 | public function getResponseColumns() |
| 233 | { |
| 234 | return $this->resultsService->getVariableColumns( |
| 235 | $this->delivery, |
| 236 | \taoResultServer_models_classes_ResponseVariable::class |
| 237 | ); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Returns all trace variables columns to be exported. |
| 242 | * |
| 243 | * @return array |
| 244 | * @throws \RuntimeException |
| 245 | */ |
| 246 | public function getTraceVariablesColumns() |
| 247 | { |
| 248 | return [ |
| 249 | [ |
| 250 | 'type' => TraceVariableColumn::class, |
| 251 | 'label' => self::LABEL_TRACE_VARIABLES, |
| 252 | 'contextId' => TraceVariableColumn::CONTEXT_IDENTIFIER, |
| 253 | 'prop' => TraceVariableColumn::CONTEXT_IDENTIFIER, |
| 254 | 'contextType' => TraceVariableDataProvider::PROP_TRACE_VARIABLE, |
| 255 | ] |
| 256 | ]; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * @return array |
| 261 | * @throws \core_kernel_persistence_Exception |
| 262 | */ |
| 263 | public function getAll() |
| 264 | { |
| 265 | return array_merge( |
| 266 | $this->getTestTakerColumns(), |
| 267 | $this->getDeliveryColumns(), |
| 268 | $this->getGradeColumns(), |
| 269 | $this->getResponseColumns(), |
| 270 | $this->getDeliveryExecutionColumns() |
| 271 | ); |
| 272 | } |
| 273 | } |