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', 1); |
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 a human readable version of the status. |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getHumanStatusAttribute() |
125
|
|
|
{ |
126
|
|
|
$statuses = trans('gitamin.issues.status'); |
127
|
|
|
|
128
|
|
|
return $statuses[rand(0, 2)]; |
129
|
|
|
//return $statuses[$this->state]; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getUrlAttribute() |
133
|
|
|
{ |
134
|
|
|
return route('projects.issue_show', ['owner' => $this->project->owner_path, 'project' => $this->project->path, 'issue' => $this->id]); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get the presenter class. |
139
|
|
|
* |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function getPresenterClass() |
143
|
|
|
{ |
144
|
|
|
return IssuePresenter::class; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.