[2.4] Constantes de tri - pas de tri dans la création de galerie dans la config

This commit is contained in:
Fred Tempez 2020-04-13 18:13:01 +02:00
parent bc0185729c
commit ea2085d584
2 changed files with 17 additions and 19 deletions

View File

@ -14,6 +14,10 @@
class gallery extends common { class gallery extends common {
const SORT_ASC = 'SORT_ASC';
const SORT_DSC = 'SORT_DSC';
const SORT_HAND = 'SORT_HAND';
public static $actions = [ public static $actions = [
'config' => self::GROUP_MODERATOR, 'config' => self::GROUP_MODERATOR,
'delete' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR,
@ -24,9 +28,9 @@ class gallery extends common {
]; ];
public static $sort = [ public static $sort = [
'SORT_ASC' => 'Alphabétique ', self::SORT_ASC => 'Alphabétique ',
'SORT_DSC' => 'Alphabétique inversé', self::SORT_DSC => 'Alphabétique inversé',
'SORT_HAND' => 'Tri manuel' self::SORT_HAND => 'Tri manuel'
]; ];
public static $directories = []; public static $directories = [];
@ -140,7 +144,7 @@ class gallery extends common {
'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' => $this->getInput('galleryConfigSort'), 'sort' => self::SORT_ASC,
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1 'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
], ],
'legend' => [], 'legend' => [],
@ -235,7 +239,7 @@ class gallery extends common {
*/ */
$picturesPosition = []; $picturesPosition = [];
if ($this->getInput('galleryEditFormResponse') && if ($this->getInput('galleryEditFormResponse') &&
$this->getInput('galleryEditSort') === 'SORT_HAND') { $this->getInput('galleryEditSort') === self::SORT_HAND) {
// Tri des images si valeur de retour et choix manuel // Tri des images si valeur de retour et choix manuel
$picturesPosition = explode('&',($this->getInput('galleryEditFormResponse'))); $picturesPosition = explode('&',($this->getInput('galleryEditFormResponse')));
$picturesPosition = str_replace('galleryTable%5B%5D=','',$picturesPosition); $picturesPosition = str_replace('galleryTable%5B%5D=','',$picturesPosition);
@ -306,7 +310,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), $this->getUrl(2), 'config', 'sort'])) {
case 'SORT_HAND': case self::SORT_HAND:
$positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'position']); $positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'position']);
if ($positions) { if ($positions) {
foreach ($positions as $position => $name) { foreach ($positions as $position => $name) {
@ -317,11 +321,11 @@ class gallery extends common {
self::$picturesId = $tempPicturesId; self::$picturesId = $tempPicturesId;
} }
break; break;
case 'SORT_ASC': case self::SORT_ASC:
ksort(self::$pictures,SORT_NATURAL); ksort(self::$pictures,SORT_NATURAL);
sort(self::$picturesId,SORT_NATURAL); sort(self::$picturesId,SORT_NATURAL);
break; break;
case 'SORT_DSC': case self::SORT_DSC:
krsort(self::$pictures,SORT_NATURAL); krsort(self::$pictures,SORT_NATURAL);
rsort(self::$picturesId,SORT_NATURAL); rsort(self::$picturesId,SORT_NATURAL);
break; break;
@ -375,7 +379,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), $this->getUrl(1), 'config', 'sort'])) {
case 'SORT_HAND': case self::SORT_HAND:
asort($picturesSort); asort($picturesSort);
if ($picturesSort) { if ($picturesSort) {
foreach ($picturesSort as $name => $position) { foreach ($picturesSort as $name => $position) {
@ -384,10 +388,10 @@ class gallery extends common {
self::$pictures = $temp; self::$pictures = $temp;
break; break;
} }
case 'SORT_DSC': case self::SORT_DSC:
krsort(self::$pictures,SORT_NATURAL); krsort(self::$pictures,SORT_NATURAL);
break; break;
case 'SORT_ASC': case self::SORT_ASC:
default: default:
ksort(self::$pictures,SORT_NATURAL); ksort(self::$pictures,SORT_NATURAL);
break; break;

View File

@ -14,12 +14,12 @@
<div class="block"> <div class="block">
<h4>Ajouter une galerie</h4> <h4>Ajouter une galerie</h4>
<div class="row"> <div class="row">
<div class="col4"> <div class="col6">
<?php echo template::text('galleryConfigName', [ <?php echo template::text('galleryConfigName', [
'label' => 'Nom' 'label' => 'Nom'
]); ?> ]); ?>
</div> </div>
<div class="col4"> <div class="col5">
<?php echo template::hidden('galleryConfigDirectoryOld', [ <?php echo template::hidden('galleryConfigDirectoryOld', [
'noDirty' => true // Désactivé à cause des modifications en ajax 'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?> ]); ?>
@ -28,12 +28,6 @@
'noDirty' => true // Désactivé à cause des modifications en ajax 'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?> ]); ?>
</div> </div>
<div class="col3">
<?php echo template::select('galleryConfigSort', $module::$sort, [
'label' => 'Tri des images',
'help' => 'Les images sont triées par nom de fichier grâce à la méthode naturelle qui donne de meilleurs résultats lorsque les images sont numérotées.'
]); ?>
</div>
<div class="col1 verticalAlignBottom"> <div class="col1 verticalAlignBottom">
<?php echo template::submit('galleryConfigSubmit', [ <?php echo template::submit('galleryConfigSubmit', [
'ico' => '', 'ico' => '',