Completed
Pull Request — develop (#98)
by Neil
17:48
created

Alert::scopeActive()   A

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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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
 *
33
 */
34
class Alert extends Model
35
{
36
    /**
37
     * Indicates if the model should be timestamped.
38
     *
39
     * @var bool
40
     */
41
    public $timestamps = false;
42
    /**
43
     * The table associated with the model.
44
     *
45
     * @var string
46
     */
47
    protected $table = 'alerts';
48
    /**
49
     * The primary key column name.
50
     *
51
     * @var string
52
     */
53
    protected $primaryKey = 'id';
54
55
    // ---- Define Reletionships ----
56
57
    /**
58
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
59
     */
60
    public function device()
61
    {
62
        return $this->belongsTo('App\Models\Device', 'device_id');
63
    }
64
65
    /**
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
67
     */
68
    public function rule()
69
    {
70
        return $this->belongsTo('App\Models\Alerting\Rule', 'rule_id');
71
    }
72
73
    /**
74
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
75
     */
76
    public function user()
77
    {
78
        return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
79
    }
80
81
    /**
82
     *
83
     */
84 1
     public function scopeActive(Builder $query)
85
     {
86 1
         return $query->where('state', '!=', '0');
87
     }
88
}
89