1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
# == Schema Information |
13
|
|
|
# |
14
|
|
|
# Table name: issues |
15
|
|
|
# |
16
|
|
|
# id :integer not null, primary key |
17
|
|
|
# title :string(255) |
18
|
|
|
# assignee_id :integer |
19
|
|
|
# author_id :integer |
20
|
|
|
# project_id :integer |
21
|
|
|
# created_at :timestamp |
22
|
|
|
# updated_at :timestamp |
23
|
|
|
# position :integer default(0) |
24
|
|
|
# branch_name :string(255) |
25
|
|
|
# description :text |
26
|
|
|
# milestone_id :integer |
27
|
|
|
# state :string(255) |
28
|
|
|
# iid :integer |
29
|
|
|
# updated_by_id :integer |
30
|
|
|
# |
31
|
|
|
|
32
|
|
|
namespace Gitamin\Models; |
33
|
|
|
|
34
|
|
|
use AltThree\Validator\ValidatingTrait; |
35
|
|
|
use Gitamin\Presenters\IssuePresenter; |
36
|
|
|
use Illuminate\Database\Eloquent\Model; |
37
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
38
|
|
|
use McCool\LaravelAutoPresenter\HasPresenter; |
39
|
|
|
|
40
|
|
|
class Issue extends Model implements HasPresenter |
41
|
|
|
{ |
42
|
|
|
use SoftDeletes, ValidatingTrait; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The accessors to append to the model's serialized form. |
46
|
|
|
* |
47
|
|
|
* @var string[] |
48
|
|
|
*/ |
49
|
|
|
protected $appends = ['human_status']; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The attributes that should be casted to native types. |
53
|
|
|
* |
54
|
|
|
* @var string[] |
55
|
|
|
*/ |
56
|
|
|
protected $casts = [ |
57
|
|
|
'id' => 'int', |
58
|
|
|
'deleted_at' => 'date', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The fillable properties. |
63
|
|
|
* |
64
|
|
|
* @var string[] |
65
|
|
|
*/ |
66
|
|
|
protected $fillable = [ |
67
|
|
|
'author_id', |
68
|
|
|
'project_id', |
69
|
|
|
'title', |
70
|
|
|
'description', |
71
|
|
|
'created_at', |
72
|
|
|
'updated_at', |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* The validation rules. |
77
|
|
|
* |
78
|
|
|
* @var string[] |
79
|
|
|
*/ |
80
|
|
|
public $rules = [ |
81
|
|
|
'author_id' => 'int', |
82
|
|
|
'project_id' => 'int', |
83
|
|
|
'title' => 'required', |
84
|
|
|
'description' => 'required', |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Finds all visible issues. |
89
|
|
|
* |
90
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query |
91
|
|
|
* |
92
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
93
|
|
|
*/ |
94
|
|
|
public function scopeVisible($query) |
95
|
|
|
{ |
96
|
|
|
return $query->where('state', null); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* An issue belongs to a project. |
101
|
|
|
* |
102
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
103
|
|
|
*/ |
104
|
|
|
public function project() |
105
|
|
|
{ |
106
|
|
|
return $this->belongsTo(Project::class, 'project_id', 'id'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* An issue belongs to an author. |
111
|
|
|
* |
112
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
113
|
|
|
*/ |
114
|
|
|
public function author() |
115
|
|
|
{ |
116
|
|
|
return $this->belongsTo(User::class, 'author_id', 'id'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Returns all comments of the issue. |
121
|
|
|
* |
122
|
|
|
* @return \Gitamin\Models\Comment[] |
123
|
|
|
*/ |
124
|
|
|
public function comments() |
125
|
|
|
{ |
126
|
|
|
return Comment::where('target_type', '=', 'Issue')->where('target_id', '=', $this->id)->orderBy('id', 'asc')->get(); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Returns a human readable version of the status. |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getHumanStatusAttribute() |
135
|
|
|
{ |
136
|
|
|
$statuses = trans('gitamin.issues.status'); |
137
|
|
|
|
138
|
|
|
return $statuses[rand(0, 2)]; |
139
|
|
|
//return $statuses[$this->state]; |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getUrlAttribute() |
143
|
|
|
{ |
144
|
|
|
return route('projects.issue_show', ['owner' => $this->project->owner_path, 'project' => $this->project->path, 'issue' => $this->id]); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get the presenter class. |
149
|
|
|
* |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getPresenterClass() |
153
|
|
|
{ |
154
|
|
|
return IssuePresenter::class; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.