Tri des images WIP

This commit is contained in:
Fred Tempez 2020-04-08 17:46:29 +02:00
parent 638606c87a
commit 179f27270c
5 changed files with 83 additions and 100 deletions

View File

@ -547,7 +547,7 @@ class init extends common {
'icebergjpg' => 'Un iceberg', 'icebergjpg' => 'Un iceberg',
'meadowjpg' => 'Une prairie' 'meadowjpg' => 'Une prairie'
], ],
'postion' => [ 'position' => [
'desertjpg' => 3, 'desertjpg' => 3,
'icebergjpg' => 1, 'icebergjpg' => 1,
'meadowjpg' => 2 'meadowjpg' => 2
@ -566,7 +566,7 @@ class init extends common {
'cosmosjpg' => 'Le cosmos', 'cosmosjpg' => 'Le cosmos',
'nebulajpg' => 'Une nébuleuse' 'nebulajpg' => 'Une nébuleuse'
], ],
'postion' => [ 'position' => [
'earthjpg' => 1, 'earthjpg' => 1,
'cosmosjpg' => 3, 'cosmosjpg' => 3,
'nebulajpg' => 2 'nebulajpg' => 2

View File

@ -25,7 +25,7 @@ class gallery extends common {
public static $sort = [ public static $sort = [
'SORT_ASC' => 'Alphabétique ', 'SORT_ASC' => 'Alphabétique ',
'SORT_DSC' => 'Alphabétique inversé', 'SORT_DSC' => 'Alphabétique inversé',
'none' => 'Aucun tri', 'SORT_HAND' => 'Tri manuel',
]; ];
public static $directories = []; public static $directories = [];
@ -58,7 +58,7 @@ class gallery extends common {
'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']), 'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']),
'homePicture' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','homePicture']), 'homePicture' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','homePicture']),
'sort' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','sort']), 'sort' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','sort']),
'position' => $i + 1 'position' => $i
], ],
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']) 'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend'])
]]); ]]);
@ -69,29 +69,6 @@ class gallery extends common {
header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() ); header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() );
} }
private function sortPicture() {
// Traitement du tri
$data = explode('&',($this->getInput('galleryEditFilterResponse')));
$data = str_replace('galleryTable%5B%5D=','',$data);
for($i=0;$i<count($data);$i++) {
$this->setData(['module', $this->getUrl(0), $data[$i], [
'config' => [
'position' => $this->getData(['module',$this->getUrl(0),$data[$i],'config'])
],
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']),
'position' => [
],
]]);
}
$this->saveData();
// Valeurs en sortie
// Recharge la page
header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() );
}
/** /**
* Configuration * Configuration
@ -175,7 +152,7 @@ class gallery extends common {
]]); ]]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(), 'redirect' => helper::baseUrl() . $this->getUrl(),
'notification' => 'Modifications enregistrées', 'notification' => 'Modifications enregistrées',
'state' => true 'state' => true
]); ]);
@ -257,48 +234,56 @@ class gallery extends common {
else { else {
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if($this->isPost()) {
if ($this->getInput('galleryEditFilterResponse')) { if ($this->getInput('galleryEditFormResponse')) {
self::sortPicture(); // Tri des images
$picturesPosition = explode('&',($this->getInput('galleryEditFormResponse')));
$picturesPosition = str_replace('galleryTable%5B%5D=','',$picturesPosition);
$picturesPosition = array_flip($picturesPosition);
} else { } else {
// Si l'id a changée $picturesPosition = $this->getData(['module',$this->getUrl(0),'position']);
$galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true);
if($galleryId !== $this->getUrl(2)) {
// Incrémente le nouvel id de la galerie
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)]));
// 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
$homePicture = array_keys($this->getInput('homePicture', null));
// Sauvegarder
$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),
'homePicture' => $homePicture[0],
'sort' => $this->getInput('galleryEditSort'),
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
],
'legend' => $legends
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Modifications enregistrées',
'state' => true
]);
} }
// Si l'id a changée
$galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true);
if($galleryId !== $this->getUrl(2)) {
// Incrémente le nouvel id de la galerie
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)]));
// 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
$homePicture = array_keys($this->getInput('homePicture', null));
// Sauvegarder
$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),
'homePicture' => $homePicture[0],
'sort' => $this->getInput('galleryEditSort'),
'position' => count($this->getData(['module',$this->getUrl(0)]))
],
'legend' => $legends,
'position' => empty($picturesPosition) ? $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'position']) : $picturesPosition
]]);
// Valeurs en sortie
$this->addOutput([
//'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $this->getUrl(2) . '/' . $_SESSION['csrf'],
'notification' => 'Modifications enregistrées',
'state' => true
]);
} }
// 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), $this->getUrl(2), '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())) {
// Créer la miniature si manquante // Créer la miniature si manquante
@ -307,35 +292,44 @@ class gallery extends common {
str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()), str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()),
self::THUMBS_WIDTH); self::THUMBS_WIDTH);
} }
self::$pictures[$fileInfos->getFilename()] = [ self::$pictures[str_replace('.','',$fileInfos->getFilename())] = [
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), $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), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())])
]), ]),
'<a href="'. str_replace('source','thumb',$directory) . '/mini_' . $fileInfos->getFilename() .'" rel="data-lity" data-lity=""><img src="'. str_replace('source','thumb',$directory) . '/' . $fileInfos->getFilename() . '"></a>' '<a href="'. str_replace('source','thumb',$directory) . '/mini_' . $fileInfos->getFilename() .'" rel="data-lity" data-lity=""><img src="'. str_replace('source','thumb',$directory) . '/' . $fileInfos->getFilename() . '"></a>'
]; ];
// Tableau des id des galleries pour le drag and drop self::$picturesId [] = str_replace('.','',$fileInfos->getFilename());
self::$picturesId[] = $fileInfos->getFilename();
} }
} }
// Tri des images par ordre alphabétique // Tri des images par ordre alphabétique
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) { switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) {
case 'none': case 'SORT_HAND':
$positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'position']);
if ($positions) {
foreach ($positions as $position => $name) {
$tempPictures [] = self::$pictures[$position];
$tempPicturesId [] = $position;
}
self::$pictures = $tempPictures;
self::$picturesId = $tempPicturesId;
}
break; break;
case 'SORT_ASC':
ksort(self::$pictures,SORT_NATURAL);
sort(self::$picturesId,SORT_NATURAL);
break;
case 'SORT_DSC': case 'SORT_DSC':
krsort(self::$pictures,SORT_NATURAL); krsort(self::$pictures,SORT_NATURAL);
rsort(self::$picturesId,SORT_NATURAL);
break; break;
case 'SORT_ASC':
default:
ksort(self::$pictures,SORT_NATURAL);
break;
} }
} }
// Valeurs en sortie // Valeurs en sortie
@ -370,7 +364,8 @@ class gallery extends common {
$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), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]);
$picturesSort[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'position', str_replace('.','',$fileInfos->getFilename())]);
// Créer la miniature si manquante // Créer la miniature si manquante
if (!file_exists( str_replace('source','thumb',$fileInfos->getPathname()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) { if (!file_exists( str_replace('source','thumb',$fileInfos->getPathname()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
$this->makeThumb($fileInfos->getPathname(), $this->makeThumb($fileInfos->getPathname(),
@ -385,8 +380,15 @@ 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), $this->getUrl(1), 'config', 'sort'])) {
case 'none': case 'SORT_HAND':
break; asort($picturesSort);
if ($picturesSort) {
foreach ($picturesSort as $name => $position) {
$temp[$name] = self::$pictures[$name];
}
self::$pictures = $temp;
break;
}
case 'SORT_DSC': case 'SORT_DSC':
krsort(self::$pictures,SORT_NATURAL); krsort(self::$pictures,SORT_NATURAL);
break; break;
@ -402,10 +404,6 @@ class gallery extends common {
$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), $this->getUrl(1), 'config', 'name']),
/* Désactivé car SLB est actif pour tout le site
'vendor' => [
'simplelightbox'
],*/
'view' => 'gallery' 'view' => 'gallery'
]); ]);
} }

