config deux options

This commit is contained in:
Fred Tempez 2024-03-15 21:14:49 +01:00
parent 75203d6e8e
commit c4fc466876
2 changed files with 135 additions and 102 deletions

View File

@ -36,7 +36,10 @@ class folder extends common
public function index()
{
self::$folders = $this->getFolderContent($this->getData(['module', $this->getUrl(0), 'path']));
$config['showsubfolder'] = $this->getData(['module', $this->getUrl(0), 'subfolder']);
$config['sort'] = $this->getData(['module', $this->getUrl(0), 'sort']);
self::$folders = $this->getFolderContent($this->getData(['module', $this->getUrl(0), 'path']), $config);
// Valeurs en sortie
$this->addOutput([
@ -54,12 +57,18 @@ class folder extends common
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData(['module',
$this->getUrl(0),[
'path'=> preg_replace('/^\\./', '', $this->getInput('folderConfigPath')),
'title' => $this->getInput('folderConfigTitle')
$this->setData([
'module',
$this->getUrl(0),
[
'path' => preg_replace('/^\\./', '', $this->getInput('folderConfigPath')),
'title' => $this->getInput('folderConfigTitle'),
'sort' => $this->getInput('folderConfigSort', helper::FILTER_BOOLEAN),
'subfolder' => $this->getInput('folderConfigSubfolder', helper::FILTER_BOOLEAN),
'folder' => $this->getInput('folderConfigFolder', helper::FILTER_BOOLEAN),
]]);
]
]);
// Valeurs en sortie
$this->addOutput([
@ -80,8 +89,11 @@ class folder extends common
}
private function getFolderContent($chemin)
{
private function getFolderContent($chemin, $config = [])
{
$showSubFolder = isset($config['showsubfolder']) ? $config['showsubfolder'] : true;
$sort = isset($config['sort']) ? $config['sort'] : true;
// Vérifier si le chemin existe et est un dossier
if (is_dir($chemin)) {
// Ouvrir le dossier
@ -111,20 +123,24 @@ class folder extends common
// Fermer le dossier
closedir($dh);
// Trier les sous-dossiers et les fichiers
// Trier les sous-dossiers et les fichiers si nécessaire
if ($sort) {
sort($subDirectories);
sort($files);
}
// Initialiser la liste des éléments
$items = '<ul>';
// Ajouter les sous-dossiers à la liste
// Ajouter les sous-dossiers à la liste si configuré pour les afficher
if ($showSubFolder) {
foreach ($subDirectories as $subDirectory) {
$items .= "<li class='directory'>$subDirectory";
// Appeler récursivement la fonction pour ce sous-dossier
$items .= $this->getFolderContent($chemin . '/' . $subDirectory);
$items .= $this->getFolderContent($chemin . '/' . $subDirectory, $config);
$items .= '</li>';
}
}
// Ajouter les fichiers à la liste
foreach ($files as $file) {
@ -139,7 +155,10 @@ class folder extends common
}
return '';
}
}

View File

@ -1,5 +1,5 @@
<?php echo template::formOpen('folderConfig'); ?>
<div class="row">
<div class="row">
<div class="col1">
<?php echo template::button('folderConfigBack', [
'class' => 'buttonGrey',
@ -10,11 +10,13 @@
<div class="col2 offset9">
<?php echo template::submit('folderConfigSubmit'); ?>
</div>
</div>
<div class='row'>
</div>
<div class='row'>
<div class="col12">
<div class="block">
<h4><?php echo helper::translate('Paramètres'); ?></h4>
<h4>
<?php echo helper::translate('Paramètres'); ?>
</h4>
<div class="row">
<div class="col6">
<?php echo template::select('folderConfigPath', $module::$sharePath, [
@ -27,13 +29,25 @@
<?php echo template::text('folderConfigTitle', [
'label' => 'Titre',
'placeholder' => 'Répertoire',
'value' => empty($this->getData(['module', $this->getUrl(0), 'title'])) ? 'Répertoire' : $this->getData(['module', $this->getUrl(0), 'title'])
'value' => empty ($this->getData(['module', $this->getUrl(0), 'title'])) ? 'Répertoire' : $this->getData(['module', $this->getUrl(0), 'title'])
]); ?>
</div>
</div>
<div class="row">
<div class="col4">
<?php echo template::checkbox('folderConfigSort', true, 'Trier les dossiers et les fichiers', [
'checked' => $this->getData(['module', $this->getUrl(0), 'sort'])
]); ?>
</div>
<div class="col4">
<?php echo template::checkbox('folderConfigSubfolder', true, 'Descendre dans l\'arboresence', [
'checked' => $this->getData(['module', $this->getUrl(0), 'subfolder'])
]); ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version
<?php echo $module::VERSION; ?>