Announcement

  •  » Requests
  •  » sort categories and sub-categories alpha-numerically reverse - default

#1 2010-07-23 19:06:25

JulianR
Guest

sort categories and sub-categories alpha-numerically reverse - default

Good morning, I wonder how I can do to change the piwigo ... or if there is a default option to put all my categories and subcategories as follows: "sort categories and sub-categories reverse alpha-numerically by default"


How I can achieve this? Modifying one of these two files. anyone can give me some help?

admin/cat_list.php

include/config_default.inc.php

 

#2 2010-07-23 23:40:07

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

Re: sort categories and sub-categories alpha-numerically reverse - default

Hi JulianR,

I see that you're expecting [Bugtracker] ticket 408 very much :-)

I've added it to Piwigo core. It will be available in Piwigo 2.2 (Fall 2010 approximately).

If you want such a feature in Piwigo 2.1, it requires to write a specific plugin. Can you wait for Piwigo 2.2? (you can read what in changed in [Subversion] r6698 but I advise you keep your Piwigo core files as they are or you will loose your modifications on next security upgrade)

Offline

 

#3 2010-07-24 01:49:24

JulianR
Guest

Re: sort categories and sub-categories alpha-numerically reverse - default

wow! many thanks, I'm super thankful ... I was waiting for this feature long ago ... Quedo super good function ... I am very nice .. and super practical ... Thank you very much ... If I can do something for you feel free to notify us.



I'll make a backup of the files that are modified in No. 6698, for when you leave the new version of piwigo, replace the files in place and I guess this way you can update normally ... right?

 

#4 2010-07-24 23:48:44

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

Re: sort categories and sub-categories alpha-numerically reverse - default

JulianR wrote:

I'll make a backup of the files that are modified in No. 6698, for when you leave the new version of piwigo, replace the files in place and I guess this way you can update normally ... right?

This is not a good solution. If Piwigo 2.1.3 modifies the file admin/cat_list.php and you overwrite it with what I did in [Subversion] r6698 you will have a wrong set of files with possible broken features, impossible to foresee.

If you want, I can propose you a "Personnal Plugin" (very easy to add) that would perform this automatic global reverse sort on all your categories when you perform a [Administration > Tools > Maintenance > Update categories information] action. The drawback is that you can't choose a specific category, it's on the whole category tree. Would that suit you before Piwigo 2.2?

Offline

 

#5 2010-07-26 11:32:43

JulianR
Guest

Re: sort categories and sub-categories alpha-numerically reverse - default

plg wrote:

JulianR wrote:

I'll make a backup of the files that are modified in No. 6698, for when you leave the new version of piwigo, replace the files in place and I guess this way you can update normally ... right?

This is not a good solution. If Piwigo 2.1.3 modifies the file admin/cat_list.php and you overwrite it with what I did in [Subversion] r6698 you will have a wrong set of files with possible broken features, impossible to foresee.

If you want, I can propose you a "Personnal Plugin" (very easy to add) that would perform this automatic global reverse sort on all your categories when you perform a [Administration > Tools > Maintenance > Update categories information] action. The drawback is that you can't choose a specific category, it's on the whole category tree. Would that suit you before Piwigo 2.2?

-------------------------------------------

be nice to have this option as a personal plug, I have to do to make it? How I can help?

 

#6 2010-07-26 23:44:32

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

Re: sort categories and sub-categories alpha-numerically reverse - default

1) activate the LocalFiles Editor plugin
2) go to [Administration > Plugins > LocalFiles Editor > Personal Plugin] and paste the following code:

Code:

<?php
/*
Plugin Name: Personal Plugin
Version: 1.0
Description: Personal Plugin
Plugin URI: http://piwigo.org
Author:
Author URI:
*/

add_event_handler('loc_begin_admin', 'sort_all_categories');
function sort_all_categories()
{
  if (!isset($_GET['page']) or 'maintenance' != $_GET['page'])
  {
    return null;
  }

  if (!isset($_GET['action']) or 'categories' != $_GET['action'])
  {
    return null;
  }

  $categories = array();
  $names = array();

  $query = '
SELECT id, name, id_uppercat
  FROM '.CATEGORIES_TABLE.'
;';
  $result = pwg_query($query);
  while ($row = pwg_db_fetch_assoc($result))
  {
    array_push(
      $categories,
      array(
        'id' => $row['id'],
        'id_uppercat' => $row['id_uppercat'],
        )
      );
    array_push(
      $names,
      $row['name']
      );
  }

  array_multisort(
    $names,
    SORT_REGULAR,
    SORT_DESC,
    $categories
  );

  $current_rank_for_id_uppercat = array();
  $current_rank = 0;
  
  $datas = array();
  foreach ($categories as $category)
  {
    if (is_array($category))
    {
      $id = $category['id'];
      $id_uppercat = $category['id_uppercat'];

      if (!isset($current_rank_for_id_uppercat[$id_uppercat]))
      {
        $current_rank_for_id_uppercat[$id_uppercat] = 0;
      }
      $current_rank = ++$current_rank_for_id_uppercat[$id_uppercat];
    }
    else
    {
      $id = $category;
      $current_rank++;
    }
    
    array_push($datas, array('id' => $id, 'rank' => $current_rank));
  }
  $fields = array('primary' => array('id'), 'update' => array('rank'));
  mass_updates(CATEGORIES_TABLE, $fields, $datas);
}

?>

Now, each time you will perform an [Administration > Tools > Maintenance > Update categories information] action, you will have an automatic revert sort on your whole category tree.

Offline

 
  •  » Requests
  •  » sort categories and sub-categories alpha-numerically reverse - default

Board footer

Powered by FluxBB

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