erste Lauffähige Fassung
This commit is contained in:
82
com_eis/src/Controller/DisplayController.php
Normal file
82
com_eis/src/Controller/DisplayController.php
Normal 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;
|
||||
}
|
||||
}
|
||||
10
com_eis/src/Extension/EISComponent.php
Normal file
10
com_eis/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
|
||||
{
|
||||
}
|
||||
16
com_eis/src/View/Main/HtmlView.php
Normal file
16
com_eis/src/View/Main/HtmlView.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user