ajout d'une galerie ok

This commit is contained in:
fredtempez 2022-04-05 15:50:48 +02:00
parent da1f293379
commit 8c26b42dec
1 changed files with 57 additions and 35 deletions

View File

@ -395,14 +395,18 @@ class gallery extends common {
public function add() { public function add() {
// Soumission du formulaire d'ajout d'une galerie // Soumission du formulaire d'ajout d'une galerie
if($this->isPost()) { if($this->isPost()) {
$galleryId = $this->getInput('galleryAddName', null, true);
$success = false;
if ($galleryId ) {
$galleryId = helper::increment($this->getInput('galleryAddName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content'])); $galleryId = helper::increment($this->getInput('galleryAddName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content']));
$homePicture = ''; $homePicture = '';
// définir une vignette par défaut // définir une vignette par défaut
$directory = $this->getInput('galleryAddDirectory', helper::FILTER_STRING_SHORT, true); $directory = $this->getInput('galleryAddDirectory', helper::FILTER_STRING_SHORT, true);
$iterator = new DirectoryIterator($directory); $iterator = new DirectoryIterator($directory);
$i = 0;
foreach($iterator as $fileInfos) { foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
$i += 1;
// Créer la miniature si manquante // Créer la miniature si manquante
if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) { if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
$this->makeThumb($fileInfos->getPathname(), $this->makeThumb($fileInfos->getPathname(),
@ -414,6 +418,8 @@ class gallery extends common {
break; break;
} }
} }
// Le dossier de la galerie est vide
if ($i > 0) {
$this->setData(['module', $this->getUrl(0), 'content', $galleryId, [ $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [
'config' => [ 'config' => [
'name' => $this->getInput('galleryAddName'), 'name' => $this->getInput('galleryAddName'),
@ -427,10 +433,18 @@ class gallery extends common {
'legend' => [], 'legend' => [],
'positions' => [] 'positions' => []
]]); ]]);
$success = true;
} else {
self::$inputNotices['galleryAddDirectory'] = "Le dossier sélectionné ne contient aucune image";
$success = false;
}
}
if ($success) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', // '#galleryAddForm'*/, 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Modifications enregistrées', 'notification' => 'La galerie a été ajoutée',
'state' => true 'state' => true
]); ]);
} else { } else {
@ -440,6 +454,14 @@ class gallery extends common {
'view' => 'add' 'view' => 'add'
]); ]);
} }
} else {
// Valeurs en sortie
$this->addOutput([
'title' => 'Ajout d\'une galerie',
'view' => 'add'
]);
}
} }
/** /**
* Suppression * Suppression