2014-11-16 23:01:12 +00:00
|
|
|
<?php
|
|
|
|
|
2014-11-27 16:05:00 +00:00
|
|
|
use Watson\Validating\ValidatingTrait;
|
|
|
|
|
|
|
|
class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
2014-11-27 22:08:28 +00:00
|
|
|
|
2014-11-27 16:05:00 +00:00
|
|
|
use ValidatingTrait;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
|
|
|
|
|
|
|
protected $rules = [
|
2014-12-01 12:21:44 +00:00
|
|
|
'user_id' => 'required|integer',
|
2014-12-13 12:22:06 +00:00
|
|
|
'component_id' => 'integer',
|
2014-12-01 12:21:44 +00:00
|
|
|
'name' => 'required',
|
|
|
|
'status' => 'required|integer',
|
|
|
|
'message' => 'required',
|
2014-11-27 16:05:00 +00:00
|
|
|
];
|
|
|
|
|
2014-12-13 12:22:06 +00:00
|
|
|
protected $fillable = ['user_id', 'component_id', 'name', 'status', 'message'];
|
2014-11-27 16:05:00 +00:00
|
|
|
|
|
|
|
protected $appends = ['humanStatus'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An incident belongs to a component.
|
|
|
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2014-12-01 12:21:44 +00:00
|
|
|
public function component() {
|
|
|
|
return $this->belongsTo('Component', 'component_id', 'id');
|
2014-11-27 16:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a human readable version of the status.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHumanStatusAttribute() {
|
2014-12-01 16:37:37 +00:00
|
|
|
$statuses = Lang::get('cachet.incident.status');
|
2014-11-27 16:05:00 +00:00
|
|
|
return $statuses[$this->status];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the icon to use for each status.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIconAttribute() {
|
|
|
|
switch ($this->status) {
|
2014-12-13 12:32:01 +00:00
|
|
|
case 1: return 'fa fa-flag';
|
|
|
|
case 2: return 'fa fa-warning';
|
|
|
|
case 3: return 'fa fa-eye';
|
|
|
|
case 4: return 'fa fa-check';
|
2014-11-27 16:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the transformer instance.
|
|
|
|
*
|
|
|
|
* @return IncidentTransformer
|
|
|
|
*/
|
|
|
|
public function getTransformer() {
|
2014-11-27 19:18:01 +00:00
|
|
|
return new CachetHQ\Cachet\Transformers\IncidentTransformer();
|
2014-11-27 16:05:00 +00:00
|
|
|
}
|
2014-11-27 22:08:28 +00:00
|
|
|
}
|