Completed
Push — settings ( bea8d4...96499a )
by Tony
05:40
created

Alert   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 2
dl 0
loc 55
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
 * app/Models/Alerting/Alert.php
4
 *
5
 * Model for access to alerts table data
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2016 Neil Lathwood
23
 * @author     Neil Lathwood <[email protected]>
24
 */
25
26
namespace App\Models\Alerting;
27
28
use Illuminate\Database\Eloquent\Model;
29
use Illuminate\Database\Eloquent\Builder;
30
31
/**
32
 * @property integer $id
33
 * @property integer $device_id
34
 * @property integer $rule_id
35
 * @property integer $state
36
 * @property integer $alerted
37
 * @property integer $open
38
 * @property string $timestamp
39
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert active()
40
 */
41
class Alert extends Model
42
{
43
    /**
44
     * Indicates if the model should be timestamped.
45
     *
46
     * @var bool
47
     */
48
    public $timestamps = false;
49
    /**
50
     * The table associated with the model.
51
     *
52
     * @var string
53
     */
54
    protected $table = 'alerts';
55
    /**
56
     * The primary key column name.
57
     *
58
     * @var string
59
     */
60
    protected $primaryKey = 'id';
61
62
    // ---- Define Reletionships ----
63
64
    /**
65
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
66
     */
67
    public function device()
68
    {
69
        return $this->belongsTo('App\Models\Device', 'device_id');
70
    }
71
72
    /**
73
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
74
     */
75
    public function rule()
76
    {
77
        return $this->belongsTo('App\Models\Alerting\Rule', 'rule_id');
78
    }
79
80
    /**
81
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
82
     */
83
    public function user()
84
    {
85
        return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
86
    }
87
88
    /**
89
     *
90
     */
91
    public function scopeActive(Builder $query)
92
    {
93
        return $query->where('state', '!=', '0');
94
    }
95
}
96