Dokumenteninfo wird jetzt in DB geschrieben.

This commit is contained in:
Thomas Spohr
2025-07-31 12:22:10 +02:00
parent 9c9d422380
commit 266fd69afb
23 changed files with 278 additions and 115 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
com_eis/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" method="install"> <extension type="component" method="install">
<!-- Database table for PDF entries --> <install>
<install>
<sql> <sql>
<file driver="mysql" charset="utf8">install/sql/mysql/install.utf8.sql</file> <file driver="mysql" charset="utf8">install/sql/mysql/install.utf8.sql</file>
</sql> </sql>
</install> </install>
<uninstall>
<sql>
<file driver="mysql" charset="utf8">install/sql/mysql/uninstall.mysql.utf8.sql</file>
</sql>
</uninstall>
<name>com_eis</name> <name>com_eis</name>
<creationDate>2025-07-23</creationDate> <creationDate>2025-07-23</creationDate>
<author>Thomas Spohr powert by OpenAI</author> <author>Thomas Spohr powert by OpenAI</author>
@@ -15,10 +17,10 @@
<description>EIS Minimal-Komponente</description> <description>EIS Minimal-Komponente</description>
<namespace path="src">EIS\Component\EIS</namespace> <namespace path="src">EIS\Component\EIS</namespace>
<administration> <administration>
<menu img="class:eis">COM_EIS_MENU</menu> <menu>COM_EIS_MENU</menu>
<submenu> <submenu>
<menu link="option=com_eis&amp;view=main" img="class:eis-main" alt="EIS/Main"> <menu link="option=com_eis&amp;view=main">COM_EIS_MAIN</menu>
COM_EIS_MAIN</menu> <menu link="option=com_eis&amp;view=config">COM_EIS_CONFIG</menu>
</submenu> </submenu>
<files client="administrator"> <files client="administrator">

Binary file not shown.

Binary file not shown.

View File

@@ -4,5 +4,15 @@ CREATE TABLE IF NOT EXISTS `#__eis_documents` (
`path` TEXT NOT NULL, `path` TEXT NOT NULL,
`parent_id` INT UNSIGNED DEFAULT NULL, `parent_id` INT UNSIGNED DEFAULT NULL,
`is_folder` TINYINT(1) DEFAULT 0, `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`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View File

@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS `#__eis_settings`;
DROP TABLE IF EXISTS `#__eis_documents`;

BIN
com_eis/language/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -4,5 +4,5 @@ COM_EIS_DOCUMENT_PATH_LABEL="Pfad zu den PDF-Dokumenten"
COM_EIS_SCAN_DOCUMENTS="Dokumente einlesen" COM_EIS_SCAN_DOCUMENTS="Dokumente einlesen"
COM_EIS_MAIN="EIS Hauptansicht" COM_EIS_MAIN="EIS Hauptansicht"
COM_EIS_MENU="EIS" COM_EIS_MENU="EIS"
COM_EIS_SETTINGS="Einstellungen" COM_EIS_CONFIG="Einstellungen"
COM_EIS_MAINTENANCE="Wartung" COM_EIS_MAINTENANCE="Wartung"

BIN
com_eis/src/.DS_Store vendored

Binary file not shown.

View File

@@ -0,0 +1,46 @@
<?php
namespace EIS\Component\EIS\Administrator\Controller;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
class ConfigController extends BaseController
{
public function save(): void
{
$app = Factory::getApplication();
$input = $app->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));
}
}

View File

@@ -3,51 +3,53 @@ namespace EIS\Component\EIS\Administrator\Controller;
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\Database\DatabaseDriver;
class DisplayController extends BaseController class DisplayController extends BaseController
{ {
protected $default_view = 'main'; 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 public function scan(): void
{ {
$input = Factory::getApplication()->input; $db = Factory::getDbo();
// Default to PDF folder if no path provided
$defaultPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'pdf'; // Pfad aus Tabelle laden
$path = $input->getString('path', $defaultPath); $query = $db->getQuery(true)
->select($db->quoteName('pdf_path'))
->from($db->quoteName('#__eis_settings'))
->order('id ASC')
->setLimit(1);
$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;
}
// Verzeichnis rekursiv scannen
$data = $this->scanFolder($path); $data = $this->scanFolder($path);
// Encode JSON // Alte Einträge löschen
$json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); $db->truncateTable('#__eis_documents');
// Determine output file path // In Datenbank speichern
$outputFile = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'com_eis' . DIRECTORY_SEPARATOR . 'documents.json'; $this->saveToDb($data, null, $db);
// Ensure directory exists
$dir = dirname($outputFile);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
// Write JSON to file
file_put_contents($outputFile, $json);
// Provide feedback and redirect // Erfolgsmeldung
Factory::getApplication() Factory::getApplication()->enqueueMessage('PDF-Struktur erfolgreich gespeichert.', 'message');
->enqueueMessage('JSON file saved to ' . $outputFile, 'message');
// Ausgabe auch im Bachkend
Factory::getApplication()->setUserState('com_eis.pdfdata', $data);
$this->setRedirect('index.php?option=com_eis&view=main'); $this->setRedirect('index.php?option=com_eis&view=main');
} }
/** /**
* Recursively scans a directory and returns an array structure * Rekursive Verzeichnisanalyse
* 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'] ]
*/ */
private function scanFolder(string $dir): array private function scanFolder(string $dir): array
{ {
@@ -63,13 +65,11 @@ class DisplayController extends BaseController
$fullPath = $dir . DIRECTORY_SEPARATOR . $file; $fullPath = $dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($fullPath)) { if (is_dir($fullPath)) {
// Directory: include name and children
$result[] = [ $result[] = [
'name' => $file, 'name' => $file,
'children' => $this->scanFolder($fullPath) 'children' => $this->scanFolder($fullPath)
]; ];
} elseif (is_file($fullPath) && strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'pdf') { } elseif (is_file($fullPath) && strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'pdf') {
// File: include name and absolute path
$result[] = [ $result[] = [
'name' => $file, 'name' => $file,
'path' => $fullPath 'path' => $fullPath
@@ -79,4 +79,31 @@ class DisplayController extends BaseController
return $result; 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);
}
}
}
} }

