erste Lauffähige Fassung

This commit is contained in:
Thomas Spohr
2025-07-29 10:33:26 +02:00
parent af2ebf4ab6
commit a481866b66
26 changed files with 500 additions and 76619 deletions

36
com_eis/eis.xml Normal file
View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" method="install">
<!-- Database table for PDF entries -->
<install>
<sql>
<file driver="mysql" charset="utf8mb4">sql/install/mysql/install.mysql.sql</file>
</sql>
</install>
<name>com_eis</name>
<creationDate>2025-07-23</creationDate>
<author>Thomas Spohr powert by OpenAI</author>
<version>1.0.0</version>
<description>EIS Minimal-Komponente</description>
<namespace path="src">EIS\Component\EIS</namespace>
<administration>
<menu img="class:eis">COM_EIS_MENU</menu>
<submenu>
<menu link="option=com_eis&amp;view=main" img="class:eis-main" alt="EIS/Main">
COM_EIS_MAIN</menu>
</submenu>
<files client="administrator">
<folder>sql</folder>
<folder>src</folder>
<folder>tmpl</folder>
<folder>language</folder>
<folder>services</folder>
</files>
<languages folder="language/en-GB">
<language tag="en-GB">en-GB.com_eis.ini</language>
<language tag="en-GB">en-GB.com_eis.sys.ini</language>
</languages>
</administration>
</extension>

View File

@@ -0,0 +1,8 @@
COM_EIS_DOCUMENT_PATH="Dokumentenpfad"
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_MAINTENANCE="Wartung"

View File

@@ -0,0 +1 @@
COM_EIS="EIS Komponente"

View File

@@ -0,0 +1,30 @@
<?php
namespace EIS\Component\EIS;
\defined('_JEXEC') or die;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\Extension\Service\Provider\RouterFactory;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
return new class implements ServiceProviderInterface
{
public function register(Container $container): void
{
$container->registerServiceProvider(new ComponentDispatcherFactory('\\EIS\\Component\\EIS'));
$container->registerServiceProvider(new MVCFactory('\\EIS\\Component\\EIS'));
$container->registerServiceProvider(new RouterFactory('\\EIS\\Component\\EIS'));
$container->set(
ComponentInterface::class,
static fn(Container $c) => new MVCComponent(
$c->get(ComponentDispatcherFactoryInterface::class)
)
);
}
};

View File

@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS `#__eis_documents` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`path` TEXT NOT NULL,
`parent_id` INT UNSIGNED DEFAULT NULL,
`is_folder` TINYINT(1) DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View File

@@ -0,0 +1,82 @@
<?php
namespace EIS\Component\EIS\Administrator\Controller;
\defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Factory;
class DisplayController extends BaseController
{
protected $default_view = 'main';
/**
* Endpoint to generate JSON of PDF directory tree
*/
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);
// Encode JSON
$json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
// 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);
}
// 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);
$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'] ]
*/
private function scanFolder(string $dir): array
{
$result = [];
if (!is_dir($dir)) {
return $result;
}
foreach (scandir($dir) as $file) {
if ($file === '.' || $file === '..') {
continue;
}
$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
];
}
}
return $result;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace EIS\Component\EIS\Administrator\Extension;
\defined('_JEXEC') or die;
use Joomla\CMS\Extension\MVCComponent;
final class EISComponent extends MVCComponent
{
}

View File

@@ -0,0 +1,16 @@
<?php
namespace EIS\Component\EIS\Administrator\View\Main;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
class HtmlView extends BaseHtmlView
{
public function display($tpl = null): void
{
echo "<h2>Willkommen bei EIS</h2>";
$this->data = Factory::getApplication()->getUserState('com_eis.pdfdata');
parent::display($tpl);
}
}

View File

@@ -0,0 +1,48 @@
<?php
\defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
?>
<form action="<?php echo Route::_('index.php?option=com_eis&task=display.scan'); ?>" method="post" name="adminForm" id="adminForm">
<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>
<button class="btn btn-primary" type="submit"><?php echo Text::_('COM_EIS_SCAN_DOCUMENTS'); ?></button>
</div>
</div>
<?php echo HTMLHelper::_('form.token'); ?>
</form>
<?php if (!empty($this->data)) : ?>
<hr>
<h3><?php echo Text::_('COM_EIS_PDF_TREE'); ?></h3>
<ul>
<?php echo renderTree($this->data); ?>
</ul>
<?php endif; ?>
<?php
function renderTree($items)
{
$html = '';
foreach ($items as $item) {
if (isset($item['children'])) {
$html .= '<li><strong>' . htmlspecialchars($item['name']) . '</strong><ul>' . renderTree($item['children']) . '</ul></li>';
} else {
$html .= '<li>' . htmlspecialchars($item['name']) . '</li>';
}
}
return $html;
}
?>