snipe-it/app/Models/LicenseSeat.php

105 lines
2.5 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace App\Models;
use App\Models\Traits\Acceptable;
use App\Notifications\CheckinLicenseNotification;
use App\Notifications\CheckoutLicenseNotification;
use App\Presenters\Presentable;
2016-03-25 01:18:05 -07:00
use Illuminate\Database\Eloquent\SoftDeletes;
class LicenseSeat extends SnipeModel implements ICompanyableChild
2016-03-25 01:18:05 -07:00
{
use CompanyableChildTrait;
use SoftDeletes;
use Loggable;
2016-03-25 01:18:05 -07:00
protected $presenter = 'App\Presenters\LicenseSeatPresenter';
use Presentable;
2016-03-25 01:18:05 -07:00
protected $dates = ['deleted_at'];
protected $guarded = 'id';
protected $table = 'license_seats';
use Acceptable;
2016-03-25 01:18:05 -07:00
public function getCompanyableParents()
{
return ['asset', 'license'];
}
/**
* Determine whether the user should be required to accept the license
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v4.0]
* @return boolean
*/
public function requireAcceptance()
{
return $this->license->category->require_acceptance;
}
public function getEula() {
return $this->license->getEula();
}
/**
* Establishes the seat -> license relationship
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v1.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function license()
{
return $this->belongsTo('\App\Models\License', 'license_id');
}
/**
* Establishes the seat -> assignee relationship
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v1.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function user()
{
return $this->belongsTo('\App\Models\User', 'assigned_to')->withTrashed();
}
/**
* Establishes the seat -> asset relationship
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v4.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function asset()
{
return $this->belongsTo('\App\Models\Asset', 'asset_id')->withTrashed();
}
2018-01-10 20:34:44 -08:00
/**
* Determines the assigned seat's location based on user
* or asset its assigned to
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v4.0]
* @return string
*/
2018-01-10 20:34:44 -08:00
public function location()
{
if (($this->user) && ($this->user->location)) {
return $this->user->location;
} elseif (($this->asset) && ($this->asset->location)) {
return $this->asset->location;
}
return false;
}
2016-03-25 01:18:05 -07:00
}