Inheritance diagram for App\Models\Location:

Public Member Functions

 users ()
 
 assets ()
 
 assignedassets ()
 
 parent ()
 
 childLocations ()
 
 scopeTextsearch ($query, $search)
 Query builder scope to search on text. More...
 
 scopeOrderParent ($query, $order)
 Query builder scope to order on parent. More...
 

Static Public Member Functions

static getLocationHierarchy ($locations, $parent_id=null)
 
static flattenLocationsArray ($location_options_array=null)
 

Protected Attributes

 $dates = ['deleted_at']
 
 $table = 'locations'
 
 $rules
 
 $injectUniqueIdentifier = true
 
 $fillable = ['name']
 

Detailed Description

Definition at line 10 of file Location.php.

Member Function Documentation

App\Models\Location::assets ( )

Definition at line 48 of file Location.php.

49  {
50  return $this->hasManyThrough('\App\Models\Asset', '\App\Models\Actionlog', 'location_id', 'id');
51  }
App\Models\Location::assignedassets ( )

Definition at line 53 of file Location.php.

54  {
55  return $this->hasMany('\App\Models\Asset', 'rtd_location_id');
56  }
App\Models\Location::childLocations ( )

Definition at line 63 of file Location.php.

64  {
65  return $this->hasMany('\App\Models\Location', 'parent_id');
66  }
static App\Models\Location::flattenLocationsArray (   $location_options_array = null)
static

Definition at line 96 of file Location.php.

97  {
98  $location_options = array();
99  foreach ($location_options_array as $id => $value) {
100 
101  // get the top level key value
102  $location_options[$id] = $value['name'];
103 
104  // If there is a key named children, it has child locations and we have to walk it
105  if (array_key_exists('children', $value)) {
106 
107  foreach ($value['children'] as $child_id => $child_location_array) {
108  $child_location_options = Location::flattenLocationsArray($value['children']);
109 
110  foreach ($child_location_options as $child_id => $child_name) {
111  $location_options[$child_id] = '--'.$child_name;
112  }
113  }
114 
115  }
116 
117  }
118 
119  return $location_options;
120  }
static flattenLocationsArray($location_options_array=null)
Definition: Location.php:96
static App\Models\Location::getLocationHierarchy (   $locations,
  $parent_id = null 
)
static

Definition at line 68 of file Location.php.

69  {
70 
71 
72  $op = array();
73 
74  foreach ($locations as $location) {
75 
76  if ($location['parent_id'] == $parent_id) {
77  $op[$location['id']] =
78  array(
79  'name' => $location['name'],
80  'parent_id' => $location['parent_id']
81  );
82 
83  // Using recursion
84  $children = Location::getLocationHierarchy($locations, $location['id']);
85  if ($children) {
86  $op[$location['id']]['children'] = $children;
87  }
88 
89  }
90 
91  }
92  return $op;
93  }
static getLocationHierarchy($locations, $parent_id=null)
Definition: Location.php:68
App\Models\Location::parent ( )

Definition at line 58 of file Location.php.

59  {
60  return $this->belongsTo('\App\Models\Location', 'parent_id');
61  }
App\Models\Location::scopeOrderParent (   $query,
  $order 
)

Query builder scope to order on parent.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 163 of file Location.php.

164  {
165  // Left join here, or it will only return results with parents
166  return $query->leftJoin('locations as parent_loc', 'locations.parent_id', '=', 'parent_loc.id')->orderBy('parent_loc.name', $order);
167  }
App\Models\Location::scopeTextsearch (   $query,
  $search 
)

Query builder scope to search on text.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$searchSearch term
Returns
Illuminate Modified query builder

Definition at line 130 of file Location.php.

131  {
132 
133  return $query->where('name', 'LIKE', "%$search%")
134  ->orWhere('address', 'LIKE', "%$search%")
135  ->orWhere('city', 'LIKE', "%$search%")
136  ->orWhere('state', 'LIKE', "%$search%")
137  ->orWhere('zip', 'LIKE', "%$search%")
138 
139  // This doesn't actually work - need to use a table alias maybe?
140  ->orWhere(function ($query) use ($search) {
141  $query->whereHas('parent', function ($query) use ($search) {
142  $query->where(function ($query) use ($search) {
143  $query->where('name', 'LIKE', '%'.$search.'%');
144  });
145  })
146  // Ugly, ugly code because Laravel sucks at self-joins
147  ->orWhere(function ($query) use ($search) {
148  $query->whereRaw("parent_id IN (select id from locations where name LIKE '%".$search."%') ");
149  });
150  });
151 
152  }
App\Models\Location::users ( )

Definition at line 43 of file Location.php.

44  {
45  return $this->hasMany('\App\Models\User', 'location_id');
46  }

Member Data Documentation

App\Models\Location::$dates = ['deleted_at']
protected

Definition at line 13 of file Location.php.

App\Models\Location::$fillable = ['name']
protected

Definition at line 41 of file Location.php.

App\Models\Location::$injectUniqueIdentifier = true
protected

Definition at line 32 of file Location.php.

App\Models\Location::$rules
protected
Initial value:
= array(
'name' => 'required|min:3|max:255|unique:locations,name,NULL,deleted_at',
'city' => 'min:3|max:255',
'state' => 'min:2|max:32',
'country' => 'min:2|max:2|max:2',
'address' => 'min:5|max:80',
'address2' => 'min:2|max:80',
'zip' => 'min:3|max:10',
)

Definition at line 15 of file Location.php.

App\Models\Location::$table = 'locations'
protected

Definition at line 14 of file Location.php.


The documentation for this class was generated from the following file: