Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ResultsExporter | |
0.00% |
0 / 49 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| getExporter | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setColumnsToExport | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setVariableToExport | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setFiltersToExport | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| export | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| createExportTask | |
0.00% |
0 / 23 |
|
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-2022 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | declare(strict_types=1); |
| 23 | |
| 24 | namespace oat\taoOutcomeUi\model\export; |
| 25 | |
| 26 | use common_exception_NotFound; |
| 27 | use oat\generis\model\OntologyAwareTrait; |
| 28 | use oat\tao\model\taskQueue\QueueDispatcherInterface; |
| 29 | use oat\tao\model\taskQueue\Task\CallbackTaskInterface; |
| 30 | use oat\taoOutcomeUi\model\ResultsService; |
| 31 | use oat\taoOutcomeUi\scripts\task\ExportDeliveryResults; |
| 32 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 33 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 34 | |
| 35 | /** |
| 36 | * ResultsExporter |
| 37 | * |
| 38 | * @author Gyula Szucs <gyula@taotesting.com> |
| 39 | */ |
| 40 | class ResultsExporter implements ServiceLocatorAwareInterface |
| 41 | { |
| 42 | use OntologyAwareTrait; |
| 43 | use ServiceLocatorAwareTrait; |
| 44 | |
| 45 | private ResultsExporterInterface $exportStrategy; |
| 46 | private ResultsService $resultsService; |
| 47 | private array $columns = []; |
| 48 | |
| 49 | /** |
| 50 | * @throws common_exception_NotFound |
| 51 | */ |
| 52 | public function __construct( |
| 53 | string $resourceUri, |
| 54 | ResultsService $resultsService, |
| 55 | DeliveryResultsExporterFactoryInterface $deliveryResultsExporterFactory = null |
| 56 | ) { |
| 57 | $resource = $this->getResource($resourceUri); |
| 58 | |
| 59 | if ($deliveryResultsExporterFactory === null) { |
| 60 | $deliveryResultsExporterFactory = new DeliveryCsvResultsExporterFactory(); |
| 61 | } |
| 62 | |
| 63 | if ($resource->isClass()) { |
| 64 | $this->exportStrategy = new MultipleDeliveriesResultsExporter( |
| 65 | $this->getClass($resource->getUri()), |
| 66 | $resultsService, |
| 67 | $deliveryResultsExporterFactory |
| 68 | ); |
| 69 | } else { |
| 70 | $this->exportStrategy = $deliveryResultsExporterFactory->getDeliveryResultsExporter( |
| 71 | $resource, |
| 72 | $resultsService |
| 73 | ); |
| 74 | } |
| 75 | $this->resultsService = $resultsService; |
| 76 | } |
| 77 | |
| 78 | public function getExporter(): ResultsExporterInterface |
| 79 | { |
| 80 | $this->exportStrategy->setServiceLocator($this->getServiceLocator()); |
| 81 | $this->exportStrategy->setColumnsToExport($this->columns); |
| 82 | |
| 83 | return $this->exportStrategy; |
| 84 | } |
| 85 | |
| 86 | public function setColumnsToExport(array $columnsToExport): self |
| 87 | { |
| 88 | $this->columns = $columnsToExport; |
| 89 | |
| 90 | return $this; |
| 91 | } |
| 92 | |
| 93 | public function setVariableToExport(string $variableToExport): self |
| 94 | { |
| 95 | $this->getExporter()->setVariableToExport($variableToExport); |
| 96 | return $this; |
| 97 | } |
| 98 | |
| 99 | public function setFiltersToExport(array $filters): self |
| 100 | { |
| 101 | $this->getExporter()->setFiltersToExport($filters); |
| 102 | return $this; |
| 103 | } |
| 104 | |
| 105 | public function export(string $destination = null): string |
| 106 | { |
| 107 | return $this->getExporter() |
| 108 | ->setColumnsToExport($this->columns) |
| 109 | ->export($destination); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return CallbackTaskInterface |
| 114 | */ |
| 115 | public function createExportTask() |
| 116 | { |
| 117 | /** @var QueueDispatcherInterface $queueDispatcher */ |
| 118 | $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); |
| 119 | |
| 120 | $label = $this->exportStrategy->getResourceToExport()->isClass() |
| 121 | ? __( |
| 122 | '%s results export for delivery class "%s"', |
| 123 | $this->exportStrategy->getResultFormat(), |
| 124 | $this->exportStrategy->getResourceToExport()->getLabel() |
| 125 | ) |
| 126 | : __( |
| 127 | '%s results export for delivery "%s"', |
| 128 | $this->exportStrategy->getResultFormat(), |
| 129 | $this->exportStrategy->getResourceToExport()->getLabel() |
| 130 | ); |
| 131 | |
| 132 | return $queueDispatcher->createTask( |
| 133 | new ExportDeliveryResults(), |
| 134 | [ |
| 135 | $this->getExporter()->getResourceToExport()->getUri(), |
| 136 | $this->columns, |
| 137 | $this->getExporter()->getVariableToExport(), |
| 138 | $this->getExporter()->getFiltersToExport(), |
| 139 | $this->exportStrategy->getResultFormat() |
| 140 | ], |
| 141 | $label |
| 142 | ); |
| 143 | } |
| 144 | } |