aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2004-12-05 22:47:46 +0000
committerplegall <plg@piwigo.org>2004-12-05 22:47:46 +0000
commit1ab32cccb7eaf8f5707c06895179e31743dceae9 (patch)
treec87e0bc8eabd428be3cbc3e95e1c4fd830bdcea1 /admin/include
parent484a431a7e257ab6f8484a9e4100d70657da17ea (diff)
- ordering function moved from admin/update to admin/include/function
- remote_site uses ordering and update_global_rank git-svn-id: http://piwigo.org/svn/trunk@638 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include')
-rw-r--r--admin/include/functions.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 987cddb9a..467a498f6 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1164,4 +1164,41 @@ SELECT image_id
'update' => array('representative_picture_id'));
mass_updates(CATEGORIES_TABLE, $fields, $datas);
}
+
+/**
+ * order categories (update categories.rank and global_rank database fields)
+ *
+ * the purpose of this function is to give a rank for all categories
+ * (insides its sub-category), even the newer that have none at te
+ * beginning. For this, ordering function selects all categories ordered by
+ * rank ASC then name ASC for each uppercat.
+ *
+ * @returns void
+ */
+function ordering()
+{
+ $current_rank = 0;
+ $current_uppercat = '';
+
+ $query = '
+SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat
+ FROM '.CATEGORIES_TABLE.'
+ ORDER BY id_uppercat,rank,name
+;';
+ $result = pwg_query($query);
+ $datas = array();
+ while ($row = mysql_fetch_array($result))
+ {
+ if ($row['id_uppercat'] != $current_uppercat)
+ {
+ $current_rank = 0;
+ $current_uppercat = $row['id_uppercat'];
+ }
+ $data = array('id' => $row['id'], 'rank' => ++$current_rank);
+ array_push($datas, $data);
+ }
+
+ $fields = array('primary' => array('id'), 'update' => array('rank'));
+ mass_updates(CATEGORIES_TABLE, $fields, $datas);
+}
?>