2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Watson\Validating\ValidatingTrait;
|
|
|
|
|
|
|
|
class Statuslabel extends Model
|
|
|
|
{
|
|
|
|
use SoftDeletes;
|
|
|
|
use ValidatingTrait;
|
|
|
|
|
|
|
|
protected $injectUniqueIdentifier = true;
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
protected $table = 'status_labels';
|
|
|
|
|
|
|
|
|
|
|
|
protected $rules = array(
|
2016-06-28 14:52:11 -07:00
|
|
|
'name' => 'required|string|unique:status_labels,name,NULL,deleted_at',
|
|
|
|
'notes' => 'string',
|
|
|
|
'deployable' => 'required',
|
|
|
|
'pending' => 'required',
|
|
|
|
'archived' => 'required',
|
2016-03-25 01:18:05 -07:00
|
|
|
);
|
|
|
|
|
2016-07-19 15:50:21 -07:00
|
|
|
protected $fillable = ['name', 'deployable', 'pending', 'archived'];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-05-24 16:08:18 -07:00
|
|
|
/**
|
|
|
|
* Show count of assets with status label
|
|
|
|
*
|
|
|
|
* @todo Remove this. It's dumb.
|
2016-06-13 10:54:28 -07:00
|
|
|
* @return \Illuminate\Support\Collection
|
2016-05-24 16:08:18 -07:00
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function has_assets()
|
|
|
|
{
|
|
|
|
return $this->hasMany('\App\Models\Asset', 'status_id')->count();
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:08:18 -07:00
|
|
|
/**
|
|
|
|
* Get assets with associated status label
|
|
|
|
*
|
2016-06-13 10:54:28 -07:00
|
|
|
* @return \Illuminate\Support\Collection
|
2016-05-24 16:08:18 -07:00
|
|
|
*/
|
2016-05-24 16:06:22 -07:00
|
|
|
public function assets()
|
|
|
|
{
|
|
|
|
return $this->hasMany('\App\Models\Asset', 'status_id');
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getStatuslabelType()
|
|
|
|
{
|
|
|
|
|
2016-06-28 14:52:11 -07:00
|
|
|
if (($this->pending == '1') && ($this->archived == '0') && ($this->deployable == '0')) {
|
2016-03-25 01:18:05 -07:00
|
|
|
return 'pending';
|
2016-06-28 14:52:11 -07:00
|
|
|
} elseif (($this->pending == '0') && ($this->archived == '1') && ($this->deployable == '0')) {
|
2016-03-25 01:18:05 -07:00
|
|
|
return 'archived';
|
2016-06-28 14:52:11 -07:00
|
|
|
} elseif (($this->pending == '0') && ($this->archived == '0') && ($this->deployable == '0')) {
|
2016-06-28 12:40:20 -07:00
|
|
|
return 'undeployable';
|
2016-06-28 14:52:11 -07:00
|
|
|
} else {
|
|
|
|
return 'deployable';
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getStatuslabelTypesForDB($type)
|
|
|
|
{
|
|
|
|
if ($type == 'pending') {
|
|
|
|
$statustype['pending'] = 1;
|
|
|
|
$statustype['deployable'] = 0;
|
|
|
|
$statustype['archived'] = 0;
|
|
|
|
|
|
|
|
} elseif ($type == 'deployable') {
|
|
|
|
$statustype['pending'] = 0;
|
|
|
|
$statustype['deployable'] = 1;
|
|
|
|
$statustype['archived'] = 0;
|
|
|
|
|
|
|
|
} elseif ($type == 'archived') {
|
|
|
|
$statustype['pending'] = 0;
|
|
|
|
$statustype['deployable'] = 0;
|
|
|
|
$statustype['archived'] = 1;
|
2016-06-28 14:52:11 -07:00
|
|
|
|
2016-06-28 12:19:05 -07:00
|
|
|
} else {
|
2016-03-25 01:18:05 -07:00
|
|
|
$statustype['pending'] = 0;
|
|
|
|
$statustype['deployable'] = 0;
|
|
|
|
$statustype['archived'] = 0;
|
2016-06-28 14:52:11 -07:00
|
|
|
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
return $statustype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query builder scope to search on text
|
|
|
|
*
|
|
|
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
|
|
|
* @param text $search Search term
|
|
|
|
*
|
|
|
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
|
|
|
*/
|
|
|
|
public function scopeTextSearch($query, $search)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $query->where(function ($query) use ($search) {
|
|
|
|
|
|
|
|
$query->where('name', 'LIKE', '%'.$search.'%');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|