snipe-it/app/Models/LicenseSeat.php
Laravel Shift 934afa036f Adopt Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started.

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
2021-06-10 20:15:52 +00:00

128 lines
3.3 KiB
PHP
Executable file

<?php
namespace App\Models;
use App\Models\Traits\Acceptable;
use App\Notifications\CheckinLicenseNotification;
use App\Notifications\CheckoutLicenseNotification;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\SoftDeletes;
class LicenseSeat extends SnipeModel implements ICompanyableChild
{
use CompanyableChildTrait;
use SoftDeletes;
use Loggable;
protected $presenter = 'App\Presenters\LicenseSeatPresenter';
use Presentable;
protected $dates = ['deleted_at'];
protected $guarded = 'id';
protected $table = 'license_seats';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'assigned_to',
'asset_id',
];
use Acceptable;
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 bool
*/
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
*/
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
*/
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
*/
public function asset()
{
return $this->belongsTo('\App\Models\Asset', 'asset_id')->withTrashed();
}
/**
* 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
*/
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;
}
/**
* 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);
}
}