BIN
com_eis/src/View/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,32 @@
<?php
namespace EIS\Component\EIS\Administrator\View\Config;
\defined('_JEXEC') or die;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Factory;
class HtmlView extends BaseHtmlView
{
protected $form;
protected $item;
public function display($tpl = null): void
{
$db = Factory::getDbo();
$query = $db->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;
}
}

BIN
com_eis/tmpl/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,38 @@
<?php defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Session\Session;
$item = $this->getItem();
$pdfPath = $item['pdf_path'] ?? '';
?>
<h2><?php echo Text::_('COM_EIS_CONFIG_TITLE'); ?></h2>
<form action="<?php echo Route::_('index.php?option=com_eis&task=config.save'); ?>" method="post" name="adminForm" id="adminForm">
<div class="form-horizontal">
<fieldset class="adminform">
<legend><?php echo Text::_('COM_EIS_FIELDSET_SETTINGS'); ?></legend>
<div class="control-group">
<label class="control-label" for="pdf_path">
<?php echo Text::_('COM_EIS_FIELD_PDF_PATH'); ?>
</label>
<div class="controls">
<input type="text" name="pdf_path" id="pdf_path" value="<?php echo htmlspecialchars($pdfPath, ENT_QUOTES); ?>" size="60" />
</div>
</div>
</fieldset>
</div>
<div>
<button type="submit" class="btn btn-primary">
<?php echo Text::_('JSAVE'); ?>
</button>
</div>
<?php echo HTMLHelper::_('form.token'); ?>
</form>

View File

@@ -1,5 +1,6 @@
<?php <?php
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
@@ -11,12 +12,7 @@ use Joomla\CMS\Session\Session;
<div class="form-horizontal"> <div class="form-horizontal">
<fieldset class="adminform"> <fieldset class="adminform">
<legend><?php echo Text::_('COM_EIS_DOCUMENT_PATH'); ?></legend> <legend><?php echo Text::_('COM_EIS_DOCUMENT_PATH'); ?></legend>
<div class="control-group">
<label class="control-label" for="docpath"><?php echo Text::_('COM_EIS_DOCUMENT_PATH_LABEL'); ?></label>
<div class="controls">
<input type="text" name="docpath" id="docpath" size="60" value="/var/www/vhosts/ts-it24.net/stbv.ts-it24.net/pdf/" />
</div>
</div>
</fieldset> </fieldset>
<div> <div>
<button class="btn btn-primary" type="submit"><?php echo Text::_('COM_EIS_SCAN_DOCUMENTS'); ?></button> <button class="btn btn-primary" type="submit"><?php echo Text::_('COM_EIS_SCAN_DOCUMENTS'); ?></button>

