Completed
Pull Request — develop (#98)
by Neil
22:06
created

Alerts   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 55
ccs 2
cts 8
cp 0.25
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A device() 0 4 1
A rule() 0 4 1
A user() 0 4 1
A scopeActive() 0 4 1
1
<?php
2
/*
3
 * Copyright (C) 2016 Neil Lathwood <[email protected]>
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
 
18
namespace App\Models\Alerting;
19
20
use Illuminate\Database\Eloquent\Model;
21
use Illuminate\Database\Eloquent\Builder;
22
23
/**
24
 *
25
 */
26
class Alerts extends Model
27
{
28
    /**
29
     * Indicates if the model should be timestamped.
30
     *
31
     * @var bool
32
     */
33
    public $timestamps = false;
34
    /**
35
     * The table associated with the model.
36
     *
37
     * @var string
38
     */
39
    protected $table = 'alerts';
40
    /**
41
     * The primary key column name.
42
     *
43
     * @var string
44
     */
45
    protected $primaryKey = 'id';
46
47
    // ---- Define Reletionships ----
48
49
    /**
50
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51
     */
52
    public function device()
53
    {
54
        return $this->belongsTo('App\Models\Device', 'device_id');
55
    }
56
57
    /**
58
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
59
     */
60
    public function rule()
61
    {
62
        return $this->belongsTo('App\Models\Alerting\Rules', 'rule_id');
63
    }
64
65
    /**
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
67
     */
68
    public function user()
69
    {
70
        return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
71
    }
72
73
    /**
74
     *
75
     */
76 1
     public function scopeActive(Builder $query)
77
     {
78 1
         return $query->where('state', '!=', '0');
79
     }
80
}
81