Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryExecutionDataProvider | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
272 | |
0.00% |
0 / 1 |
| prepare | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
156 | |||
| getValue | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getServiceLocator | |
0.00% |
0 / 1 |
|
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) 2019 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * @author Oleksandr Zagovorychev <zagovorichev@gmail.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoOutcomeUi\model\table; |
| 24 | |
| 25 | use core_kernel_classes_Resource; |
| 26 | use oat\oatbox\service\ServiceManager; |
| 27 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 28 | use tao_models_classes_table_Column; |
| 29 | use tao_models_classes_table_DataProvider; |
| 30 | |
| 31 | /** |
| 32 | * Short description of class |
| 33 | * |
| 34 | * @access public |
| 35 | * @package taoOutcomeUi |
| 36 | */ |
| 37 | class DeliveryExecutionDataProvider implements tao_models_classes_table_DataProvider |
| 38 | { |
| 39 | public const PROP_STARTED_AT = 'started_at'; |
| 40 | public const PROP_FINISHED_AT = 'finished_at'; |
| 41 | public const PROP_DELIVERY_EXECUTION_ID = 'delivery_execution_id'; |
| 42 | public const PROP_USER_ID = 'user_id'; |
| 43 | |
| 44 | /** |
| 45 | * @var array |
| 46 | */ |
| 47 | public $cache = []; |
| 48 | |
| 49 | /** |
| 50 | * @param $resources |
| 51 | * @param $columns |
| 52 | * @return mixed|void |
| 53 | * @throws \common_Exception |
| 54 | * @throws \common_exception_Error |
| 55 | * @throws \common_exception_NotFound |
| 56 | */ |
| 57 | public function prepare($resources, $columns) |
| 58 | { |
| 59 | $this->cache = []; |
| 60 | |
| 61 | /** @var ServiceProxy $service */ |
| 62 | $service = $this->getServiceLocator()->get(ServiceProxy::SERVICE_ID); |
| 63 | foreach ($resources as $identifier) { |
| 64 | $de = $service->getDeliveryExecution($identifier); |
| 65 | /** @var DeliveryExecutionColumn $column */ |
| 66 | foreach ($columns as $column) { |
| 67 | switch ($column->getIdentifier()) { |
| 68 | case self::PROP_STARTED_AT: |
| 69 | //$column->setContextIdentifier($identifier); |
| 70 | $this->cache[$identifier][$column->getIdentifier()] = $de->getStartTime() ?: ''; |
| 71 | break; |
| 72 | case self::PROP_FINISHED_AT: |
| 73 | //$column->setContextIdentifier($identifier); |
| 74 | $this->cache[$identifier][$column->getIdentifier()] = $de->getFinishTime() ?: ''; |
| 75 | break; |
| 76 | case self::PROP_USER_ID: |
| 77 | $this->cache[$identifier][$column->getIdentifier()] = $de->getUserIdentifier() ?: ''; |
| 78 | break; |
| 79 | case self::PROP_DELIVERY_EXECUTION_ID: |
| 80 | $this->cache[$identifier][$column->getIdentifier()] = $de->getIdentifier() ?: ''; |
| 81 | break; |
| 82 | default: |
| 83 | throw new \common_exception_Error('Undefined property ' . $column->getIdentifier()); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @param core_kernel_classes_Resource $resource |
| 91 | * @param tao_models_classes_table_Column $column |
| 92 | * @return array|string |
| 93 | */ |
| 94 | public function getValue(core_kernel_classes_Resource $resource, tao_models_classes_table_Column $column) |
| 95 | { |
| 96 | $return = []; |
| 97 | if ( |
| 98 | array_key_exists($resource->getUri(), $this->cache) |
| 99 | && array_key_exists($column->getIdentifier(), $this->cache[$resource->getUri()]) |
| 100 | ) { |
| 101 | $return[$resource->getUri()] = [$this->cache[$resource->getUri()][$column->getIdentifier()]]; |
| 102 | } else { |
| 103 | \common_Logger::d('no data for resource: ' . $resource->getUri() . ' column: ' . $column->getIdentifier()); |
| 104 | } |
| 105 | |
| 106 | return $return; |
| 107 | } |
| 108 | |
| 109 | protected function getServiceLocator() |
| 110 | { |
| 111 | return ServiceManager::getServiceManager(); |
| 112 | } |
| 113 | } |