diff --git a/.DS_Store b/.DS_Store index 9b2ae09..8ef6a8a 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/com_eis/.DS_Store b/com_eis/.DS_Store index a277ae7..81efcaa 100644 Binary files a/com_eis/.DS_Store and b/com_eis/.DS_Store differ diff --git a/com_eis/Archiv.zip b/com_eis/Archiv.zip index b55cef6..f9d4b23 100644 Binary files a/com_eis/Archiv.zip and b/com_eis/Archiv.zip differ diff --git a/com_eis/eis.xml b/com_eis/eis.xml index fef6bb4..fff3d50 100644 --- a/com_eis/eis.xml +++ b/com_eis/eis.xml @@ -1,13 +1,15 @@ - - - - - install/sql/mysql/install.utf8.sql - - - + + + install/sql/mysql/install.utf8.sql + + + + + install/sql/mysql/uninstall.mysql.utf8.sql + + com_eis 2025-07-23 Thomas Spohr powert by OpenAI @@ -15,17 +17,17 @@ EIS Minimal-Komponente EIS\Component\EIS - COM_EIS_MENU + COM_EIS_MENU - - COM_EIS_MAIN + COM_EIS_MAIN + COM_EIS_CONFIG - + sql src tmpl - install + install language services diff --git a/com_eis/install/.DS_Store b/com_eis/install/.DS_Store index 98fec11..2ea210a 100644 Binary files a/com_eis/install/.DS_Store and b/com_eis/install/.DS_Store differ diff --git a/com_eis/install/sql/.DS_Store b/com_eis/install/sql/.DS_Store index 5008ddf..8c581de 100644 Binary files a/com_eis/install/sql/.DS_Store and b/com_eis/install/sql/.DS_Store differ diff --git a/com_eis/install/sql/mysql/install.utf8.sql b/com_eis/install/sql/mysql/install.utf8.sql index 518d930..4fa17c6 100644 --- a/com_eis/install/sql/mysql/install.utf8.sql +++ b/com_eis/install/sql/mysql/install.utf8.sql @@ -4,5 +4,15 @@ CREATE TABLE IF NOT EXISTS `#__eis_documents` ( `path` TEXT NOT NULL, `parent_id` INT UNSIGNED DEFAULT NULL, `is_folder` TINYINT(1) DEFAULT 0, + `title` VARCHAR(255) DEFAULT NULL, + `description` TEXT DEFAULT NULL, + `ordering` INT DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + +CREATE TABLE IF NOT EXISTS `#__eis_settings` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `pdf_path` TEXT NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/com_eis/install/sql/mysql/uninstall.mysql.utf8.sql b/com_eis/install/sql/mysql/uninstall.mysql.utf8.sql new file mode 100644 index 0000000..b6bd761 --- /dev/null +++ b/com_eis/install/sql/mysql/uninstall.mysql.utf8.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS `#__eis_settings`; +DROP TABLE IF EXISTS `#__eis_documents`; \ No newline at end of file diff --git a/com_eis/language/.DS_Store b/com_eis/language/.DS_Store new file mode 100644 index 0000000..2f0642a Binary files /dev/null and b/com_eis/language/.DS_Store differ diff --git a/com_eis/language/en-GB/en-GB.com_eis.ini b/com_eis/language/en-GB/en-GB.com_eis.ini index 65491ea..69c1898 100644 --- a/com_eis/language/en-GB/en-GB.com_eis.ini +++ b/com_eis/language/en-GB/en-GB.com_eis.ini @@ -4,5 +4,5 @@ COM_EIS_DOCUMENT_PATH_LABEL="Pfad zu den PDF-Dokumenten" COM_EIS_SCAN_DOCUMENTS="Dokumente einlesen" COM_EIS_MAIN="EIS Hauptansicht" COM_EIS_MENU="EIS" -COM_EIS_SETTINGS="Einstellungen" +COM_EIS_CONFIG="Einstellungen" COM_EIS_MAINTENANCE="Wartung" diff --git a/com_eis/src/.DS_Store b/com_eis/src/.DS_Store index b368cc3..07ebed8 100644 Binary files a/com_eis/src/.DS_Store and b/com_eis/src/.DS_Store differ diff --git a/com_eis/src/Controller/ConfigController.php b/com_eis/src/Controller/ConfigController.php new file mode 100644 index 0000000..3f05047 --- /dev/null +++ b/com_eis/src/Controller/ConfigController.php @@ -0,0 +1,46 @@ +getInput(); + $db = Factory::getDbo(); + + // Eingabe + $pdfPath = $input->getString('pdf_path', ''); + + // Existiert ein Eintrag? + $query = $db->getQuery(true) + ->select('COUNT(*)') + ->from($db->quoteName('#__eis_settings')); + $db->setQuery($query); + $exists = (int) $db->loadResult() > 0; + + if ($exists) { + // Update + $query = $db->getQuery(true) + ->update($db->quoteName('#__eis_settings')) + ->set($db->quoteName('pdf_path') . ' = ' . $db->quote($pdfPath)); + } else { + // Insert + $query = $db->getQuery(true) + ->insert($db->quoteName('#__eis_settings')) + ->columns([$db->quoteName('pdf_path')]) + ->values($db->quote($pdfPath)); + } + + $db->setQuery($query)->execute(); + + $app->enqueueMessage('Pfad gespeichert: ' . $pdfPath, 'message'); + $this->setRedirect(Route::_('index.php?option=com_eis&view=config', false)); + } +} diff --git a/com_eis/src/Controller/DisplayController.php b/com_eis/src/Controller/DisplayController.php index ebdee98..019c7c7 100644 --- a/com_eis/src/Controller/DisplayController.php +++ b/com_eis/src/Controller/DisplayController.php @@ -3,51 +3,53 @@ namespace EIS\Component\EIS\Administrator\Controller; \defined('_JEXEC') or die; -use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\Database\DatabaseDriver; class DisplayController extends BaseController { protected $default_view = 'main'; /** - * Endpoint to generate JSON of PDF directory tree + * Button-Aktion: PDF-Verzeichnis scannen und in Datenbank speichern */ public function scan(): void { - $input = Factory::getApplication()->input; - // Default to PDF folder if no path provided - $defaultPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'pdf'; - $path = $input->getString('path', $defaultPath); - $data = $this->scanFolder($path); + $db = Factory::getDbo(); - // Encode JSON - $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); + // Pfad aus Tabelle laden + $query = $db->getQuery(true) + ->select($db->quoteName('pdf_path')) + ->from($db->quoteName('#__eis_settings')) + ->order('id ASC') + ->setLimit(1); - // Determine output file path - $outputFile = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'com_eis' . DIRECTORY_SEPARATOR . 'documents.json'; - // Ensure directory exists - $dir = dirname($outputFile); - if (!is_dir($dir)) { - mkdir($dir, 0755, true); + $db->setQuery($query); + $path = $db->loadResult(); + + if (!$path || !is_dir($path)) { + Factory::getApplication()->enqueueMessage('Pfad ungültig oder nicht gesetzt: ' . $path, 'error'); + $this->setRedirect('index.php?option=com_eis&view=main'); + return; } - // Write JSON to file - file_put_contents($outputFile, $json); - // Provide feedback and redirect - Factory::getApplication() - ->enqueueMessage('JSON file saved to ' . $outputFile, 'message'); - // Ausgabe auch im Bachkend - Factory::getApplication()->setUserState('com_eis.pdfdata', $data); + // Verzeichnis rekursiv scannen + $data = $this->scanFolder($path); + + // Alte Einträge löschen + $db->truncateTable('#__eis_documents'); + + // In Datenbank speichern + $this->saveToDb($data, null, $db); + + // Erfolgsmeldung + Factory::getApplication()->enqueueMessage('PDF-Struktur erfolgreich gespeichert.', 'message'); $this->setRedirect('index.php?option=com_eis&view=main'); } /** - * Recursively scans a directory and returns an array structure - * with names and absolute paths for PDF files. - * - * @param string $dir Absolute filesystem path - * @return array Structure: [ ['name'=>'FolderName','children'=>[...] ], ['name'=>'file.pdf','path'=>'/abs/path/file.pdf'] ] + * Rekursive Verzeichnisanalyse */ private function scanFolder(string $dir): array { @@ -63,13 +65,11 @@ class DisplayController extends BaseController $fullPath = $dir . DIRECTORY_SEPARATOR . $file; if (is_dir($fullPath)) { - // Directory: include name and children $result[] = [ 'name' => $file, 'children' => $this->scanFolder($fullPath) ]; } elseif (is_file($fullPath) && strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'pdf') { - // File: include name and absolute path $result[] = [ 'name' => $file, 'path' => $fullPath @@ -79,4 +79,31 @@ class DisplayController extends BaseController return $result; } + + /** + * Struktur rekursiv in die Datenbank schreiben + */ + private function saveToDb(array $items, ?int $parentId, DatabaseDriver $db): void + { + foreach ($items as $item) { + $name = $db->quote($item['name']); + $path = $db->quote($item['path'] ?? ''); // Leerer String statt NULL + $parent = $parentId !== null ? (int) $parentId : 'NULL'; + $isFolder = isset($item['children']) ? 1 : 0; + + $query = $db->getQuery(true) + ->insert($db->quoteName('#__eis_documents')) + ->columns(['name', 'path', 'parent_id', 'is_folder']) + ->values("$name, $path, $parent, $isFolder"); + + $db->setQuery($query); + $db->execute(); + + $insertedId = $db->insertid(); + + if ($isFolder && !empty($item['children'])) { + $this->saveToDb($item['children'], $insertedId, $db); + } + } + } } diff --git a/com_eis/src/View/.DS_Store b/com_eis/src/View/.DS_Store new file mode 100644 index 0000000..b8dba7a Binary files /dev/null and b/com_eis/src/View/.DS_Store differ diff --git a/com_eis/src/View/Config/HtmlView.php b/com_eis/src/View/Config/HtmlView.php new file mode 100644 index 0000000..b0f1f90 --- /dev/null +++ b/com_eis/src/View/Config/HtmlView.php @@ -0,0 +1,32 @@ +getQuery(true) + ->select('*') + ->from($db->quoteName('#__eis_settings')) + ->setLimit(1); + + $db->setQuery($query); + $this->item = $db->loadAssoc(); + + parent::display($tpl); + } + + public function getItem() + { + return $this->item; + } +} diff --git a/com_eis/tmpl/.DS_Store b/com_eis/tmpl/.DS_Store new file mode 100644 index 0000000..ad922eb Binary files /dev/null and b/com_eis/tmpl/.DS_Store differ diff --git a/com_eis/tmpl/config/default.php b/com_eis/tmpl/config/default.php new file mode 100644 index 0000000..7c485e0 --- /dev/null +++ b/com_eis/tmpl/config/default.php @@ -0,0 +1,38 @@ +getItem(); +$pdfPath = $item['pdf_path'] ?? ''; +?> + +

+ +
+
+
+ + +
+ +
+ +
+
+ +
+
+ +
+ +
+ + +
diff --git a/com_eis/tmpl/main/default.php b/com_eis/tmpl/main/default.php index 32dde48..55a7148 100644 --- a/com_eis/tmpl/main/default.php +++ b/com_eis/tmpl/main/default.php @@ -1,5 +1,6 @@
-
- -
- -
-
+
-
+
@@ -45,4 +41,4 @@ function renderTree($items) } return $html; } -?> +?> \ No newline at end of file diff --git a/mod_pdf_tree/.DS_Store b/mod_pdf_tree/.DS_Store index 26e52f3..d95efbe 100644 Binary files a/mod_pdf_tree/.DS_Store and b/mod_pdf_tree/.DS_Store differ diff --git a/mod_pdf_tree/Archiv.zip b/mod_pdf_tree/Archiv.zip index af13493..8032246 100644 Binary files a/mod_pdf_tree/Archiv.zip and b/mod_pdf_tree/Archiv.zip differ diff --git a/mod_pdf_tree/helper.php b/mod_pdf_tree/helper.php index 4b458df..c2f74db 100644 --- a/mod_pdf_tree/helper.php +++ b/mod_pdf_tree/helper.php @@ -1,75 +1,66 @@ - getQuery(true) + ->select('*') + ->from($db->quoteName('#__eis_documents')) + ->order($db->quoteName('ordering') . ' ASC'); + + $rows = $db->setQuery($query)->loadAssocList(); + + // Nach parent_id gruppieren + $grouped = []; + foreach ($rows as $row) { + $pid = $row['parent_id'] === null ? null : (int) $row['parent_id']; + $grouped[$pid][] = $row; } - $json = file_get_contents($file); - $data = json_decode($json, true); - - if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) { - return []; - } - - return $data; + return $grouped; } /** - * Baumstruktur als HTML generieren (rekursiv) - * @param array $items Eingelesene JSON-Daten - * @return string HTML-Ausgabe + * Hauptfunktion zum Rendern des Baums */ - public static function renderTree(array $items): string + + public static function renderTree(array $items, int $parentId = null): string { + if (!isset($items[$parentId])) { + return ''; + } + $html = '