Announcement

  •  » Requests
  •  » Add sort by natural order for albums

#1 2021-04-07 21:17:07

Crythes
Member
2020-01-23
112

Add sort by natural order for albums

Hello/Hi/Greetings,

Ordering albums by natural order is something that is a must for me, so in the older version I made changes to the website files as there was no way of doing that by default. I am really not sure why this option is not available, since I do think most people will find it useful and it should be easy to implement. I saw that in the new version, the album management system has been changed, with ordering albums getting its own page so to speak. I found that by applying the following changes to cat_move.php and cat_move.tpl I was able to get back the ability to sort albums by natural order once again.

In cat_move.php,

from:

$sort_orders = array(
  'name ASC',
  'name DESC',
  'date_creation DESC',
  'date_creation ASC',
  'date_available DESC',
  'date_available ASC'
);

To:

$sort_orders = array(
  'NATURAL sorting',
  'name ASC',
  'name DESC',
  'date_creation DESC',
  'date_creation ASC',
  'date_available DESC',
  'date_available ASC'
);


From this:

array_multisort(
    $sort,
    SORT_REGULAR,
    'ASC' == $order_by_asc ? SORT_ASC : SORT_DESC,
    $categories
    );

To:

if($order_by_field == 'NATURAL'){
    array_multisort(
     $sort,
     SORT_NATURAL,
     $categories
     );
    } else if($order_by_field == 'name') {
      array_multisort(
        $sort,
        SORT_REGULAR,
        'ASC' == $order_by_asc ? SORT_ASC : SORT_DESC,
        $categories
        );
    }

And in cat_move.tpl, just added a label field:

<label class="font-checkbox">
          <span class="icon-dot-circled"> </span>
          <input type="radio" value="NATURAL sorting" name="order" checked>
          {'Natural Order'|@translate}
        </label>

        <label class="font-checkbox">
          <span class="icon-dot-circled"> </span>
          <input type="radio" value="name ASC" name="order">
          {'Album name, A &rarr; Z'|@translate}
        </label>
....
..
..


I am not a PHP programmer so this may not be the best solution, but it seems to be working. It would really be great if the ability to sort by natural order was added by default, since it seems to be quite easy to implement and I really don't feel writing a plugin for this sort of thing is necessary, yet I have to keep changing the website files whenever a new updates comes...

Last edited by Crythes (2021-04-07 22:42:40)

Offline

 

#2 2021-04-08 03:42:28

executive
Member
2017-08-16
1214

Re: Add sort by natural order for albums

what is natural order

Offline

 

#3 2021-04-08 09:54:39

Crythes
Member
2020-01-23
112

Re: Add sort by natural order for albums

https://www.php.net/manual/en/function.natsort.php

Sure, you could add 0 in front of the single digit numbers but that is far from ideal.

Offline

 

#4 2021-04-17 11:24:06

carry0987
Member
2021-04-12
1

Re: Add sort by natural order for albums

Great work, I think this feature should be added to photo ordering too

Offline

 

#5 2021-08-11 17:06:55

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: Add sort by natural order for albums

Offline

 
  •  » Requests
  •  » Add sort by natural order for albums

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact