RelationTrait::assignTo()   A
last analyzed

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