Changeset 28934 for trunk/admin/cat_list.php
- Timestamp:
- Jul 3, 2014, 3:18:12 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_list.php
r28587 r28934 41 41 } 42 42 43 $sort_orders = array( 44 'name ASC' => l10n('Album name, A → Z'), 45 'name DESC' => l10n('Album name, Z → A'), 46 'date_creation DESC' => l10n('Date created, new → old'), 47 'date_creation ASC' => l10n('Date created, old → new'), 48 'date_available DESC' => l10n('Date posted, new → old'), 49 'date_available ASC' => l10n('Date posted, old → new'), 50 ); 51 43 52 // +-----------------------------------------------------------------------+ 44 53 // | functions | … … 87 96 } 88 97 98 function get_categories_ref_date($ids, $field='date_available', $minmax='max') 99 { 100 // we need to work on the whole tree under each category, even if we don't 101 // want to sort sub categories 102 $category_ids = get_subcat_ids($ids); 103 104 // search for the reference date of each album 105 $query = ' 106 SELECT 107 category_id, 108 '.$minmax.'('.$field.') as ref_date 109 FROM '.IMAGE_CATEGORY_TABLE.' 110 JOIN '.IMAGES_TABLE.' ON image_id = id 111 WHERE category_id IN ('.implode(',', $category_ids).') 112 GROUP BY category_id 113 ;'; 114 $ref_dates = query2array($query, 'category_id', 'ref_date'); 115 116 // the iterate on all albums (having a ref_date or not) to find the 117 // reference_date, with a search on sub-albums 118 $query = ' 119 SELECT 120 id, 121 uppercats 122 FROM '.CATEGORIES_TABLE.' 123 WHERE id IN ('.implode(',', $category_ids).') 124 ;'; 125 $uppercats_of = query2array($query, 'id', 'uppercats'); 126 127 foreach (array_keys($uppercats_of) as $cat_id) 128 { 129 // find the subcats 130 $subcat_ids = array(); 131 132 foreach ($uppercats_of as $id => $uppercats) 133 { 134 if (preg_match('/(^|,)'.$cat_id.'(,|$)/', $uppercats)) 135 { 136 $subcat_ids[] = $id; 137 } 138 } 139 140 $to_compare = array(); 141 foreach ($subcat_ids as $id) 142 { 143 if (isset($ref_dates[$id])) 144 { 145 $to_compare[] = $ref_dates[$id]; 146 } 147 } 148 149 if (count($to_compare) > 0) 150 { 151 $ref_dates[$cat_id] = 'max' == $minmax ? max($to_compare) : min($to_compare); 152 } 153 else 154 { 155 $ref_dates[$cat_id] = null; 156 } 157 } 158 159 // only return the list of $ids, not the sub-categories 160 $return = array(); 161 foreach ($ids as $id) 162 { 163 $return[$id] = $ref_dates[$id]; 164 } 165 166 return $return; 167 } 168 89 169 // +-----------------------------------------------------------------------+ 90 170 // | initialization | … … 153 233 elseif (isset($_POST['submitAutoOrder'])) 154 234 { 235 if (!isset($sort_orders[ $_POST['order_by'] ])) 236 { 237 die('Invalid sort order'); 238 } 239 155 240 $query = ' 156 241 SELECT id … … 167 252 168 253 $categories = array(); 169 $names = array(); 170 $id_uppercats = array(); 171 254 $sort = array(); 255 256 list($order_by_field, $order_by_asc) = explode(' ', $_POST['order_by']); 257 258 $order_by_date = false; 259 if (strpos($order_by_field, 'date_') === 0) 260 { 261 $order_by_date = true; 262 263 $ref_dates = get_categories_ref_date( 264 $category_ids, 265 $order_by_field, 266 'ASC' == $order_by_asc ? 'min' : 'max' 267 ); 268 } 269 172 270 $query = ' 173 271 SELECT id, name, id_uppercat … … 178 276 while ($row = pwg_db_fetch_assoc($result)) 179 277 { 278 if ($order_by_date) 279 { 280 $sort[] = $ref_dates[ $row['id'] ]; 281 } 282 else 283 { 284 $sort[] = $row['name']; 285 } 286 180 287 $categories[] = array( 181 288 'id' => $row['id'], 182 289 'id_uppercat' => $row['id_uppercat'], 183 290 ); 184 $names[] = $row['name'];185 291 } 186 292 187 293 array_multisort( 188 $ names,294 $sort, 189 295 SORT_REGULAR, 190 ' asc' == $_POST['ascdesc']? SORT_ASC : SORT_DESC,296 'ASC' == $order_by_asc ? SORT_ASC : SORT_DESC, 191 297 $categories 192 298 ); 299 193 300 save_categories_order($categories); 194 301 … … 224 331 'F_ACTION'=>$form_action, 225 332 'PWG_TOKEN' => get_pwg_token(), 333 'sort_orders' => $sort_orders, 334 'sort_order_checked' => array_shift(array_keys($sort_orders)), 226 335 )); 227 336
Note: See TracChangeset
for help on using the changeset viewer.