Beispiel #1
0
 /**
  * A dropdown list of sites this supervisor has authority over
  *
  * @return array
  */
 public function supervisorSiteListSelect($status = '', $prompt = '')
 {
     $array = [];
     $client_list = $this->company->clients->pluck('id')->toArray();
     if ($status) {
         $collection = Site::where('status', $status)->whereIn('client_id', $client_list)->get();
     } else {
         $collection = Site::whereIn('client_id', $client_list)->get();
     }
     foreach ($collection as $site) {
         $record = Site::findOrFail($site->id);
         if ($this->is('supervisor') && $record->isUserSupervisor($this)) {
             $array[$site->id] = $record->name;
         } else {
             if ($this->is('full.access|full.read.access|whs.admin|general.admin|construction.manager')) {
                 $array[$site->id] = $record->name;
             }
         }
     }
     asort($array);
     if ($prompt == 'all') {
         return $prompt && count($array) > 1 ? $array = array('' => 'All Sites') + $array : $array;
     }
     return $prompt && count($array) > 1 ? $array = array('' => 'Select Site') + $array : $array;
 }
Beispiel #2
0
 /**
  * A list of sites this company is on a Planner for
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function sitePlannerList($status = '')
 {
     $client_list = $this->reportsToCompany()->clients->pluck('id')->toArray();
     if ($status != '') {
         $collection = Site::where('status', $status)->whereIn('client_id', $client_list)->get();
     } else {
         $collection = Site::whereIn('client_id', $client_list)->get();
     }
     // If Company has no Parent then return full collection
     // ie. a list of all sites of all their own clients
     if (!$this->parentCompany) {
         return $collection;
     }
     $logged_site_id = '';
     if (Session::has('siteID')) {
         $site_code = Session::get('siteID');
         $site = Site::where(['code' => $site_code])->first();
         $logged_site_id = $site->id;
     }
     // Otherwise return a filtered collection of sites that company is on Planner for
     $filteredCollection = [];
     foreach ($collection as $site) {
         $onPlanner = SitePlanner::where('site_id', $site->id)->where('entity_type', 'c')->where('entity_id', $this->id)->first();
         if (!$onPlanner && $site->id != $logged_site_id) {
             $filteredCollection[] = $site->id;
         }
     }
     return $collection->except($filteredCollection);
 }
 /**
  * Get List of Site Without Supervisor options for 'select' dropdown in Vuejs format
  */
 public function getSitesWithoutSuper(Request $request)
 {
     $allowedSites = Auth::user()->company->reportsToCompany()->siteList()->pluck('id')->toArray();
     $sites = Site::whereIn('id', $allowedSites)->where('status', '<>', '0')->orderBy('name')->get();
     $array = [];
     $array[] = ['value' => '', 'text' => 'Select site'];
     // Create array in specific Vuejs 'select' format.
     $tobeallocated = User::find(136);
     foreach ($sites as $site) {
         if ($site->isUserSupervisor($tobeallocated)) {
             $array[] = ['value' => $site->id, 'text' => $site->name, 'name' => $site->name];
         }
     }
     return $array;
 }