getServiceLocator()->get(EventManager::SERVICE_ID); } /** * initialize the classUri and execute the upload action * * @requiresRight id WRITE * @requiresRight classUri WRITE */ public function index() { $importer = $this->getCurrentImporter(); $this->propagate($importer); $formContainer = new tao_actions_form_Import( $importer, $this->getAvailableImportHandlers(), $this->getCurrentClass() ); $importForm = $formContainer->getForm(); if ($importForm->isSubmited() && $importForm->isValid()) { /** @var QueueDispatcher $queueDispatcher */ $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcher::SERVICE_ID); $task = $queueDispatcher->createTask( new ImportByHandler(), [ ImportByHandler::PARAM_IMPORT_HANDLER => get_class($importer), ImportByHandler::PARAM_FORM_VALUES => $importer instanceof TaskParameterProviderInterface ? $importer->getTaskParameters($importForm) : [], ImportByHandler::PARAM_PARENT_CLASS => $this->getCurrentClass()->getUri(), ImportByHandler::PARAM_OWNER => \common_session_SessionManager::getSession()->getUser()->getIdentifier(), ], __('Import a %s into "%s"', $importer->getLabel(), $this->getCurrentClass()->getLabel()) ); return $this->returnTaskJson($task); } $context = Context::getInstance(); $this->setData('import_extension', $context->getExtensionName()); $this->setData('import_module', $context->getModuleName()); $this->setData('import_action', $context->getActionName()); $this->setData('myForm', $importForm->render()); $this->setData('formTitle', __('Import ')); $this->setView('form/import.tpl', 'tao'); } /** * Returns the currently selected import handler * or the import handler to use by default * * @return tao_models_classes_import_ImportHandler */ protected function getCurrentImporter() { $handlers = $this->getAvailableImportHandlers(); if ($this->hasRequestParameter('importHandler')) { foreach ($handlers as $importHandler) { if (get_class($importHandler) == $_POST['importHandler']) { return $importHandler; } } } $availableImportHandlers = $this->getAvailableImportHandlers(); $currentImporter = reset($availableImportHandlers); return $currentImporter; } /** * Gets the available import handlers for this module * Should be overwritten by extensions that want to provide additional ImportHandlers * * @return tao_models_classes_import_ImportHandler[] */ protected function getAvailableImportHandlers() { if (empty($this->availableHandlers)) { $this->availableHandlers = [ new tao_models_classes_import_RdfImporter(), new tao_models_classes_import_CsvImporter() ]; } return $this->availableHandlers; } /** * Helper to get the selected class, needs to be passed as hidden field in the form */ protected function getCurrentClass() { return $this->getClass(tao_helpers_Uri::decode($this->getRequestParameter('classUri'))); } protected function getValidators() { return []; } }