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\Traits\Project\Issue\Comment; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* RelationTrait is trait class containing the relationship methods for the Project\Issue\Comment model. |
18
|
|
|
* |
19
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
20
|
|
|
* |
21
|
|
|
* @property static $this |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
trait RelationTrait |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* A comment has one user (inverse relationship of User::comments). |
27
|
|
|
* |
28
|
|
|
* @return Relations\BelongsTo |
29
|
|
|
*/ |
30
|
|
|
public function user() |
31
|
|
|
{ |
32
|
|
|
return $this->belongsTo('\Tinyissue\Model\User', 'created_by'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* A comment has belongs to an issue. |
37
|
|
|
* |
38
|
|
|
* @return Relations\BelongsTo |
39
|
|
|
*/ |
40
|
5 |
|
public function issue() |
41
|
|
|
{ |
42
|
5 |
|
return $this->belongsTo('\Tinyissue\Model\Project\Issue', 'issue_id'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Comment can have many attachments. |
47
|
|
|
* |
48
|
|
|
* @return Relations\HasMany |
49
|
|
|
*/ |
50
|
9 |
|
public function attachments() |
51
|
|
|
{ |
52
|
9 |
|
return $this->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'comment_id'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Comment can have one activity. |
57
|
|
|
* |
58
|
|
|
* @return Relations\HasOne |
59
|
|
|
*/ |
60
|
10 |
|
public function activity() |
61
|
|
|
{ |
62
|
10 |
|
return $this->hasOne('Tinyissue\Model\User\Activity', 'action_id'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Comment can have many messages queue. |
67
|
|
|
* |
68
|
|
|
* @return Relations\HasMany |
69
|
|
|
*/ |
70
|
|
|
public function messagesQueue() |
71
|
|
|
{ |
72
|
|
|
return $this->morphMany('Tinyissue\Model\Message\Queue', 'model'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); |
76
|
|
|
abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
77
|
|
|
abstract public function hasMany($related, $foreignKey = null, $localKey = null); |
78
|
|
|
abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null); |
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.