1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* GitScrum v0.1. |
4
|
|
|
* |
5
|
|
|
* @author Renato Marinho <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace GitScrum\Models; |
10
|
|
|
|
11
|
|
|
use Illuminate\Database\Eloquent\Model; |
12
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
13
|
|
|
use GitScrum\Scopes\GlobalScope; |
14
|
|
|
use Carbon\Carbon; |
15
|
|
|
|
16
|
|
|
class Status extends Model |
17
|
|
|
{ |
18
|
|
|
use SoftDeletes; |
19
|
|
|
use GlobalScope; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The database table used by the model. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $table = 'statuses'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Attributes that should be mass-assignable. |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $fillable = ['statusesable_type', 'statusesable_id', 'config_status_id', 'user_id', 'deleted_at']; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The attributes excluded from the model's JSON form. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $hidden = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The attributes that should be casted to native types. |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $casts = []; |
48
|
|
|
|
49
|
|
|
protected $dates = ['deleted_at']; |
50
|
|
|
|
51
|
|
|
protected static function boot() |
52
|
|
|
{ |
53
|
|
|
parent::boot(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setUpdatedAtAttribute($value) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function user() |
61
|
|
|
{ |
62
|
|
|
return $this->belongsTo(\GitScrum\Models\User::class, 'user_id', 'id'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function configStatus() |
66
|
|
|
{ |
67
|
|
|
return $this->belongsTo(\GitScrum\Models\ConfigStatus::class, 'config_status_id', 'id'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function available() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
return $this->hasMany(\GitScrum\Models\ConfigStatus::class, 'type', 'statusesable_type') |
73
|
|
|
->orderby('position', 'ASC'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getDateforhumansAttribute() |
77
|
|
|
{ |
78
|
|
|
return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['created_at'])->diffForHumans(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function track($alias, $model, $id = null) |
82
|
|
|
{ |
83
|
|
|
if (!isset($model->config_status_id)) { |
84
|
|
|
if (is_null($id)) { |
85
|
|
|
$status = ConfigStatus::type($alias)->default(); |
86
|
|
|
} else { |
87
|
|
|
$status = ConfigStatus::find($id); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$model->config_status_id = $status->first()->id; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->create([ |
94
|
|
|
'statusesable_type' => $alias, |
95
|
|
|
'statusesable_id' => $model->id, |
96
|
|
|
'config_status_id' => $model->config_status_id, |
97
|
|
|
'user_id' => $model->user_id, ]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function statusesable() |
101
|
|
|
{ |
102
|
|
|
return $this->morphTo(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.