mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 19:59:18 -08:00
Added location method, fixed assetLoc
This commit is contained in:
parent
c70db75de9
commit
ce5ccc31f0
|
@ -255,23 +255,33 @@ class Asset extends Depreciable
|
|||
**/
|
||||
public function assetLoc()
|
||||
{
|
||||
static $iterations=0;
|
||||
static $first_asset;
|
||||
if (!empty($this->assignedType())) {
|
||||
// dd($this->assignedType());
|
||||
if ($this->assignedType() == self::ASSET) {
|
||||
return $this->assignedto->assetloc(); // Recurse until we have a final location
|
||||
$iterations++;
|
||||
if(!$first_asset) {
|
||||
$first_asset=$this;
|
||||
}
|
||||
if($iterations>10) {
|
||||
throw new \Exception("Asset assignment Loop for Asset ID: ".$first_asset->id);
|
||||
}
|
||||
$assigned_to=Asset::find($this->assigned_to); //have to do this this way because otherwise it errors
|
||||
return $assigned_to->assetLoc(); // Recurse until we have a final location
|
||||
}
|
||||
if ($this->assignedType() == self::LOCATION) {
|
||||
return $this->assignedTo();
|
||||
return $this->assignedTo;
|
||||
}
|
||||
if ($this->assignedType() == self::USER) {
|
||||
if (!$this->assignedTo) {
|
||||
return $this->defaultLoc();
|
||||
if (!$this->assignedTo->userLoc) {
|
||||
//this makes no sense
|
||||
return $this->defaultLoc;
|
||||
}
|
||||
return $this->assignedTo->userLoc();
|
||||
return $this->assignedTo->userLoc;
|
||||
}
|
||||
|
||||
}
|
||||
return $this->defaultLoc();
|
||||
return $this->defaultLoc;
|
||||
}
|
||||
|
||||
public function assignedType()
|
||||
|
@ -407,6 +417,12 @@ class Asset extends Depreciable
|
|||
}
|
||||
|
||||
|
||||
public function location()
|
||||
{
|
||||
return $this->belongsTo('\App\Models\Location', 'location_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get auto-increment
|
||||
|
|
Loading…
Reference in a new issue