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

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,
`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;

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_MAIN="EIS Hauptansicht"
COM_EIS_MENU="EIS"
COM_EIS_SETTINGS="Einstellungen"
COM_EIS_CONFIG="Einstellungen"
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;
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);
}
}
}
}

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
\defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
@@ -11,14 +12,9 @@ use Joomla\CMS\Session\Session;
<div class="form-horizontal">
<fieldset class="adminform">
<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>
<div>
<div>
<button class="btn btn-primary" type="submit"><?php echo Text::_('COM_EIS_SCAN_DOCUMENTS'); ?></button>
</div>
</div>

BIN
mod_pdf_tree/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@@ -1,75 +1,66 @@
<?php
// Direktzugriff verhindern
defined('_JEXEC') or die;
// Hilfsklasse zur URI-Verarbeitung einbinden
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseDriver;
/**
* Modul-Hilfsklasse: Baumstruktur aus JSON-Datei aufbereiten
*/
class ModEisAnzeigeHelper
{
/**
* JSON-Datei einlesen und als Array zurückgeben
* @param string $jsonPath Pfad relativ zum Joomla-Root
* @return array Strukturierte Baumdaten oder leeres Array
* Holt alle PDF-Elemente aus der Datenbank
*/
public static function getItems(string $jsonPath): array
public static function getItems(): array
{
$file = JPATH_ROOT . DIRECTORY_SEPARATOR . ltrim($jsonPath, '/');
if (!file_exists($file)) {
return [];
/** @var DatabaseDriver $db */
$db = Factory::getDbo();
$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);
$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 = '<ul class="pdf-tree">';
foreach ($items as $node) {
$name = htmlspecialchars($node['name'], ENT_QUOTES, 'UTF-8');
foreach ($items[$parentId] as $item) {
$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 (isset($node['children']) && is_array($node['children'])) {
$count = self::countFiles($node['children']);
$html .= '<li class="folder">'
. '<span class="toggle">▶</span>'
. '<span class="folder-icon"></span>'
. '<span class="folder-name">'
. $name . ' (' . $count . ')'
. '</span>';
// Rekursiver Aufruf
$html .= self::renderTree($node['children']);
if ($isFolder) {
$fileCount = self::countFilesRecursive($items, $item['id']);
$html .= '<li class="folder">';
$html .= '<span class="toggle">▶</span>';
$html .= '<span class="folder-icon"></span>' . $title . ' <small>(' . $fileCount . ')</small>';
$html .= self::renderTree($items, $item['id']);
$html .= '</li>';
} else {
// Datei
$path = $node['path'] ?? '';
$relative = str_replace(JPATH_ROOT, '', $path);
$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>';
$html .= '<li class="file">';
$html .= '<span class="file-icon"></span><a class="file-link" href="' . $path . '">' . $title . '</a>';
$html .= '</li>';
}
}
@@ -77,18 +68,36 @@ class ModEisAnzeigeHelper
return $html;
}
/**
* Dateien im aktuellen Knotenbaum zählen
* @param array $items Unterknoten
* @return int Anzahl Dateien
* Konvertiert absoluten Serverpfad in URL
*/
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;
foreach ($items as $node) {
if (isset($node['children']) && is_array($node['children'])) {
$count += self::countFiles($node['children']);
if (!isset($items[$parentId])) {
return 0;
}
foreach ($items[$parentId] as $item) {
if ((bool)$item['is_folder']) {
$count += self::countFilesRecursive($items, $item['id']);
} else {
$count++;
}

View File

@@ -6,12 +6,13 @@ defined('_JEXEC') or die;
require_once __DIR__ . '/helper.php';
// Retrieve JSON path and access params
$jsonPath = $params->get('json_path', 'media/com_eis/documents.json');
$confidentialLevel = $params->get('confidential_level');
$privateUserId = $params->get('private_user');
// $jsonPath = $params->get('json_path', 'media/com_eis/documents.json');
// $confidentialLevel = $params->get('confidential_level');
// $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
// $items = ModEisAnzeigeHelper::filterByAccess($items, $confidentialLevel, $privateUserId);