getServiceLocator()->get(EventManager::SERVICE_ID); } public function index() { $testUri = tao_helpers_Uri::decode($this->getRequestParameter('uri')); $test = $this->getResource($testUri); $this->setData('label', $test->getLabel()); $this->setData('rootClassUri', DeliveryAssemblyService::CLASS_URI); $this->setData('testUri', $testUri); $this->setView('Publish/index.tpl'); } public function publish() { try { $parsedBody = $this->getPsrRequest()->getParsedBody(); $testUri = $parsedBody['testUri'] ?? null; $classUri = $parsedBody['classUri'] ?? null; $test = $this->getResource($testUri); $testService = $this->getTestService(); $testItems = $testService->getTestItems($test); if (empty($testItems)) { throw new RuntimeException( __('The test "%s" does not contain any items and cannot be published.', $test->getLabel()) ); } $deliveryClass = $this->getClass($classUri); $deliveryFactoryResources = $this->getDeliveryFactory(); $initialProperties = $deliveryFactoryResources->getInitialPropertiesFromArray([OntologyRdfs::RDFS_LABEL => 'new delivery']); return $this->returnTaskJson(CompileDelivery::createTask($test, $deliveryClass, $initialProperties)); } catch (Exception $e) { return $this->returnJson([ 'success' => false, 'errorMsg' => $e instanceof UserReadableException ? $e->getUserMessage() : $e->getMessage(), 'errorCode' => $e->getCode(), ]); } } /** * @return TestsService */ private function getTestService() { return $this->getServiceLocator()->get(TestsService::class); } /** * @return DeliveryFactory */ private function getDeliveryFactory() { return $this->getServiceLocator()->get(DeliveryFactory::SERVICE_ID); ; } }