Ignore:
Timestamp:
Dec 5, 2004, 11:47:46 PM (19 years ago)
Author:
plg
Message:
  • ordering function moved from admin/update to admin/include/function
  • remote_site uses ordering and update_global_rank
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r637 r638  
    11651165  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    11661166}
     1167
     1168/**
     1169 * order categories (update categories.rank and global_rank database fields)
     1170 *
     1171 * the purpose of this function is to give a rank for all categories
     1172 * (insides its sub-category), even the newer that have none at te
     1173 * beginning. For this, ordering function selects all categories ordered by
     1174 * rank ASC then name ASC for each uppercat.
     1175 *
     1176 * @returns void
     1177 */
     1178function ordering()
     1179{
     1180  $current_rank = 0;
     1181  $current_uppercat = '';
     1182               
     1183  $query = '
     1184SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat
     1185  FROM '.CATEGORIES_TABLE.'
     1186  ORDER BY id_uppercat,rank,name
     1187;';
     1188  $result = pwg_query($query);
     1189  $datas = array();
     1190  while ($row = mysql_fetch_array($result))
     1191  {
     1192    if ($row['id_uppercat'] != $current_uppercat)
     1193    {
     1194      $current_rank = 0;
     1195      $current_uppercat = $row['id_uppercat'];
     1196    }
     1197    $data = array('id' => $row['id'], 'rank' => ++$current_rank);
     1198    array_push($datas, $data);
     1199  }
     1200
     1201  $fields = array('primary' => array('id'), 'update' => array('rank'));
     1202  mass_updates(CATEGORIES_TABLE, $fields, $datas);
     1203}
    11671204?>
Note: See TracChangeset for help on using the changeset viewer.