BIN
mod_pdf_tree/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@@ -1,75 +1,66 @@
<?php <?php
// Direktzugriff verhindern
defined('_JEXEC') or die; defined('_JEXEC') or die;
// Hilfsklasse zur URI-Verarbeitung einbinden use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri; use Joomla\Database\DatabaseDriver;
/**
* Modul-Hilfsklasse: Baumstruktur aus JSON-Datei aufbereiten
*/
class ModEisAnzeigeHelper class ModEisAnzeigeHelper
{ {
/** /**
* JSON-Datei einlesen und als Array zurückgeben * Holt alle PDF-Elemente aus der Datenbank
* @param string $jsonPath Pfad relativ zum Joomla-Root
* @return array Strukturierte Baumdaten oder leeres Array
*/ */
public static function getItems(string $jsonPath): array
public static function getItems(): array
{ {
$file = JPATH_ROOT . DIRECTORY_SEPARATOR . ltrim($jsonPath, '/'); /** @var DatabaseDriver $db */
if (!file_exists($file)) { $db = Factory::getDbo();
return [];
$query = $db->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); return $grouped;
$data = json_decode($json, true);
if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) {
return [];
}
return $data;
} }
/** /**
* Baumstruktur als HTML generieren (rekursiv) * Hauptfunktion zum Rendern des Baums
* @param array $items Eingelesene JSON-Daten
* @return string HTML-Ausgabe
*/ */
public static function renderTree(array $items): string
public static function renderTree(array $items, int $parentId = null): string
{ {
if (!isset($items[$parentId])) {
return '';
}
$html = '<ul class="pdf-tree">'; $html = '<ul class="pdf-tree">';
foreach ($items as $node) { foreach ($items[$parentId] as $item) {
$name = htmlspecialchars($node['name'], ENT_QUOTES, 'UTF-8'); $isFolder = (bool) $item['is_folder'];
$title = htmlspecialchars($item['title'] ?: $item['name']);
// $path = htmlspecialchars($item['path'] ?? '');
$path = htmlspecialchars(self::convertToRelativeUrl($item['path'] ?? ''));
// Ordner: hat Kinder if ($isFolder) {
if (isset($node['children']) && is_array($node['children'])) { $fileCount = self::countFilesRecursive($items, $item['id']);
$count = self::countFiles($node['children']); $html .= '<li class="folder">';
$html .= '<span class="toggle">▶</span>';
$html .= '<li class="folder">' $html .= '<span class="folder-icon"></span>' . $title . ' <small>(' . $fileCount . ')</small>';
. '<span class="toggle">▶</span>' $html .= self::renderTree($items, $item['id']);
. '<span class="folder-icon"></span>'
. '<span class="folder-name">'
. $name . ' (' . $count . ')'
. '</span>';
// Rekursiver Aufruf
$html .= self::renderTree($node['children']);
$html .= '</li>'; $html .= '</li>';
} else { } else {
// Datei $html .= '<li class="file">';
$path = $node['path'] ?? ''; $html .= '<span class="file-icon"></span><a class="file-link" href="' . $path . '">' . $title . '</a>';
$relative = str_replace(JPATH_ROOT, '', $path); $html .= '</li>';
$url = Uri::root(true) . '/' . ltrim(str_replace(DIRECTORY_SEPARATOR, '/', $relative), '/');
$html .= '<li class="file">'
. '<span class="file-icon"></span>'
. '<a href="' . $url . '" class="file-link" download>'
. $name . '</a>'
. '</li>';
} }
} }
@@ -77,18 +68,36 @@ class ModEisAnzeigeHelper
return $html; return $html;
} }
/** /**
* Dateien im aktuellen Knotenbaum zählen * Konvertiert absoluten Serverpfad in URL
* @param array $items Unterknoten
* @return int Anzahl Dateien
*/ */
private static function countFiles(array $items): int private static function convertToRelativeUrl(string $fullPath): string
{
// <== HIER den absoluten Pfad zu deinem Webroot anpassen
$webRoot = '/var/www/vhosts/ts-it24.net/stbv.ts-it24.net';
$webBase = ''; // ggf. '/subdir' falls Joomla in Unterordner
if (str_starts_with($fullPath, $webRoot)) {
return $webBase . str_replace($webRoot, '', $fullPath);
}
return $fullPath; // Fallback: Original verwenden
}
/**
* Zählt alle PDF-Dateien unterhalb eines Ordners rekursiv
*/
private static function countFilesRecursive(array $items, int $parentId): int
{ {
$count = 0; $count = 0;
foreach ($items as $node) { if (!isset($items[$parentId])) {
if (isset($node['children']) && is_array($node['children'])) { return 0;
$count += self::countFiles($node['children']); }
foreach ($items[$parentId] as $item) {
if ((bool)$item['is_folder']) {
$count += self::countFilesRecursive($items, $item['id']);
} else { } else {
$count++; $count++;
} }

View File

@@ -6,12 +6,13 @@ defined('_JEXEC') or die;
require_once __DIR__ . '/helper.php'; require_once __DIR__ . '/helper.php';
// Retrieve JSON path and access params // Retrieve JSON path and access params
$jsonPath = $params->get('json_path', 'media/com_eis/documents.json'); // $jsonPath = $params->get('json_path', 'media/com_eis/documents.json');
$confidentialLevel = $params->get('confidential_level'); // $confidentialLevel = $params->get('confidential_level');
$privateUserId = $params->get('private_user'); // $privateUserId = $params->get('private_user');
// Load and parse document tree
$items = ModEisAnzeigeHelper::getItems();
// Load and parse JSON document tree
$items = ModEisAnzeigeHelper::getItems($jsonPath);
// TODO: Apply access filtering // TODO: Apply access filtering
// $items = ModEisAnzeigeHelper::filterByAccess($items, $confidentialLevel, $privateUserId); // $items = ModEisAnzeigeHelper::filterByAccess($items, $confidentialLevel, $privateUserId);