2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
|
2018-07-28 04:09:21 -07:00
|
|
|
use App\Models\Traits\Acceptable;
|
2018-03-25 13:46:57 -07:00
|
|
|
use App\Notifications\CheckinLicenseNotification;
|
2018-07-28 03:43:09 -07:00
|
|
|
use App\Notifications\CheckoutLicenseNotification;
|
|
|
|
use App\Presenters\Presentable;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
2018-07-28 03:43:09 -07:00
|
|
|
class LicenseSeat extends SnipeModel implements ICompanyableChild
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
use CompanyableChildTrait;
|
|
|
|
use SoftDeletes;
|
2016-09-06 19:39:42 -07:00
|
|
|
use Loggable;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2018-07-28 03:43:09 -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';
|
|
|
|
|
2021-03-29 19:41:26 -07:00
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'assigned_to',
|
|
|
|
'asset_id'
|
|
|
|
];
|
|
|
|
|
2018-07-28 04:09:21 -07:00
|
|
|
use Acceptable;
|
2018-03-25 13:46:57 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getCompanyableParents()
|
|
|
|
{
|
|
|
|
return ['asset', 'license'];
|
|
|
|
}
|
|
|
|
|
2018-10-11 14:08:09 -07:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2018-07-28 03:43:09 -07:00
|
|
|
public function getEula() {
|
|
|
|
return $this->license->getEula();
|
|
|
|
}
|
|
|
|
|
2018-08-01 00:06:41 -07:00
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
|
|
|
|
2018-08-01 00:06:41 -07:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2018-08-01 00:06:41 -07:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2018-08-01 00:06:41 -07: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;
|
|
|
|
|
|
|
|
}
|
2019-11-21 22:03:56 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to order on department
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $order Order
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeOrderDepartments($query, $order)
|
|
|
|
{
|
|
|
|
return $query->leftJoin('users as license_seat_users', 'license_seats.assigned_to', '=', 'license_seat_users.id')
|
|
|
|
->leftJoin('departments as license_user_dept', 'license_user_dept.id', '=', 'license_seat_users.department_id')
|
|
|
|
->orderBy('license_user_dept.name', $order);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|