Completed
Pull Request — develop (#38)
by Neil
09:06
created

Notification   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeUnread() 0 4 1
A scopeRead() 0 4 1
A scopeLimit() 0 4 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Notification extends Model
8
{
9
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'notifications';
16
17
    /**
18
     * The primary key column name.
19
     *
20
     * @var string
21
     */
22
    protected $primaryKey = 'notifications_id';
23
24
    /**
25
     * Indicates if the model should be timestamped.
26
     *
27
     * @var bool
28
     */
29
    public $timestamps = false;
30
31
    public function scopeUnread($query)
32
    {
33
        return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->whereNull('user_id')->orWhere(['key'=>'sticky', 'value'=> 1]);
34
    }
35
36
    public function scopeRead($query, $user_id)
37
    {
38
        return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->where('user_id', $user_id)->where(['key'=>'read', 'value'=> 1]);
39
    }
40
41
    public function scopeLimit($query)
42
    {
43
        return $query->select('notifications.*','key');
44
    }
45
46
}
47