From 1e39da2b6537ab54c7aa9ca7c9e6ebaf23c433bc Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sat, 22 Feb 2020 22:18:49 +0100 Subject: [PATCH] [9.2.22] Choix photo album --- CHANGES.md | 4 ++++ module/gallery/gallery.php | 29 ++++++++++++++++++++-------- module/gallery/view/edit/edit.js.php | 5 +++++ module/gallery/view/edit/edit.php | 2 +- module/gallery/view/index/index.php | 10 ++++++++-- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e269f79b..30aff957 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,10 @@ - Modifications : - Aperçu de la police dans les sélecteurs. - Gestion du canal de mise à jour selon la version installée + - Module Blog : position des boutons d'édition de l'article au-dessus des commentaires. + - Module Gallery : + - choix de la vignette d'album + - Tri ordre naturel de la galerie et des images de la galerie - Mises à jour : - Configurations Code Mirror pour TinyMCE et standalone diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 2116c093..9680fdd6 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -39,7 +39,7 @@ class gallery extends common { // Liste des galeries $galleries = $this->getData(['module', $this->getUrl(0)]); if($galleries) { - ksort($galleries); + ksort($galleries,SORT_NATURAL); foreach($galleries as $galleryId => $gallery) { // Erreur dossier vide if(is_dir($gallery['config']['directory'])) { @@ -165,16 +165,25 @@ class gallery extends common { // Supprime l'ancienne galerie $this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); } + // légendes $legends = []; foreach((array) $this->getInput('legend', null) as $file => $legend) { $file = str_replace('.','',$file); $legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); } - + // Photo de la page de garde de l'album + $homePictures = []; + foreach((array) $this->getInput('homePicture', null) as $file => $homePicture) { + $homePictures[$file] = $file; + } + // Pas de sélection, retourne NULL plutôt que 0 + // Permet de traiter aussi le cas où l'image d'album n'est pas définie. + $homePictures[$file] = $homePictures[$file] === 0 ? NULL : $homePictures[$file]; $this->setData(['module', $this->getUrl(0), $galleryId, [ 'config' => [ 'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), - 'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true) + 'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true), + 'homePicture' => $homePictures[$file] ], 'legend' => $legends ]]); @@ -193,6 +202,11 @@ class gallery extends common { if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { self::$pictures[$fileInfos->getFilename()] = [ $fileInfos->getFilename(), + template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [ + 'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false, + 'class' => 'homePicture' + + ]), template::text('legend[' . $fileInfos->getFilename() . ']', [ 'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())]) ]) @@ -200,7 +214,7 @@ class gallery extends common { } } // Tri des images par ordre alphabétique - ksort(self::$pictures); + ksort(self::$pictures,SORT_NATURAL); } // Valeurs en sortie $this->addOutput([ @@ -226,7 +240,7 @@ class gallery extends common { // La galerie existe else { // Images de la galerie - $directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'directory']); + $directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'directory']); if(is_dir($directory)) { $iterator = new DirectoryIterator($directory); foreach($iterator as $fileInfos) { @@ -235,7 +249,7 @@ class gallery extends common { } } // Tri des images par ordre alphabétique - ksort(self::$pictures); + ksort(self::$pictures,SORT_NATURAL); } // Affichage du template if(self::$pictures) { @@ -260,7 +274,7 @@ class gallery extends common { } // Liste des galeries - else { + else { foreach((array) $this->getData(['module', $this->getUrl(0)]) as $galleryId => $gallery) { if(is_dir($gallery['config']['directory'])) { $iterator = new DirectoryIterator($gallery['config']['directory']); @@ -271,7 +285,6 @@ class gallery extends common { continue(2); } } - } } // Valeurs en sortie diff --git a/module/gallery/view/edit/edit.js.php b/module/gallery/view/edit/edit.js.php index 4b6a4130..63252061 100644 --- a/module/gallery/view/edit/edit.js.php +++ b/module/gallery/view/edit/edit.js.php @@ -48,4 +48,9 @@ setInterval(function() { */ directoryDOM.on("change", function() { directoryOldDOM.val($(this).val()); +}); + +$('.homePicture').click(function(){ + $('.homePicture').prop('checked', false); + $(this).prop('checked', true); }); \ No newline at end of file diff --git a/module/gallery/view/edit/edit.php b/module/gallery/view/edit/edit.php index 4eb99514..9d27a437 100644 --- a/module/gallery/view/edit/edit.php +++ b/module/gallery/view/edit/edit.php @@ -38,6 +38,6 @@ - + \ No newline at end of file diff --git a/module/gallery/view/index/index.php b/module/gallery/view/index/index.php index cd8f0182..51e9a7c8 100644 --- a/module/gallery/view/index/index.php +++ b/module/gallery/view/index/index.php @@ -4,12 +4,18 @@ $gallery): ?>
- +