90 lines
2.3 KiB
PHP
90 lines
2.3 KiB
PHP
<?php
|
|
|
|
use CachetHQ\Cachet\Transformers\ComponentTransformer;
|
|
use Dingo\Api\Transformer\TransformableInterface;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
|
use Illuminate\Support\Facades\Lang;
|
|
use Watson\Validating\ValidatingTrait;
|
|
|
|
class Component extends Model implements TransformableInterface
|
|
{
|
|
use SoftDeletingTrait, ValidatingTrait;
|
|
|
|
/**
|
|
* The validation rules.
|
|
*
|
|
* @var string[]
|
|
*/
|
|
protected $rules = [
|
|
'user_id' => 'integer|required',
|
|
'name' => 'required',
|
|
'status' => 'integer',
|
|
'link' => 'url',
|
|
];
|
|
|
|
/**
|
|
* The fillable properties.
|
|
*
|
|
* @var string[]
|
|
*/
|
|
protected $fillable = ['name', 'description', 'status', 'user_id', 'tags', 'link', 'order'];
|
|
|
|
/**
|
|
* Lookup all of the incidents reported on the component.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function incidents()
|
|
{
|
|
return $this->hasMany('Incident', 'component_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* Finds all components by status.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param int $status
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeStatus(Builder $query, $status)
|
|
{
|
|
return $query->where('status', $status);
|
|
}
|
|
|
|
/**
|
|
* Finds all components which don't have the given status.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param int $status
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeNotStatus(Builder $query, $status)
|
|
{
|
|
return $query->where('status', '<>', $status);
|
|
}
|
|
|
|
/**
|
|
* Looks up the human readable version of the status.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getHumanStatusAttribute()
|
|
{
|
|
return Lang::get('cachet.component.status.'.$this->status);
|
|
}
|
|
|
|
/**
|
|
* Get the transformer instance.
|
|
*
|
|
* @return \CachetHQ\Cachet\Transformers\ComponentTransformer
|
|
*/
|
|
public function getTransformer()
|
|
{
|
|
return new ComponentTransformer();
|
|
}
|
|
}
|