*/ class ResultsExporter implements ServiceLocatorAwareInterface { use OntologyAwareTrait; use ServiceLocatorAwareTrait; private $exportStrategy; /** * @var ResultsService */ private $resultsService; /** * ResultsExporter constructor. * @param $resource * @param ResultsService $resultsService * @param DeliveryResultsExporterFactoryInterface|null $deliveryResultsExporterFactory * @throws common_exception_NotFound */ public function __construct($resource, ResultsService $resultsService, DeliveryResultsExporterFactoryInterface $deliveryResultsExporterFactory = null) { $resource = $this->getResource($resource); if ($deliveryResultsExporterFactory === null) { $deliveryResultsExporterFactory = new DeliveryCsvResultsExporterFactory(); } if ($resource->isClass()) { $this->exportStrategy = new MultipleDeliveriesResultsExporter($this->getClass($resource->getUri()), $resultsService, $deliveryResultsExporterFactory); } else { $this->exportStrategy = $deliveryResultsExporterFactory->getDeliveryResultsExporter( $resource, $resultsService ); } $this->resultsService = $resultsService; } /** * @return ResultsExporterInterface */ public function getExporter() { $this->exportStrategy->setServiceLocator($this->getServiceLocator()); return $this->exportStrategy; } /** * @param string|array $columnsToExport * @return ResultsExporter */ public function setColumnsToExport($columnsToExport) { $this->getExporter()->setColumnsToExport($columnsToExport); return $this; } /** * @param string $variableToExport * @return ResultsExporter */ public function setVariableToExport($variableToExport) { $this->getExporter()->setVariableToExport($variableToExport); return $this; } public function setFiltersToExport($filters) { $this->getExporter()->setFiltersToExport($filters); return $this; } /** * @param null|string $destination * @return string */ public function export($destination = null) { return $this->getExporter()->export($destination); } /** * @return CallbackTaskInterface */ public function createExportTask() { /** @var QueueDispatcherInterface $queueDispatcher */ $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); $columns = []; // we need to convert every column object into array first foreach ($this->getExporter()->getColumnsToExport() as $column) { $columns[] = $column->toArray(); } $label = $this->exportStrategy->getResourceToExport()->isClass() ? __('%s results export for delivery class "%s"', $this->exportStrategy->getResultFormat(), $this->exportStrategy->getResourceToExport()->getLabel()) : __('%s results export for delivery "%s"', $this->exportStrategy->getResultFormat(), $this->exportStrategy->getResourceToExport()->getLabel()); return $queueDispatcher->createTask( new ExportDeliveryResults(), [ $this->getExporter()->getResourceToExport()->getUri(), $columns, $this->getExporter()->getVariableToExport(), $this->getExporter()->getFiltersToExport(), $this->exportStrategy->getResultFormat() ], $label ); } }