Exemplo n.º 1
0
 /**
  * Get Sites current user is authorised to manage + Process datatables ajax request.
  */
 public function getSites(Request $request)
 {
     $site_list = Auth::user()->company->reportsToCompany()->siteList($request->get('status'))->pluck('id')->toArray();
     $site_records = Site::select(['id', 'code', 'name', 'slug', DB::raw('CONCAT(address, ", ", suburb, " ", state, " ", postcode) AS fulladdress'), 'status'])->whereIn('id', $site_list);
     //$site_records = Auth::user()->company->reportsToCompany()->siteList($request->get('status'));
     $dt = Datatables::of($site_records)->editColumn('id', function ($site) {
         $s = Site::find($site->id);
         if (Auth::user()->can('view.site|view.p.site') && $s->client->clientOfCompany->id == Auth::user()->company->id) {
             return '<div class="text-center"><a href="/site/' . $s->slug . '"><i class="fa fa-search"></i></a></div>';
         } else {
             return '';
         }
     })->addColumn('supervisor', function ($site) {
         //$s = Site::find($site->id);
         return $site->supervisorsSeparatedByComma();
     })->addColumn('action', function ($site) {
         $s = Site::find($site->id);
         if (Auth::user()->can('edit.site|edit.p.site') && $s->client->clientOfCompany->id == Auth::user()->company->id) {
             return '<a href="/site/' . $s->slug . '/settings" class="btn blue btn-xs btn-outline sbold uppercase margin-bottom"><i class="fa fa-pencil"></i> Edit</a>';
         } else {
             return '';
         }
     })->filterColumn('fulladdress', 'whereRaw', "CONCAT(address,', ',suburb) like ?", ["%\$1%"])->make(true);
     return $dt;
 }
Exemplo n.º 2
0
 /**
  * Get list of Sites User is authorised to view
  */
 public function getSites(Request $request)
 {
     if (Auth::user()->company->subscription) {
         $allowedSites = Auth::user()->company->siteList('1')->pluck('id')->toArray();
     } else {
         $allowedSites = Auth::user()->company->sitePlannerList('1')->pluck('id')->toArray();
     }
     //$allowedSites = ['115'];
     $sites = Site::select(['id', 'name'])->where('status', '=', '1')->whereIn('id', $allowedSites)->orderBy('name')->get();
     $site_details = [];
     foreach ($sites as $site) {
         $array = [];
         $array['id'] = $site->id;
         $array['value'] = $site->id;
         $array['name'] = $site->name;
         $array['text'] = $site->name;
         $site_record = Site::find($site->id);
         $array['code'] = $site_record->code;
         $array['supervisors'] = $site_record->supervisorSelect();
         $site_details[] = $array;
     }
     return $site_details;
 }