@@ -264,23 +264,23 @@ function index()
264
264
265
265
// Pagination
266
266
$ pagination = new Pagination (array (
267
- 'query_string ' => 'page ' ,
268
- 'items_per_page ' => (int ) Kohana::config ('settings.items_per_page_admin ' ),
269
- 'total_items ' => ORM ::factory ('category ' )
270
- ->where ('parent_id ' ,'0 ' )
271
- ->count_all ()
272
- ));
267
+ 'query_string ' => 'page ' ,
268
+ 'items_per_page ' => (int ) Kohana::config ('settings.items_per_page_admin ' ),
269
+ 'total_items ' => ORM ::factory ('category ' )
270
+ ->where ('parent_id ' ,'0 ' )
271
+ ->count_all ()
272
+ ));
273
273
274
274
$ categories = ORM ::factory ('category ' )
275
- ->with ('category_lang ' )
276
- ->where ('parent_id ' ,'0 ' )
277
- ->orderby ('category_title ' , 'asc ' )
278
- -> find_all (( int ) Kohana:: config ( ' settings.items_per_page_admin ' ),
279
- $ pagination ->sql_offset );
275
+ ->with ('category_lang ' )
276
+ ->where ('parent_id ' ,'0 ' )
277
+ ->orderby ('category_position ' , 'asc ' )
278
+ -> orderby ( ' category_title ' , ' asc ' )
279
+ -> find_all (( int ) Kohana:: config ( ' settings.items_per_page_admin ' ), $ pagination ->sql_offset );
280
280
281
281
$ parents_array = ORM ::factory ('category ' )
282
- ->where ('parent_id ' ,'0 ' )
283
- ->select_list ('id ' , 'category_title ' );
282
+ ->where ('parent_id ' ,'0 ' )
283
+ ->select_list ('id ' , 'category_title ' );
284
284
285
285
// add none to the list
286
286
$ parents_array [0 ] = "--- Top Level Category --- " ;
@@ -301,13 +301,64 @@ function index()
301
301
302
302
// Javascript Header
303
303
$ this ->template ->colorpicker_enabled = TRUE ;
304
+ $ this ->template ->tablerowsort_enabled = TRUE ;
304
305
$ this ->template ->js = new View ('admin/categories_js ' );
305
306
$ this ->template ->form_error = $ form_error ;
306
307
307
308
$ this ->template ->content ->locale_array = $ locales ;
308
309
$ this ->template ->js ->locale_array = $ locales ;
309
310
}
310
311
312
+ public function category_sort ()
313
+ {
314
+ $ this ->auto_render = FALSE ;
315
+ $ this ->template = "" ;
316
+
317
+ if ($ _POST )
318
+ {
319
+ if (isset ($ _POST ['categories ' ])
320
+ AND ! empty ($ _POST ['categories ' ])
321
+ )
322
+ {
323
+ $ categories = array_map ('trim ' , explode (', ' , $ _POST ['categories ' ]));
324
+ $ i = 0 ;
325
+ $ parent_id = 0 ;
326
+ foreach ($ categories as $ category_id )
327
+ {
328
+ if ($ category_id )
329
+ {
330
+ $ category = ORM ::factory ('category ' , $ category_id );
331
+ if ($ category ->loaded )
332
+ {
333
+ if ($ i == 0 AND $ category ->parent_id != 0 )
334
+ { // ERROR!!!!!!!! WHY ARE YOU TRYING TO PLACE A SUBCATEGORY ABOVE A CATEGORY???
335
+ echo "ERROR " ;
336
+ return ;
337
+ }
338
+
339
+ if ($ category ->parent_id == 0 )
340
+ {
341
+ // Set Parent ID
342
+ $ parent_id = $ category ->id ;
343
+ }
344
+ else
345
+ {
346
+ if ($ parent_id )
347
+ {
348
+ $ category ->parent_id = $ parent_id ;
349
+ }
350
+ }
351
+
352
+ $ category ->category_position = $ i ;
353
+ $ category ->save ();
354
+ }
355
+ }
356
+ $ i ++;
357
+ }
358
+ }
359
+ }
360
+ }
361
+
311
362
/*
312
363
Manage Public Listing for External Applications
313
364
*/
0 commit comments