Completed
Push — master ( 9d9a88...6b3a24 )
by Joao
02:31
created

BlogPost   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 10
c 2
b 0
f 1
lcom 2
cbo 0
dl 0
loc 120
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getUsersModel() 0 4 1
A setUsersModel() 0 4 1
A getCategoriesModel() 0 4 1
A setCategoriesModel() 0 4 1
A getAuthor() 0 4 1
A getCategory() 0 4 1
A getCreatedByAttribute() 0 9 4
1
<?php namespace jlourenco\blog\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
use Illuminate\Database\Eloquent\SoftDeletes;
5
use jlourenco\comments\Traits\Commentable;
6
use jlourenco\support\Traits\Creation;
7
use jlourenco\support\Traits\Sluggable;
8
use Sentinel;
9
10
class BlogPost extends Model
11
{
12
13
    /**
14
     * To allow user actions identity (Created_by, Updated_by, Deleted_by)
15
     */
16
    use Creation;
17
18
    use Sluggable;
19
20
    use SoftDeletes;
21
22
    use Commentable;
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected $table = 'BlogPost';
28
29
    /**
30
     * The User model name.
31
     *
32
     * @var string
33
     */
34
    protected static $usersModel = 'jlourenco\base\Models\BaseUser';
35
36
    /**
37
     * The Blog category model name.
38
     *
39
     * @var string
40
     */
41
    protected static $categoryModel = 'jlourenco\blog\Models\BlogCategory';
42
43
    protected $dates = [ 'created_at', 'deleted_at'];
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    protected $fillable = [
49
        'title',
50
        'slug',
51
        'contents',
52
        'category',
53
        'author',
54
        'likes',
55
        'shares',
56
        'views',
57
        'keywords'
58
    ];
59
60
    /**
61
     * Returns the user model.
62
     *
63
     * @return string
64
     */
65
    public static function getUsersModel()
66
    {
67
        return static::$usersModel;
68
    }
69
70
    /**
71
     * Sets the user model.
72
     *
73
     * @param  string  $usersModel
74
     * @return void
75
     */
76
    public static function setUsersModel($usersModel)
77
    {
78
        static::$usersModel = $usersModel;
79
    }
80
81
    /**
82
     * Returns the category model.
83
     *
84
     * @return string
85
     */
86
    public static function getCategoriesModel()
87
    {
88
        return static::$categoryModel;
89
    }
90
91
    /**
92
     * Sets the categories model.
93
     *
94
     * @param  string  $categoryModel
95
     * @return void
96
     */
97
    public static function setCategoriesModel($categoryModel)
98
    {
99
        static::$categoryModel = $categoryModel;
100
    }
101
102
    public function getAuthor()
103
    {
104
        return $this->belongsTo(static::$usersModel, 'author');
105
    }
106
107
    public function getCategory()
108
    {
109
        return $this->belongsTo(static::$categoryModel, 'category');
110
    }
111
112
    /**
113
     * Get the user's first name.
114
     *
115
     * @param  string  $value
116
     * @return string
117
     */
118
    public function getCreatedByAttribute($value)
119
    {
120
        if ($value > 0)
121
            if ($user = Sentinel::findUserById($value))
122
                if ($user != null)
123
                    return $user->first_name . ' ' . $user->last_name;
124
125
        return $value;
126
    }
127
128
129
}
130