Mit deutscher Sprache
This commit is contained in:
BIN
com_eis/administrator/src/.DS_Store
vendored
Normal file
BIN
com_eis/administrator/src/.DS_Store
vendored
Normal file
Binary file not shown.
46
com_eis/administrator/src/Controller/ConfigController.php
Normal file
46
com_eis/administrator/src/Controller/ConfigController.php
Normal 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));
|
||||
}
|
||||
}
|
||||
141
com_eis/administrator/src/Controller/DisplayController.php
Normal file
141
com_eis/administrator/src/Controller/DisplayController.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace EIS\Component\EIS\Administrator\Controller;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\Database\DatabaseDriver;
|
||||
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
protected $default_view = 'main';
|
||||
|
||||
/**
|
||||
* Button-Aktion: PDF-Verzeichnis scannen und in Datenbank speichern
|
||||
*/
|
||||
public function scan(): void
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Pfad aus Tabelle laden
|
||||
$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);
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rekursive Verzeichnisanalyse
|
||||
*/
|
||||
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)) {
|
||||
$result[] = [
|
||||
'name' => $file,
|
||||
'children' => $this->scanFolder($fullPath)
|
||||
];
|
||||
} elseif (is_file($fullPath) && strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'pdf') {
|
||||
$result[] = [
|
||||
'name' => $file,
|
||||
'path' => $fullPath
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function rename(): void
|
||||
{
|
||||
// CSRF prüfen
|
||||
\Joomla\CMS\Session\Session::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
|
||||
|
||||
$app = \Joomla\CMS\Factory::getApplication();
|
||||
$id = (int) $app->input->get('id');
|
||||
$title = trim((string) $app->input->get('title', '', 'STRING'));
|
||||
|
||||
if ($id <= 0) {
|
||||
$app->enqueueMessage('Ungültige ID', 'error');
|
||||
$this->setRedirect('index.php?option=com_eis&view=main');
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var \Joomla\Database\DatabaseDriver $db */
|
||||
$db = \Joomla\CMS\Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__eis_documents'))
|
||||
->set($db->quoteName('title') . ' = ' . ($title === '' ? 'NULL' : $db->quote($title)))
|
||||
->where($db->quoteName('id') . ' = ' . (int) $id);
|
||||
|
||||
try {
|
||||
$db->setQuery($query)->execute();
|
||||
$app->enqueueMessage('Anzeigename gespeichert', 'message');
|
||||
} catch (\Throwable $e) {
|
||||
$app->enqueueMessage('Fehler beim Speichern: ' . $e->getMessage(), 'error');
|
||||
}
|
||||
|
||||
$this->setRedirect('index.php?option=com_eis&view=main');
|
||||
}
|
||||
}
|
||||
10
com_eis/administrator/src/Extension/EISComponent.php
Normal file
10
com_eis/administrator/src/Extension/EISComponent.php
Normal 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
|
||||
{
|
||||
}
|
||||
112
com_eis/administrator/src/Helper/TreeHelper.php
Normal file
112
com_eis/administrator/src/Helper/TreeHelper.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace EIS\Component\EIS\Administrator\Helper;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Database\DatabaseDriver;
|
||||
|
||||
class TreeHelper
|
||||
{
|
||||
/** Lädt #__eis_documents, gruppiert nach parent_id und sortiert */
|
||||
public static function getItems(): array
|
||||
{
|
||||
/** @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();
|
||||
|
||||
$grouped = [];
|
||||
foreach ($rows as $row) {
|
||||
$pid = $row['parent_id'] === null ? null : (int) $row['parent_id'];
|
||||
$grouped[$pid][] = $row;
|
||||
}
|
||||
|
||||
// alphabetisch nach name
|
||||
foreach ($grouped as &$group) {
|
||||
usort($group, fn($a, $b) => strcasecmp($a['name'], $b['name']));
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/** Baum rendern (nutzt title als alternativen Anzeigenamen) */
|
||||
public static function renderTree(array $items, ?int $parentId = null): string
|
||||
{
|
||||
if (!isset($items[$parentId])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = '<ul class="pdf-tree">';
|
||||
|
||||
foreach ($items[$parentId] as $item) {
|
||||
$isFolder = (bool) $item['is_folder'];
|
||||
$rawName = $item['title'] ?: $item['name'];
|
||||
$display = preg_replace('/\.pdf$/i', '', (string) $rawName);
|
||||
$display = htmlspecialchars($display, ENT_QUOTES, 'UTF-8');
|
||||
$id = (int) $item['id'];
|
||||
if ($isFolder) {
|
||||
$fileCount = self::countFilesRecursive($items, $id);
|
||||
|
||||
$html .= '<li class="folder"'
|
||||
. ' data-id="' . $id . '"'
|
||||
. ' data-title="' . htmlspecialchars((string)($item['title'] ?? ''), ENT_QUOTES, 'UTF-8') . '"'
|
||||
. ' data-name="' . htmlspecialchars((string)$item['name'], ENT_QUOTES, 'UTF-8') . '"'
|
||||
. '>';
|
||||
$html .= '<span class="toggle" role="button" aria-label="Ordner umschalten" tabindex="0">▶</span> ';
|
||||
$html .= '<span class="folder-label">📁 ' . $display . ' <small class="count">(' . (int)$fileCount . ')</small></span>';
|
||||
$html .= self::renderTree($items, $id);
|
||||
$html .= '</li>';
|
||||
} else {
|
||||
$sizeStr = '';
|
||||
if (!empty($item['path']) && is_file($item['path'])) {
|
||||
$size = @filesize($item['path']);
|
||||
if ($size !== false) {
|
||||
$sizeStr = ' <small class="meta">(' . self::formatFileSize((int) $size) . ')</small>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '<li class="file"'
|
||||
. ' data-id="' . $id . '"'
|
||||
. ' data-title="' . htmlspecialchars((string)($item['title'] ?? ''), ENT_QUOTES, 'UTF-8') . '"'
|
||||
. ' data-name="' . htmlspecialchars((string)$item['name'], ENT_QUOTES, 'UTF-8') . '"'
|
||||
. '>';
|
||||
$html .= '<span class="file-label">📄 ' . $display . $sizeStr . '</span>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
private static function countFilesRecursive(array $items, int $parentId): int
|
||||
{
|
||||
$count = 0;
|
||||
if (!isset($items[$parentId])) {
|
||||
return 0;
|
||||
}
|
||||
foreach ($items[$parentId] as $item) {
|
||||
if ((bool) $item['is_folder']) {
|
||||
$count += self::countFilesRecursive($items, (int)$item['id']);
|
||||
} else {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
private static function formatFileSize(int $bytes): string
|
||||
{
|
||||
if ($bytes >= 1073741824) return number_format($bytes / 1073741824, 2) . ' GB';
|
||||
if ($bytes >= 1048576) return number_format($bytes / 1048576, 1) . ' MB';
|
||||
if ($bytes >= 1024) return number_format($bytes / 1024, 0) . ' KB';
|
||||
return $bytes . ' B';
|
||||
}
|
||||
}
|
||||
BIN
com_eis/administrator/src/View/.DS_Store
vendored
Normal file
BIN
com_eis/administrator/src/View/.DS_Store
vendored
Normal file
Binary file not shown.
32
com_eis/administrator/src/View/Config/HtmlView.php
Normal file
32
com_eis/administrator/src/View/Config/HtmlView.php
Normal 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;
|
||||
}
|
||||
}
|
||||
20
com_eis/administrator/src/View/Main/HtmlView.php
Normal file
20
com_eis/administrator/src/View/Main/HtmlView.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace EIS\Component\EIS\Administrator\View\Main;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use EIS\Component\EIS\Administrator\Helper\TreeHelper;
|
||||
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
public function display($tpl = null): void
|
||||
{
|
||||
// Baumdaten laden und fürs Template bereitstellen
|
||||
$items = TreeHelper::getItems();
|
||||
$this->treeHtml = TreeHelper::renderTree($items);
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user