Log::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * app/Models/Alerting/Log.php
4
 *
5
 * Model for access to alert log 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
30
/**
31
 * App\Models\Alerting\Log
32
 *
33
 * @property integer $id
34
 * @property integer $rule_id
35
 * @property integer $device_id
36
 * @property integer $state
37
 * @property mixed $details
38
 * @property string $time_logged
39
 * @property-read \App\Models\Device $device
40
 * @property-read \App\Models\Alerting\Rule $rule
41
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $user
42
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereId($value)
43
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereRuleId($value)
44
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereDeviceId($value)
45
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereState($value)
46
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereDetails($value)
47
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereTimeLogged($value)
48
 * @mixin \Eloquent
49
 */
50
class Log extends Model
51
{
52
    /**
53
     * Indicates if the model should be timestamped.
54
     *
55
     * @var bool
56
     */
57
    public $timestamps = false;
58
    /**
59
     * The table associated with the model.
60
     *
61
     * @var string
62
     */
63
    protected $table = 'alert_log';
64
    /**
65
     * The primary key column name.
66
     *
67
     * @var string
68
     */
69
    protected $primaryKey = 'id';
70
71
    // ---- Accessors/Mutators ----
72
73 1
    public function getDetailsAttribute($details)
74
    {
75 1
        if ($details) {
76
            return json_decode(gzuncompress($details), true);
77
        }
78 1
    }
79
80 1
    public function getTimeLoggedAttribute($date)
81
    {
82 1
        if ($date) {
83 1
            return strtotime($date) * 1000;
84
        }
85
    }
86
87
    // ---- Define Relationships ----
88
89
    /**
90
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
91
     */
92
    public function device()
93
    {
94
        return $this->belongsTo('App\Models\Device', 'device_id');
95
    }
96
97
    /**
98
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
99
     */
100
    public function rule()
101
    {
102
        return $this->belongsTo('App\Models\Alerting\Rule', 'rule_id');
103
    }
104
105
    /**
106
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
107
     */
108
    public function user()
109
    {
110
        return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
111
    }
112
}
113