Ejemplo n.º 1
0
 /**
  * Returns the JSON response to populate the bootstrap tables on the locationa view.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see LocationsController::getIndex() method that returns JSON for location index
  * @since [v1.0]
  * @return View
  */
 public function getDatatable()
 {
     $locations = Location::select(array('locations.id', 'locations.name', 'locations.address', 'locations.address2', 'locations.city', 'locations.state', 'locations.zip', 'locations.country', 'locations.parent_id', 'locations.currency'))->with('assets');
     if (Input::has('search')) {
         $locations = $locations->TextSearch(e(Input::get('search')));
     }
     if (Input::has('offset')) {
         $offset = e(Input::get('offset'));
     } else {
         $offset = 0;
     }
     if (Input::has('limit')) {
         $limit = e(Input::get('limit'));
     } else {
         $limit = 50;
     }
     $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
     switch (Input::get('sort')) {
         case 'parent':
             $locations = $locations->OrderParent($order);
             break;
         default:
             $allowed_columns = ['id', 'name', 'address', 'city', 'state', 'country', 'currency'];
             $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
             $locations = $locations->orderBy($sort, $order);
             break;
     }
     $locationsCount = $locations->count();
     $locations = $locations->skip($offset)->take($limit)->get();
     $rows = array();
     foreach ($locations as $location) {
         $actions = '<nobr><a href="' . route('update/location', $location->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/location', $location->id) . '" data-content="' . trans('admin/locations/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($location->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
         $rows[] = array('id' => $location->id, 'name' => (string) link_to('admin/settings/locations/' . $location->id . '/view', e($location->name)), 'parent' => $location->parent ? e($location->parent->name) : '', 'assets_default' => $location->assignedassets->count(), 'assets_checkedout' => $location->assets->count(), 'address' => $location->address ? e($location->address) : '', 'city' => e($location->city), 'state' => e($location->state), 'country' => e($location->country), 'currency' => e($location->currency), 'actions' => $actions);
     }
     $data = array('total' => $locationsCount, 'rows' => $rows);
     return $data;
 }