Completed
Push — master ( fa5230...195b94 )
by Mohamed
16:12 queued 06:12
created

RelationTrait::generalActivities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
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;
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\Issue model.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @method Relations\HasMany       hasMany($related, $foreignKey = null, $localKey = null)
23
 * @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
24
 * @method Relations\BelongsTo     belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
25
 */
26
trait RelationTrait
27
{
28
    /**
29
     * An issue has one user assigned to (inverse relationship of User::issues).
30
     *
31
     * @return Relations\BelongsTo
32
     */
33
    public function assigned()
34 13
    {
35
        return $this->belongsTo('Tinyissue\Model\User', 'assigned_to');
36 13
    }
37
38
    /**
39
     * An issue has one user updated by (inverse relationship of User::issuesUpdatedBy).
40
     *
41
     * @return Relations\BelongsTo
42
     */
43
    public function updatedBy()
44 6
    {
45
        return $this->belongsTo('Tinyissue\Model\User', 'updated_by');
46 6
    }
47
48
    /**
49
     * An issue has one user closed it (inverse relationship of User::issuesClosedBy).
50
     *
51
     * @return Relations\BelongsTo
52
     */
53
    public function closer()
54
    {
55
        return $this->belongsTo('Tinyissue\Model\User', 'closed_by');
56
    }
57
58
    /**
59
     * An issue has one user created it (inverse relationship of User::issuesCreatedBy).
60
     *
61
     * @return Relations\BelongsTo
62
     */
63
    public function user()
64 21
    {
65
        return $this->belongsTo('Tinyissue\Model\User', 'created_by');
66 21
    }
67
68
    /**
69
     * Issue belong to a project.
70
     *
71
     * @return Relations\BelongsTo
72
     */
73
    public function project()
74 2
    {
75
        return $this->belongsTo('Tinyissue\Model\Project');
76 2
    }
77
78
    /**
79
     * Issue can have many attachments.
80
     *
81
     * @return Relations\HasMany
82
     */
83
    public function attachments()
84 18
    {
85
        return $this
86
            ->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'issue_id')
87 18
            ->where('comment_id', '=', 0)
88 18
            ->orWhere('comment_id', '=', null);
89 18
    }
90 18
91 18
    /**
92
     * Issue have many users activities.
93
     *
94
     * @return Relations\HasMany
95
     */
96
    public function activities()
97
    {
98
        return $this
99 28
            ->hasMany('Tinyissue\Model\User\Activity', 'item_id')
100
            ->orderBy('created_at', 'ASC');
101
    }
102 28
103 28
    /**
104
     * Issue have many tags.
105
     *
106
     * @return Relations\BelongsToMany
107
     */
108
    public function tags()
109
    {
110
        return $this->belongsToMany('Tinyissue\Model\Tag', 'projects_issues_tags', 'issue_id', 'tag_id');
111 1
    }
112
113
    /**
114 1
     * Issue have many comments.
115 1
     *
116 1
     * @return Relations\HasMany
117
     */
118
    public function comments()
119
    {
120
        return $this
121
            ->hasMany('Tinyissue\Model\Project\Issue\Comment', 'issue_id')
122
            ->orderBy('created_at', 'ASC');
123
    }
124
}
125