Completed
Push — develop ( e210c1...b7d5d2 )
by Mohamed
07:16 queued 59s
created

RelationTrait::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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\User\Activity;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model\Project;
16
17
/**
18
 * RelationTrait is trait class containing the relationship method for the User\Activity model.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @method Relations\BelongsTo     belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
23
 */
24
trait RelationTrait
25
{
26
    /**
27
     * Returns the project issue this activity is belongs to by the item_id, which can hold the issue id.
28
     *
29
     * @return Relations\BelongsTo
30
     */
31 2
    public function issue()
32
    {
33 2
        return $this->belongsTo('Tinyissue\Model\Project\Issue', 'item_id');
34
    }
35
36
    /**
37
     * Returns the user this activity is belongs to.
38
     *
39
     * @return Relations\BelongsTo
40
     */
41 7
    public function user()
42
    {
43 7
        return $this->belongsTo('\Tinyissue\Model\User', 'user_id');
44
    }
45
46
    /**
47
     * Returns the user that was assigned to the issue. Only for reassign activity.
48
     *
49
     * @return Relations\BelongsTo
50
     */
51 7
    public function assignTo()
52
    {
53 7
        return $this->belongsTo('\Tinyissue\Model\User', 'action_id');
54
    }
55
56
    /**
57
     * User activity has one activity type.
58
     *
59
     * @return Relations\BelongsTo
60
     */
61 7
    public function activity()
62
    {
63 7
        return $this->belongsTo('Tinyissue\Model\Activity', 'type_id');
64
    }
65
66
    /**
67
     * Returns the comment this activity belongs to if any.
68
     *
69
     * @return Relations\BelongsTo
70
     */
71 7
    public function comment()
72
    {
73 7
        return $this->belongsTo('Tinyissue\Model\Project\Issue\Comment', 'action_id');
74
    }
75
76
    /**
77
     * Returns the project his activity belongs to.
78
     *
79
     * @return Relations\BelongsTo
80
     */
81
    public function project()
82
    {
83
        return $this->belongsTo('Tinyissue\Model\Project', 'parent_id');
84
    }
85
86
    /**
87
     * Returns the note this activity belongs to if any.
88
     *
89
     * @return Relations\BelongsTo
90
     */
91 2
    public function note()
92
    {
93 2
        return $this->belongsTo('\Tinyissue\Model\Project\Note', 'action_id');
94
    }
95
}
96