2014-11-16 23:01:12 +00:00
|
|
|
<?php
|
|
|
|
|
2014-11-25 22:01:39 +00:00
|
|
|
use Watson\Validating\ValidatingTrait;
|
2014-11-25 11:06:28 +00:00
|
|
|
|
2014-11-25 20:24:56 +00:00
|
|
|
class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface {
|
2014-11-25 11:06:28 +00:00
|
|
|
use ValidatingTrait;
|
2014-11-25 22:01:39 +00:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
2014-11-25 11:06:28 +00:00
|
|
|
|
|
|
|
protected $rules = [
|
2014-11-25 11:50:15 +00:00
|
|
|
'user_id' => 'required|integer',
|
2014-11-25 12:42:29 +00:00
|
|
|
'component' => 'required|integer',
|
|
|
|
'name' => 'required',
|
|
|
|
'status' => 'required|integer',
|
|
|
|
'message' => 'required',
|
2014-11-25 11:06:28 +00:00
|
|
|
];
|
|
|
|
|
2014-11-25 12:40:12 +00:00
|
|
|
protected $fillable = ['component', 'name', 'status', 'message'];
|
2014-11-25 11:06:28 +00:00
|
|
|
|
2014-11-25 09:08:04 +00:00
|
|
|
/**
|
|
|
|
* An incident belongs to a component.
|
2014-11-25 10:32:39 +00:00
|
|
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
2014-11-25 09:08:04 +00:00
|
|
|
*/
|
|
|
|
public function parent() {
|
|
|
|
return $this->belongsTo('Component', 'component', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a human readable version of the status.
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-11-16 23:34:46 +00:00
|
|
|
public function getHumanStatusAttribute() {
|
2014-11-25 09:18:22 +00:00
|
|
|
return Lang::get('incident.status' . $this->status);
|
2014-11-16 23:34:46 +00:00
|
|
|
}
|
2014-11-19 12:02:51 +00:00
|
|
|
|
2014-11-25 09:08:04 +00:00
|
|
|
/**
|
|
|
|
* Finds the icon to use for each status.
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-11-19 13:26:53 +00:00
|
|
|
public function getIconAttribute() {
|
|
|
|
switch ($this->status) {
|
2014-11-25 09:08:04 +00:00
|
|
|
case 1: return 'glyphicon-flag';
|
|
|
|
case 2: return 'glyphicon-warning-sign';
|
|
|
|
case 3: return 'glyphicon-eye-open';
|
|
|
|
case 4: return 'glyphicon-ok';
|
2014-11-19 12:02:51 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 10:30:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the transformer instance.
|
|
|
|
*
|
|
|
|
* @return IncidentTransformer
|
|
|
|
*/
|
|
|
|
public function getTransformer() {
|
|
|
|
return new IncidentTransformer();
|
|
|
|
}
|
2014-11-16 23:01:12 +00:00
|
|
|
}
|