RelationTrait::comments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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\User;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model\Project;
16
17
/**
18
 * RelationTrait is trait class containing the relationship methods for the User model.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @property static $this
23
 */
24
trait RelationTrait
25
{
26
    /**
27
     * A user has one role (inverse relationship of Role::users).
28
     *
29
     * @return Relations\BelongsTo
30
     */
31 47
    public function role()
32
    {
33 47
        return $this->belongsTo('Tinyissue\Model\Role', 'role_id');
34
    }
35
36
    /**
37
     * User has many comments (One-many relationship of Comment::user).
38
     *
39
     * @return Relations\HasMany
40
     */
41
    public function comments()
42
    {
43
        return $this->hasMany('Tinyissue\Model\Project\Issue\Comment', 'created_by', 'id');
44
    }
45
46
    /**
47
     * Returns issues created by the user.
48
     *
49
     * @return Relations\HasMany
50
     */
51 2
    public function issuesCreatedBy()
52
    {
53 2
        return $this->hasMany('Tinyissue\Model\Project\Issue', 'created_by');
54
    }
55
56
    /**
57
     * Returns issues closed by the user.
58
     *
59
     * @return Relations\HasMany
60
     */
61
    public function issuesClosedBy()
62
    {
63
        return $this->hasMany('Tinyissue\Model\Project\Issue', 'closed_by');
64
    }
65
66
    /**
67
     * Returns issues updated by the user.
68
     *
69
     * @return Relations\HasMany
70
     */
71
    public function issuesUpdatedBy()
72
    {
73
        return $this->hasMany('Tinyissue\Model\Project\Issue', 'updated_by');
74
    }
75
76
    /**
77
     * User has many attachments (One-many relationship of Attachment::user).
78
     *
79
     * @return Relations\HasMany
80
     */
81
    public function attachments()
82
    {
83
        return $this->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'uploaded_by');
84
    }
85
86
    /**
87
     * Returns all projects the user can access.
88
     *
89
     * @param int $status
90
     *
91
     * @return Relations\HasMany
92
     */
93 32
    public function projects($status = Project::STATUS_OPEN)
94
    {
95
        return $this
96 32
            ->belongsToMany('Tinyissue\Model\Project', 'projects_users')
97 32
            ->where('status', '=', $status)
98 32
            ->orderBy('name');
99
    }
100
101
    /**
102
     * User has many issues assigned to (One-many relationship of Issue::assigned).
103
     *
104
     * @return Relations\HasMany
105
     */
106 20
    public function issues()
107
    {
108 20
        return $this->hasMany('Tinyissue\Model\Project\Issue', 'assigned_to');
109
    }
110
111
    /**
112
     * Returns all permission for the user.
113
     *
114
     * @return Relations\HasMany
115
     */
116 65
    public function permissions()
117
    {
118 65
        return $this->hasMany('\Tinyissue\Model\Role\Permission', 'role_id', 'role_id');
119
    }
120
121
    /**
122
     * Define an inverse one-to-one or many relationship.
123
     *
124
     * @param string $related
125
     * @param string $foreignKey
126
     * @param string $otherKey
127
     * @param string $relation
128
     *
129
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
130
     */
131
    abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null);
132
133
    /**
134
     * Define a one-to-many relationship.
135
     *
136
     * @param string $related
137
     * @param string $foreignKey
138
     * @param string $localKey
139
     *
140
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
141
     */
142
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
143
144
    /**
145
     * Define a many-to-many relationship.
146
     *
147
     * @param string $related
148
     * @param string $table
149
     * @param string $foreignKey
150
     * @param string $otherKey
151
     * @param string $relation
152
     *
153
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
154
     */
155
    abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null);
156
}
157