@@ -218,30 +218,40 @@ public function getView($categoryID = null)
218218 public function getDatatable ()
219219 {
220220 // Grab all the categories
221- $ categories = Category::orderBy ( ' created_at ' , 'DESC ' )-> get ( );
221+ $ categories = Category::select ( array ( ' id ' , 'name ' , ' category_type ' , ' require_acceptance ' ))-> whereNull ( ' deleted_at ' );
222222
223- $ actions = new \ Chumper \ Datatable \ Columns \ FunctionColumn ( ' actions ' , function ( $ categories ) {
224- return ' <a href=" ' . route ( ' update/category ' , $ categories-> id ). ' " class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href=" ' . route ( ' delete/category ' , $ categories ->id ). ' " data-content=" ' .Lang:: get ( ' admin/categories/message.delete.confirm ' ). ' " data-title=" ' .Lang ::get ('general.delete ' ). ' ' . htmlspecialchars ( $ categories -> name ). ' ?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> ' ;
225- });
223+ if (Input:: has ( ' search ' ) ) {
224+ $ categories = $ categories ->TextSearch (Input ::get ('search ' )) ;
225+ }
226226
227- return Datatable::collection ($ categories )
228- ->showColumns ('name ' )
229- ->addColumn ('category_type ' , function ($ categories ) {
230- return ucwords ($ categories ->category_type );
231- })
232- ->addColumn ('count ' , function ($ categories ) {
233- return ($ categories ->category_type =='asset ' ) ? link_to ('/admin/settings/categories/ ' .$ categories ->id .'/view ' , $ categories ->assetscount ()) : $ categories ->accessoriescount ();
234- })
235- ->addColumn ('acceptance ' , function ($ categories ) {
236- return ($ categories ->require_acceptance =='1 ' ) ? '<i class="fa fa-check" style="margin-right:50%;margin-left:50%;"></i> ' : '' ;
237- })
238- ->addColumn ('eula ' , function ($ categories ) {
239- return ($ categories ->getEula ()) ? '<i class="fa fa-check" style="margin-right:50%;margin-left:50%;"></i></a> ' : '' ;
240- })
241- ->addColumn ($ actions )
242- ->searchColumns ('name ' ,'category_type ' ,'count ' ,'acceptance ' ,'eula ' ,'actions ' )
243- ->orderColumns ('name ' ,'category_type ' ,'count ' ,'acceptance ' ,'eula ' ,'actions ' )
244- ->make ();
227+ $ allowed_columns = ['name ' ,'category_type ' ];
228+ $ order = Input::get ('order ' ) === 'asc ' ? 'asc ' : 'desc ' ;
229+ $ sort = in_array (Input::get ('sort ' ), $ allowed_columns ) ? Input::get ('sort ' ) : 'created_at ' ;
230+
231+ $ categories = $ categories ->orderBy ($ sort , $ order );
232+
233+ $ catCount = $ categories ->count ();
234+ $ categories = $ categories ->skip (Input::get ('offset ' ))->take (Input::get ('limit ' ))->get ();
235+
236+ $ rows = array ();
237+
238+ foreach ($ categories as $ category ) {
239+ $ actions = '<a href=" ' .route ('update/category ' , $ category ->id ).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href=" ' .route ('delete/category ' , $ category ->id ).'" data-content=" ' .Lang::get ('admin/categories/message.delete.confirm ' ).'" data-title=" ' .Lang::get ('general.delete ' ).' ' .htmlspecialchars ($ category ->name ).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> ' ;
240+
241+ $ rows [] = array (
242+ 'name ' => $ category ->name ,
243+ 'category_type ' => ucwords ($ category ->category_type ),
244+ 'count ' => ($ category ->category_type =='asset ' ) ? link_to ('/admin/settings/categories/ ' .$ category ->id .'/view ' , $ category ->assetscount ()) : $ category ->accessoriescount (),
245+ 'acceptance ' => ($ category ->require_acceptance =='1 ' ) ? '<i class="fa fa-check"></i> ' : '' ,
246+ //EULA is still not working correctly
247+ 'eula ' => ($ category ->getEula ()) ? '<i class="fa fa-check"></i> ' : '' ,
248+ 'actions ' => $ actions
249+ );
250+ }
251+
252+ $ data = array ('total ' => $ catCount , 'rows ' => $ rows );
253+
254+ return $ data ;
245255 }
246256
247257 public function getDataView ($ categoryID ) {
0 commit comments