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
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>
@@ -45,4 +41,4 @@ function renderTree($items)
}
return $html;
}
?>
?>