1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
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
|
|
|
namespace Tinyissue\Model\Project\Issue; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Model as BaseModel; |
15
|
|
|
use Tinyissue\Model\Permission; |
16
|
|
|
use Tinyissue\Model\Traits\Project\Issue\Comment\CrudTrait; |
17
|
|
|
use Tinyissue\Model\Traits\Project\Issue\Comment\QueueTrait; |
18
|
|
|
use Tinyissue\Model\Traits\Project\Issue\Comment\RelationTrait; |
19
|
|
|
use Tinyissue\Model\User; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Comment is model class for project issue comments. |
23
|
|
|
* |
24
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
25
|
|
|
* |
26
|
|
|
* @property int $id |
27
|
|
|
* @property int $issue_id |
28
|
|
|
* @property int $project_id |
29
|
|
|
* @property string $comment |
30
|
|
|
* @property int $created_by |
31
|
|
|
*/ |
32
|
|
|
class Comment extends BaseModel |
33
|
|
|
{ |
34
|
|
|
use CrudTrait, |
35
|
|
|
RelationTrait, |
36
|
|
|
QueueTrait; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Timestamp enabled. |
40
|
|
|
* |
41
|
|
|
* @var bool |
42
|
|
|
*/ |
43
|
|
|
public $timestamps = true; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Name of database table. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $table = 'projects_issues_comments'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* List of allowed columns to be used in $this->fill(). |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $fillable = [ |
58
|
|
|
'created_by', |
59
|
|
|
'project_id', |
60
|
|
|
'issue_id', |
61
|
|
|
'comment', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Whether a user can view the issue. |
66
|
|
|
* |
67
|
|
|
* @param User $user |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
1 |
|
public function canView(User $user) |
72
|
|
|
{ |
73
|
1 |
|
return $this->issue->canView($user); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Whether a user can edit the comment. |
78
|
|
|
* |
79
|
|
|
* @param User $user |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
8 |
|
public function canEdit(User $user) |
84
|
|
|
{ |
85
|
8 |
|
return $user->id === $this->created_by || ($this->canView($user) && $user->permission(Permission::PERM_ISSUE_MODIFY)); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|