From 24fd2bdc00bccc7e9d4001bd892983ef57112e3f Mon Sep 17 00:00:00 2001 From: Christoph Ludolf Date: Fri, 25 Oct 2024 12:28:52 +0200 Subject: [PATCH] Test: Removed test export options (csv results, xml results, plugins) from export tab. Removed test question pool export option (excel) from export tab. Fixed file paths of test archive export option. Removed corresponding code from gui classes. --- .../Test/classes/class.ilTestExportGUI.php | 62 ------ .../classes/class.ilTestExportOptionARC.php | 21 +- .../classes/class.ilTestExportOptionCSV.php | 180 --------------- .../class.ilTestExportOptionPlugins.php | 208 ------------------ .../class.ilTestExportOptionXMLRES.php | 191 ---------------- .../classes/class.ilObjQuestionPoolGUI.php | 2 +- ...ass.ilTestQuestionPoolExportOptionXLSX.php | 182 --------------- 7 files changed, 8 insertions(+), 838 deletions(-) delete mode 100644 components/ILIAS/Test/classes/class.ilTestExportOptionCSV.php delete mode 100644 components/ILIAS/Test/classes/class.ilTestExportOptionPlugins.php delete mode 100644 components/ILIAS/Test/classes/class.ilTestExportOptionXMLRES.php delete mode 100644 components/ILIAS/TestQuestionPool/classes/class.ilTestQuestionPoolExportOptionXLSX.php diff --git a/components/ILIAS/Test/classes/class.ilTestExportGUI.php b/components/ILIAS/Test/classes/class.ilTestExportGUI.php index 39e13419b02e..827068c4c188 100755 --- a/components/ILIAS/Test/classes/class.ilTestExportGUI.php +++ b/components/ILIAS/Test/classes/class.ilTestExportGUI.php @@ -37,7 +37,6 @@ */ class ilTestExportGUI extends ilExportGUI { - protected array $active_export_plugins; protected UIServices $ui; public function __construct( @@ -54,70 +53,9 @@ public function __construct( private readonly ilTestHTMLGenerator $html_generator, private readonly array $selected_files, ) { - $this->active_export_plugins = iterator_to_array($active_export_plugins); parent::__construct($parent_gui, null); } - public function executeCommand(): void - { - $cmd = $this->ctrl->getCmd(); - if ( - $cmd === "exportPlugin" || - $cmd === "showExportPluginMenu" - ) { - $this->$cmd(); - return; - } - parent::executeCommand(); - } - - protected function buildExportPluginMenuForm(): StandardForm - { - $this->lng->loadLanguageModule('exp'); - $items = []; - foreach ($this->active_export_plugins as $plugin) { - /** @var ilPlugin $plugin */ - $items[$plugin->getId()] = $plugin->getFormatLabel(); - } - $select = $this->ui_factory->input()->field()->select($this->lng->txt("export_type"), $items) - ->withRequired(true); - $section = $this->ui_factory->input()->field()->section( - [$select], - $this->lng->txt("export_options") - ); - return $this->ui_factory->input()->container()->form()->standard( - $this->ctrl->getLinkTarget($this, "exportPlugin"), - [$section] - )->withSubmitLabel($this->lng->txt("export")); - } - - protected function exportPlugin(): void - { - $form = $this->buildExportPluginMenuForm()->withRequest($this->http->request()); - $plugin = null; - if (!is_null($form->getData())) { - $plugin_id = $form->getData()[0][0]; - foreach ($this->active_export_plugins as $current_plugin) { - if ($current_plugin->getId() === $plugin_id) { - $plugin = $current_plugin; - break; - } - } - } - if (is_null($form->getData())) { - $this->tpl->setContent($this->ui_renderer->render($form)); - return; - } - $plugin->export(); - $this->ctrl->redirectByClass(ilExportGUI::class, ilExportGUI::CMD_LIST_EXPORT_FILES); - } - - public function showExportPluginMenu(): void - { - $form = $this->buildExportPluginMenuForm(); - $this->tpl->setContent($this->ui_renderer->render($form)); - } - /** * @return ilTestExportTableGUI */ diff --git a/components/ILIAS/Test/classes/class.ilTestExportOptionARC.php b/components/ILIAS/Test/classes/class.ilTestExportOptionARC.php index db7474661955..e6ffd0eb7bf7 100644 --- a/components/ILIAS/Test/classes/class.ilTestExportOptionARC.php +++ b/components/ILIAS/Test/classes/class.ilTestExportOptionARC.php @@ -140,28 +140,21 @@ public function onExportOptionSelected( protected function getExportFiles( string $directory ): array { - $file = []; + $files = []; try { - $h_dir = dir($directory); - while ($entry = $h_dir->read()) { + foreach (scandir($directory) as $file) { if ( - $entry !== "." && - $entry !== ".." && - substr($entry, -4) === ".zip" + in_array($file, ['.', '..']) || + !str_ends_with($file, ".zip") ) { - $ts = substr($entry, 0, strpos($entry, "__")); - $file[$entry . $this->getExportType()] = [ - "type" => $this->getExportType(), - "file" => $entry, - "size" => (int) filesize($directory . "/" . $entry), - "timestamp" => (int) $ts - ]; + continue; } + $files[$file] = ["file" => $file]; } } catch (Exception $e) { } - return $file; + return $files; } protected function getDirectory( diff --git a/components/ILIAS/Test/classes/class.ilTestExportOptionCSV.php b/components/ILIAS/Test/classes/class.ilTestExportOptionCSV.php deleted file mode 100644 index f7514423011b..000000000000 --- a/components/ILIAS/Test/classes/class.ilTestExportOptionCSV.php +++ /dev/null @@ -1,180 +0,0 @@ -lng = $DIC->language(); - parent::init($DIC); - } - - public function getExportType(): string - { - return 'Results'; - } - - public function getExportOptionId(): string - { - return 'test_exp_option_csv'; - } - - public function getSupportedRepositoryObjectTypes(): array - { - return ['tst']; - } - - public function getLabel(): string - { - return $this->lng->txt('ass_create_export_test_results'); - } - - public function onDeleteFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", $file_identifier->getIdentifier()); - $file[1] = basename($file[1]); - $export_dir = $this->getDirectory($object_id, $context->exportObject()->getType()); - $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]); - $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4); - if (is_file($exp_file)) { - unlink($exp_file); - } - if ( - is_dir($exp_dir) and - count(scandir($exp_dir)) === 2 - ) { - ilFileUtils::delDir($exp_dir); - } - } - } - - public function onDownloadFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getDirectory($object_id, $context->exportObject()->getType()); - $file[1] = basename($file[1]); - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - } - - public function onDownloadWithLink( - ReferenceId $reference_id, - ilExportHandlerConsumerFileIdentifierInterface $file_identifier - ): void { - $object_id = $reference_id->toObjectId(); - $type = ilObject::_lookupType($object_id->toInt()); - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getDirectory($object_id, $type); - $file[1] = basename($file[1]); - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - - public function getFiles( - ilExportHandlerConsumerContextInterface $context - ): ilExportHandlerFileInfoCollectionInterface { - $collection_builder = $context->fileCollectionBuilder(); - $object_id = new ObjectId($context->exportObject()->getId()); - $dir = $this->getDirectory($object_id, $context->exportObject()->getType()); - $file_infos = $this->getExportFiles($dir); - foreach ($file_infos as $file_name => $file_info) { - $collection_builder = $collection_builder->withSPLFileInfo( - new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]), - $object_id, - $this - ); - } - return $collection_builder->collection(); - } - - public function onExportOptionSelected( - ilExportHandlerConsumerContextInterface $context - ): void { - $context->exportGUIObject()->createTestResultsExport(); - } - - protected function getExportFiles( - string $directory - ): array { - $file = []; - try { - $h_dir = dir($directory); - while ($entry = $h_dir->read()) { - if ( - $entry !== "." && - $entry !== ".." && - ( - substr($entry, -4) === ".csv" or - substr($entry, -5) === ".xlsx" - ) - ) { - $ts = substr($entry, 0, strpos($entry, "__")); - $file[$entry . $this->getExportType()] = [ - "type" => $this->getExportType(), - "file" => $entry, - "size" => (int) filesize($directory . "/" . $entry), - "timestamp" => (int) $ts - ]; - } - } - } catch (Exception $e) { - - } - return $file; - } - - protected function getDirectory( - ObjectId $object_id, - string $export_object_type - ): string { - $dir = ilExport::_getExportDirectory( - $object_id->toInt(), - "", - $export_object_type - ); - $dir = substr($dir, 0, strlen($dir) - 1); - return $dir; - } -} diff --git a/components/ILIAS/Test/classes/class.ilTestExportOptionPlugins.php b/components/ILIAS/Test/classes/class.ilTestExportOptionPlugins.php deleted file mode 100644 index b3df6343c1a5..000000000000 --- a/components/ILIAS/Test/classes/class.ilTestExportOptionPlugins.php +++ /dev/null @@ -1,208 +0,0 @@ -lng = $DIC->language(); - $this->ui = $DIC->ui(); - $this->component_factory = $DIC['component.factory']; - parent::init($DIC); - } - - public function getExportType(): string - { - return "Plugin"; - } - - public function getExportOptionId(): string - { - return "tst_exp_option_plugin"; - } - - public function getSupportedRepositoryObjectTypes(): array - { - return ['tst']; - } - - public function getLabel(): string - { - return $this->lng->txt("obj_cmps"); - } - - public function isObjectSupported(ObjectId $object_id): bool - { - $plugin_count = 0; - foreach ($this->component_factory->getActivePluginsInSlot('texp') as $plugin) { - $plugin_count++; - } - return $plugin_count > 0; - } - - public function onDeleteFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $export_dir = $this->getExportDirectory( - $context->exportObject()->getId(), - $context->exportObject()->getType() - ); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", $file_identifier->getIdentifier()); - $file[1] = basename($file[1]); - $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]); - $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4); - if (is_file($exp_file)) { - unlink($exp_file); - } - if ( - is_dir($exp_dir) and - count(scandir($exp_dir)) === 2 - ) { - ilFileUtils::delDir($exp_dir); - } - } - } - - public function onDownloadFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $export_dir = $this->getExportDirectory( - $context->exportObject()->getId(), - $context->exportObject()->getType() - ); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", trim($file_identifier->getIdentifier())); - $file[1] = basename($file[1]); - if (!file_exists($export_dir . "/" . $file[1])) { - continue; - } - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - } - - public function onDownloadWithLink( - ReferenceId $reference_id, - ilExportHandlerConsumerFileIdentifierInterface $file_identifier - ): void { - $object_id = $reference_id->toObjectId()->toInt(); - $type = ilObject::_lookupType($object_id); - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getExportDirectory( - $object_id, - $type - ); - $file[1] = basename($file[1]); - if (!file_exists($export_dir . "/" . $file[1])) { - return; - } - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - - public function getFiles( - ilExportHandlerConsumerContextInterface $context - ): ilExportHandlerFileInfoCollectionInterface { - $collection_builder = $context->fileCollectionBuilder(); - $dir = $this->getExportDirectory( - $context->exportObject()->getId(), - $context->exportObject()->getType() - ); - foreach ($this->component_factory->getActivePluginsInSlot('texp') as $plugin) { - /** @var ilTestExportPlugin $plugin */ - $file_infos = $this->getFileInfoForPlugin( - $plugin, - $dir - ); - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_infos as $file_name => $file_info) { - $collection_builder = $collection_builder->withSPLFileInfo( - new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]), - $object_id, - $this - ); - } - } - return $collection_builder->collection(); - } - - public function onExportOptionSelected( - ilExportHandlerConsumerContextInterface $context - ): void { - $this->ctrl->redirectByClass(ilTestExportGUI::class, "showExportPluginMenu"); - } - - protected function getExportDirectory( - int $object_id, - string $object_type - ): string { - $dir = ilExport::_getExportDirectory( - $object_id, - "", - $object_type - ); - $dir = substr($dir, 0, strlen($dir) - 1); - return $dir; - } - - protected function getFileInfoForPlugin( - ilTestExportPlugin $plugin, - string $export_dir_path, - ): array { - $file_infos = []; - if (!is_dir($export_dir_path)) { - return $file_infos; - } - foreach (scandir($export_dir_path) as $file) { - $file_path = $export_dir_path . DIRECTORY_SEPARATOR . $file; - if ( - in_array($file, ['.', '..']) or - is_dir($file_path) or - !str_contains($file, $plugin->getPluginName()) - ) { - continue; - } - $file_infos[$file_path] = [ - "file" => $file, - ]; - } - return $file_infos; - } -} diff --git a/components/ILIAS/Test/classes/class.ilTestExportOptionXMLRES.php b/components/ILIAS/Test/classes/class.ilTestExportOptionXMLRES.php deleted file mode 100644 index fc96c348a1bb..000000000000 --- a/components/ILIAS/Test/classes/class.ilTestExportOptionXMLRES.php +++ /dev/null @@ -1,191 +0,0 @@ -lng = $DIC->language(); - parent::init($DIC); - } - - public function getExportType(): string - { - return 'ZIP Results'; - } - - public function getExportOptionId(): string - { - return 'test_exp_option_xmlres'; - } - - public function getSupportedRepositoryObjectTypes(): array - { - return ['tst']; - } - - public function getLabel(): string - { - return $this->lng->txt('ass_create_export_file_with_results'); - } - - public function onDeleteFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", $file_identifier->getIdentifier()); - $file[1] = basename($file[1]); - $export_dir = $this->getDirectory($object_id, $context->exportObject()->getType()); - $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]); - $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4); - if (is_file($exp_file)) { - unlink($exp_file); - } - if ( - is_dir($exp_dir) and - count(scandir($exp_dir)) === 2 - ) { - ilFileUtils::delDir($exp_dir); - } - } - } - - public function onDownloadFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getDirectory($object_id, $context->exportObject()->getType()); - $file[1] = basename($file[1]); - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - } - - public function onDownloadWithLink( - ReferenceId $reference_id, - ilExportHandlerConsumerFileIdentifierInterface $file_identifier - ): void { - $object_id = $reference_id->toObjectId(); - $type = ilObject::_lookupType($object_id->toInt()); - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getDirectory($object_id, $type); - $file[1] = basename($file[1]); - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - - public function getFiles( - ilExportHandlerConsumerContextInterface $context - ): ilExportHandlerFileInfoCollectionInterface { - $collection_builder = $context->fileCollectionBuilder(); - $object_id = new ObjectId($context->exportObject()->getId()); - $dir = $this->getDirectory($object_id, $context->exportObject()->getType()); - $file_infos = $this->getExportFiles($dir); - foreach ($file_infos as $file_name => $file_info) { - $collection_builder = $collection_builder->withSPLFileInfo( - new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]), - $object_id, - $this - ); - } - return $collection_builder->collection(); - } - - public function onExportOptionSelected( - ilExportHandlerConsumerContextInterface $context - ): void { - $context->exportGUIObject()->createTestExportWithResults(); - } - - protected function getExportFiles( - string $directory - ): array { - $file = []; - try { - $h_dir = dir($directory); - while ($entry = $h_dir->read()) { - if ( - $entry === "." || - $entry === ".." || - substr($entry, -4) !== ".zip" - ) { - continue; - } - $zip_archive = new ZipArchive(); - $zip_archive->open($directory . DIRECTORY_SEPARATOR . $entry); - $is_result = false; - for ($i = 0; $i < $zip_archive->numFiles; $i++) { - $stat = $zip_archive->statIndex($i); - if (str_contains(basename($stat['name']), "results")) { - $is_result = true; - break; - } - } - if (!$is_result) { - continue; - } - $ts = substr($entry, 0, strpos($entry, "__")); - $file[$entry . $this->getExportType()] = [ - "type" => $this->getExportType(), - "file" => $entry, - "size" => (int) filesize($directory . "/" . $entry), - "timestamp" => (int) $ts - ]; - } - } catch (Exception $e) { - - } - return $file; - } - - protected function getDirectory( - ObjectId $object_id, - string $export_object_type - ): string { - $dir = ilExport::_getExportDirectory( - $object_id->toInt(), - "", - $export_object_type - ); - $dir = substr($dir, 0, strlen($dir) - 1); - return $dir; - } -} diff --git a/components/ILIAS/TestQuestionPool/classes/class.ilObjQuestionPoolGUI.php b/components/ILIAS/TestQuestionPool/classes/class.ilObjQuestionPoolGUI.php index 863b4fe61828..a1dfe0a1a9f7 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.ilObjQuestionPoolGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.ilObjQuestionPoolGUI.php @@ -1312,7 +1312,7 @@ public function moveQuestions(array $ids): void } } - public function createExportExcelObject(): void + public function createExportExcel(): void { $rbacsystem = $this->rbac_system; if ($rbacsystem->checkAccess('write', $this->qplrequest->getRefId())) { diff --git a/components/ILIAS/TestQuestionPool/classes/class.ilTestQuestionPoolExportOptionXLSX.php b/components/ILIAS/TestQuestionPool/classes/class.ilTestQuestionPoolExportOptionXLSX.php deleted file mode 100644 index 5136f06e73c6..000000000000 --- a/components/ILIAS/TestQuestionPool/classes/class.ilTestQuestionPoolExportOptionXLSX.php +++ /dev/null @@ -1,182 +0,0 @@ -lng = $DIC->language(); - $this->ctrl = $DIC->ctrl(); - } - - public function getExportType(): string - { - return 'xlsx'; - } - - public function getExportOptionId(): string - { - return 'qpl_exp_option_xlsx'; - } - - public function getSupportedRepositoryObjectTypes(): array - { - return ['qpl']; - } - - public function getLabel(): string - { - return $this->lng->txt('qpl_export_excel'); - } - - public function onDeleteFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", $file_identifier->getIdentifier()); - $file[1] = basename($file[1]); - $export_dir = $this->getDirectory( - $context->exportObject()->getId(), - $context->exportObject()->getType() - ); - $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]); - $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 5); - if (is_file($exp_file)) { - unlink($exp_file); - } - if ( - is_dir($exp_dir) and - count(scandir($exp_dir)) === 2 - ) { - ilFileUtils::delDir($exp_dir); - } - } - } - - public function onDownloadFiles( - ilExportHandlerConsumerContextInterface $context, - ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers - ): void { - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_identifiers as $file_identifier) { - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getDirectory($object_id->toInt(), $context->exportObject()->getType()); - $file[1] = basename($file[1]); - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - } - - public function onDownloadWithLink( - ReferenceId $reference_id, - ilExportHandlerConsumerFileIdentifierInterface $file_identifier - ): void { - $object_id = $reference_id->toObjectId(); - $type = ilObject::_lookupType($object_id->toInt()); - $file = explode(":", trim($file_identifier->getIdentifier())); - $export_dir = $this->getDirectory($object_id->toInt(), $type); - $file[1] = basename($file[1]); - ilFileDelivery::deliverFileLegacy( - $export_dir . "/" . $file[1], - $file[1] - ); - } - - public function getFiles( - ilExportHandlerConsumerContextInterface $context - ): ilExportHandlerFileInfoCollectionInterface { - $collection_builder = $context->fileCollectionBuilder(); - $dir = $this->getDirectory( - $context->exportObject()->getId(), - $context->exportObject()->getType() - ); - $file_infos = $this->getExportFiles($dir); - $object_id = new ObjectId($context->exportObject()->getId()); - foreach ($file_infos as $file_name => $file_info) { - $collection_builder = $collection_builder->withSPLFileInfo( - new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]), - $object_id, - $this - ); - } - return $collection_builder->collection(); - } - - public function onExportOptionSelected( - ilExportHandlerConsumerContextInterface $context - ): void { - $this->ctrl->redirectByClass(ilObjQuestionPoolGUI::class, "createExportExcelObject"); - } - - protected function getExportFiles( - string $directory - ): array { - $file = []; - try { - $h_dir = dir($directory); - while ($entry = $h_dir->read()) { - if ( - $entry !== "." && - $entry !== ".." && - substr($entry, -5) === ".xlsx" - ) { - $ts = substr($entry, 0, strpos($entry, "__")); - $file[$entry . $this->getExportType()] = [ - "type" => $this->getExportType(), - "file" => $entry, - "size" => (int) filesize($directory . "/" . $entry), - "timestamp" => (int) $ts - ]; - } - } - } catch (Exception $e) { - - } - return $file; - } - - protected function getDirectory( - int $object_id, - string $object_type - ): string { - $dir = ilExport::_getExportDirectory( - $object_id, - "", - $object_type - ); - $dir .= "xlsx"; - return $dir; - } -}