View File

@ -26,7 +26,7 @@ $( document ).ready(function() {
// Activer le bouton de tri uniquement après un tri // Activer le bouton de tri uniquement après un tri
$("#galleryTable").click(function() { $("#galleryTable").click(function() {
if ($("#galleryConfigFilterResponse").val() != "") { if ($("#galleryEditFilterResponse").val() != "") {
$(":input[type='submit']").prop('disabled', false); $(":input[type='submit']").prop('disabled', false);
} }
}); });

View File

@ -61,15 +61,8 @@ $('.homePicture').click(function(){
$( document ).ready(function() { $( document ).ready(function() {
$("#galleryTable").tableDnD({ $("#galleryTable").tableDnD({
onDrop: function(table, row) { onDrop: function(table, row) {
$("#galleryEditFilterResponse").val($.tableDnD.serialize()); $("#galleryEditFormResponse").val($.tableDnD.serialize());
}, },
serializeRegexp: "[^\_]*$" serializeRegexp: "[^\_]*$"
}); });
}); });
// Activer le bouton de tri uniquement après un tri
$("#galleryTable").click(function() {
if ($("#galleryEditResponse").val() != "") {
$(":input[type='submit']").prop('disabled', false);
}
});

View File

@ -44,24 +44,16 @@
</div> </div>
</div> </div>
</div> </div>
<?php echo template::formClose(); ?>
<?php echo template::formOpen('galleryEditFilterForm'); ?>
<?php if($module::$pictures): ?> <?php if($module::$pictures): ?>
<?php echo template::table([1, 4, 1, 5, 1], $module::$pictures, ['','Image', 'Couverture','Légende',''],['id' => 'galleryTable'], $module::$picturesId ); ?> <?php echo template::table([1, 4, 1, 5, 1], $module::$pictures, ['','Image', 'Couverture','Légende',''],['id' => 'galleryTable'], $module::$picturesId ); ?>
<?php echo template::hidden('galleryEditFilterResponse'); ?> <?php echo template::hidden('galleryEditFormResponse'); ?>
<?php echo template::hidden('galleryEditFilterSubmit',[ <?php echo template::hidden('galleryEditSubmit',[
'value' => false 'value' => false
]); ?> ]); ?>
<?php else: ?> <?php else: ?>
<?php echo template::speech('Aucune galerie.'); ?> <?php echo template::speech('Aucune galerie.'); ?>
<?php endif; ?> <?php endif; ?>
<div class="row">
<div class="col2 offset10">
<?php echo template::submit('galleryEditFilterSubmit', [
'value' => 'Trier',
'disabled' => true
]); ?>
</div>
</div> </div>
<?php echo template::formClose(); ?> <?php echo template::formClose(); ?>
<div class="moduleVersion">Version <div class="moduleVersion">Version