|
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\Note; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations; |
|
15
|
|
|
use Tinyissue\Model; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* RelationTrait is trait class containing the relationship methods for the Project\Note model. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
21
|
|
|
* |
|
22
|
|
|
* @property static $this |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
trait RelationTrait |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Note created by a user. |
|
28
|
|
|
* |
|
29
|
|
|
* @return Relations\BelongsTo |
|
30
|
|
|
*/ |
|
31
|
6 |
|
public function createdBy() |
|
32
|
|
|
{ |
|
33
|
6 |
|
return $this->belongsTo('Tinyissue\Model\User', 'created_by'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Note belong to a project. |
|
38
|
|
|
* |
|
39
|
|
|
* @return Relations\BelongsTo |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function project() |
|
42
|
|
|
{ |
|
43
|
1 |
|
return $this->belongsTo('Tinyissue\Model\Project', 'project_id'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Note has a user activity record. |
|
48
|
|
|
* |
|
49
|
|
|
* @return Relations\HasOne |
|
50
|
|
|
*/ |
|
51
|
7 |
|
public function activity() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this |
|
54
|
7 |
|
->hasOne('Tinyissue\Model\User\Activity', 'action_id') |
|
55
|
7 |
|
->where('type_id', '=', Model\Activity::TYPE_NOTE); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Note can have many messages queue. |
|
60
|
|
|
* |
|
61
|
|
|
* @return Relations\HasMany |
|
62
|
|
|
*/ |
|
63
|
|
|
public function messagesQueue() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->morphMany('Tinyissue\Model\Message\Queue', 'model'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); |
|
69
|
|
|
abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
|
70
|
|
|
abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null); |
|
71
|
|
|
} |
|
72
|
|
|
|
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.