Gallery 3.0 structure données config et content

This commit is contained in:
fredtempez 2021-04-04 14:55:47 +02:00
parent c6d48a8fdf
commit a6e245e83b
3 changed files with 51 additions and 32 deletions

View File

@ -17,7 +17,7 @@
class gallery extends common { class gallery extends common {
const VERSION = '2.6'; const VERSION = '3.0';
const REALNAME = 'Galerie'; const REALNAME = 'Galerie';
const DELETE = true; const DELETE = true;
const UPDATE = '0.0'; const UPDATE = '0.0';
@ -143,6 +143,20 @@ class gallery extends common {
'1px 1px 50px' => 'Très importante' '1px 1px 50px' => 'Très importante'
]; ];
/**
* Mise à jour du module
* Appelée par les fonctions index et config
*/
private function update() {
if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '3.0', '<') ) {
$data = $this->getData(['module', $this->getUrl(0)]);
$this->deleteData(['module', $this->getUrl(0)]);
$this->setData(['module', $this->getUrl(0), 'content', $data]);
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.0']);
}
}
/** /**
* Tri de la liste des galeries * Tri de la liste des galeries
* *
@ -152,7 +166,7 @@ class gallery extends common {
$data = explode('&',$_POST['response']); $data = explode('&',$_POST['response']);
$data = str_replace('galleryTable%5B%5D=','',$data); $data = str_replace('galleryTable%5B%5D=','',$data);
for($i=0;$i<count($data);$i++) { for($i=0;$i<count($data);$i++) {
$this->setData(['module', $this->getUrl(0), $data[$i], [ $this->setData(['module', $this->getUrl(0), 'content', $data[$i], [
'config' => [ 'config' => [
'name' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','name']), 'name' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','name']),
'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']), 'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']),
@ -179,7 +193,7 @@ class gallery extends common {
$data = explode('&',$_POST['response']); $data = explode('&',$_POST['response']);
$data = str_replace('galleryTable%5B%5D=','',$data); $data = str_replace('galleryTable%5B%5D=','',$data);
// Sauvegarder // Sauvegarder
$this->setData(['module', $this->getUrl(0), $galleryName, [ $this->setData(['module', $this->getUrl(0), 'content', $galleryName, [
'config' => [ 'config' => [
'name' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','name']), 'name' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','name']),
'directory' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','directory']), 'directory' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','directory']),
@ -200,8 +214,11 @@ class gallery extends common {
* Configuration * Configuration
*/ */
public function config() { public function config() {
// Mise à jour des données de module
$this->update();
//Affichage de la galerie triée //Affichage de la galerie triée
$g = $this->getData(['module', $this->getUrl(0)]); $g = $this->getData(['module', $this->getUrl(0), 'content']);
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); $p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position');
asort($p,SORT_NUMERIC); asort($p,SORT_NUMERIC);
$galleries = []; $galleries = [];
@ -243,7 +260,7 @@ class gallery extends common {
// Soumission du formulaire d'ajout d'une galerie // Soumission du formulaire d'ajout d'une galerie
if($this->isPost()) { if($this->isPost()) {
if (!$this->getInput('galleryConfigFilterResponse')) { if (!$this->getInput('galleryConfigFilterResponse')) {
$galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content']));
// définir une vignette par défaut // définir une vignette par défaut
$directory = $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true); $directory = $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true);
$iterator = new DirectoryIterator($directory); $iterator = new DirectoryIterator($directory);
@ -260,13 +277,13 @@ class gallery extends common {
break; break;
} }
} }
$this->setData(['module', $this->getUrl(0), $galleryId, [ $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [
'config' => [ 'config' => [
'name' => $this->getInput('galleryConfigName'), 'name' => $this->getInput('galleryConfigName'),
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePicture, 'homePicture' => $homePicture,
'sort' => self::SORT_ASC, 'sort' => self::SORT_ASC,
'position' => $this->getData(['module', $this->getUrl(0), $galleryId,'config','position']), 'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']),
'fullScreen' => false 'fullScreen' => false
], ],
'legend' => [], 'legend' => [],
@ -296,7 +313,7 @@ class gallery extends common {
public function delete() { public function delete() {
// $url prend l'adresse sans le token // $url prend l'adresse sans le token
// La galerie n'existe pas // La galerie n'existe pas
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) { if($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]) === null) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'access' => false 'access' => false
@ -312,7 +329,7 @@ class gallery extends common {
} }
// Suppression // Suppression
else { else {
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); $this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
@ -346,7 +363,7 @@ class gallery extends common {
]); ]);
} }
// La galerie n'existe pas // La galerie n'existe pas
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) { if($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]) === null) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'access' => false 'access' => false
@ -360,11 +377,11 @@ class gallery extends common {
$galleryId = !empty($this->getInput('galleryEditName')) ? $this->getInput('galleryEditName', helper::FILTER_ID, true) : $this->getUrl(2); $galleryId = !empty($this->getInput('galleryEditName')) ? $this->getInput('galleryEditName', helper::FILTER_ID, true) : $this->getUrl(2);
if($galleryId !== $this->getUrl(2)) { if($galleryId !== $this->getUrl(2)) {
// Incrémente le nouvel id de la galerie // Incrémente le nouvel id de la galerie
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)])); $galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0), 'content']));
// Transférer la position des images // Transférer la position des images
$oldPositions = $this->getData(['module',$this->getUrl(0), $this->getUrl(2),'positions']); $oldPositions = $this->getData(['module',$this->getUrl(0), $this->getUrl(2),'positions']);
// Supprime l'ancienne galerie // Supprime l'ancienne galerie
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); $this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]);
} }
// légendes // légendes
$legends = []; $legends = [];
@ -382,19 +399,19 @@ class gallery extends common {
} }
// Sauvegarder // Sauvegarder
if ($this->getInput('galleryEditName')) { if ($this->getInput('galleryEditName')) {
$this->setData(['module', $this->getUrl(0), $galleryId, [ $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [
'config' => [ 'config' => [
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), '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' => $homePicture, 'homePicture' => $homePicture,
// pas de positions, on active le tri alpha // pas de positions, on active le tri alpha
'sort' => $this->getInput('galleryEditSort'), 'sort' => $this->getInput('galleryEditSort'),
'position' => $this->getData(['module', $this->getUrl(0), $galleryId,'config','position']), 'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']),
'fullScreen' => $this->getInput('galleryEditFullscreen', helper::FILTER_BOOLEAN) 'fullScreen' => $this->getInput('galleryEditFullscreen', helper::FILTER_BOOLEAN)
], ],
'legend' => $legends, 'legend' => $legends,
'positions' => empty($oldPositions) ? $this->getdata(['module', $this->getUrl(0), $galleryId, 'positions']) : $oldPositions 'positions' => empty($oldPositions) ? $this->getdata(['module', $this->getUrl(0), 'content', $galleryId, 'positions']) : $oldPositions
]]); ]]);
} }
// Valeurs en sortie // Valeurs en sortie
@ -405,7 +422,7 @@ class gallery extends common {
]); ]);
} }
// Met en forme le tableau // Met en forme le tableau
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']); $directory = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'directory']);
if(is_dir($directory)) { if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory); $iterator = new DirectoryIterator($directory);
@ -421,11 +438,11 @@ class gallery extends common {
template::ico('sort'), template::ico('sort'),
$fileInfos->getFilename(), $fileInfos->getFilename(),
template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [ template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [
'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false, 'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false,
'class' => 'homePicture' 'class' => 'homePicture'
]), ]),
template::text('legend[' . $fileInfos->getFilename() . ']', [ template::text('legend[' . $fileInfos->getFilename() . ']', [
'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())]) 'value' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())])
]), ]),
'<a href="' . str_replace('source','thumb',$directory) . '/' . self::THUMBS_SEPARATOR . $fileInfos->getFilename() .'" rel="data-lity" data-lity=""><img src="'. str_replace('source','thumb',$directory) . '/' . $fileInfos->getFilename() . '"></a>' '<a href="' . str_replace('source','thumb',$directory) . '/' . self::THUMBS_SEPARATOR . $fileInfos->getFilename() .'" rel="data-lity" data-lity=""><img src="'. str_replace('source','thumb',$directory) . '/' . $fileInfos->getFilename() . '"></a>'
]; ];
@ -433,7 +450,7 @@ class gallery extends common {
} }
} }
// Tri des images // Tri des images
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) { switch ($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort'])) {
case self::SORT_HAND: case self::SORT_HAND:
$positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'positions']); $positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'positions']);
if ($positions) { if ($positions) {
@ -466,7 +483,7 @@ class gallery extends common {
} }
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']), 'title' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'name']),
'view' => 'edit', 'view' => 'edit',
'vendor' => [ 'vendor' => [
'tablednd' 'tablednd'
@ -479,10 +496,12 @@ class gallery extends common {
* Accueil (deux affichages en un pour éviter une url à rallonge) * Accueil (deux affichages en un pour éviter une url à rallonge)
*/ */
public function index() { public function index() {
// Mise à jour des données de module
$this->update();
// Images d'une galerie // Images d'une galerie
if($this->getUrl(1)) { if($this->getUrl(1)) {
// La galerie n'existe pas // La galerie n'existe pas
if($this->getData(['module', $this->getUrl(0), $this->getUrl(1)]) === null) { if($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1)]) === null) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'access' => false 'access' => false
@ -491,13 +510,13 @@ class gallery extends common {
// La galerie existe // La galerie existe
else { else {
// Images de la galerie // Images de la galerie
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'directory']); $directory = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'directory']);
if(is_dir($directory)) { if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory); $iterator = new DirectoryIterator($directory);
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())) {
self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]); self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]);
$picturesSort[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'positions', str_replace('.','',$fileInfos->getFilename())]); $picturesSort[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'positions', str_replace('.','',$fileInfos->getFilename())]);
// 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(),
@ -511,7 +530,7 @@ class gallery extends common {
} }
} }
// Tri des images par ordre alphabétique // Tri des images par ordre alphabétique
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'sort'])) { switch ($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'sort'])) {
case self::SORT_HAND: case self::SORT_HAND:
asort($picturesSort); asort($picturesSort);
if ($picturesSort) { if ($picturesSort) {
@ -535,7 +554,7 @@ class gallery extends common {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'showBarEditButton' => true, 'showBarEditButton' => true,
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'name']), 'title' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'name']),
'view' => 'gallery' 'view' => 'gallery'
]); ]);
} }
@ -552,7 +571,7 @@ class gallery extends common {
// Liste des galeries // Liste des galeries
else { else {
// Tri des galeries suivant l'ordre défini // Tri des galeries suivant l'ordre défini
$g = $this->getData(['module', $this->getUrl(0)]); $g = $this->getData(['module', $this->getUrl(0), 'content']);
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); $p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position');
asort($p,SORT_NUMERIC); asort($p,SORT_NUMERIC);
$galleries = []; $galleries = [];

View File

@ -20,12 +20,12 @@
<div class="col5"> <div class="col5">
<?php echo template::text('galleryEditName', [ <?php echo template::text('galleryEditName', [
'label' => 'Nom', 'label' => 'Nom',
'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']) 'value' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'name'])
]); ?> ]); ?>
</div> </div>
<div class="col4"> <div class="col4">
<?php echo template::hidden('galleryEditDirectoryOld', [ <?php echo template::hidden('galleryEditDirectoryOld', [
'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']), 'value' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'directory']),
'noDirty' => true // Désactivé à cause des modifications en ajax 'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?> ]); ?>
<?php echo template::select('galleryEditDirectory', [], [ <?php echo template::select('galleryEditDirectory', [], [
@ -35,7 +35,7 @@
</div> </div>
<div class="col3"> <div class="col3">
<?php echo template::select('galleryEditSort', $module::$sort, [ <?php echo template::select('galleryEditSort', $module::$sort, [
'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort']), 'selected' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort']),
'label' => 'Tri des images', 'label' => 'Tri des images',
'help' => 'Tri manuel : déplacez le images dans le tableau ci-dessous. L\'ordre est sauvegardé automatiquement.' 'help' => 'Tri manuel : déplacez le images dans le tableau ci-dessous. L\'ordre est sauvegardé automatiquement.'
]); ?> ]); ?>
@ -43,7 +43,7 @@
<div clas="row"> <div clas="row">
<div class="col12"> <div class="col12">
<?php echo template::checkbox('galleryEditFullscreen', true, 'Mode plein écran automatique' , [ <?php echo template::checkbox('galleryEditFullscreen', true, 'Mode plein écran automatique' , [
'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'fullScreen']), 'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'fullScreen']),
'help' => 'A l\'ouverture de la galerie, la première image est affichée en plein écran.' 'help' => 'A l\'ouverture de la galerie, la première image est affichée en plein écran.'
]); ?> ]); ?>
</div> </div>

View File

@ -46,7 +46,7 @@ class search extends common {
]; ];
/** /**
* Mise à jour du module * Mise à jour du module
* Appelée par les fonctions index et config * Appelée par les fonctions index et config
*/ */