Completed
Push — master ( cd2ebb...7ad1ba )
by Tony
11s
created

User::ports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Foundation\Auth\User as Authenticatable;
6
7
/**
8
 * @property string $username
9
 * @property string $realname
10
 * @property string $password
11
 * @property string $email
12
 * @property int $level
13
 */
14
class User extends Authenticatable
15
{
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = [
22
        'realname', 'username', 'password', 'email', 'level',
23
    ];
24
    protected $primaryKey = 'user_id';
25
26
    /**
27
     * The attributes excluded from the model's JSON form.
28
     *
29
     * @var array
30
     */
31
    protected $hidden = [
32
        'password', 'remember_token',
33
    ];
34
35
36
    // ---- Define Convience Functions ----
37
38
    /**
39
     * Test if the User is an admin or demo.
40
     *
41
     * @return boolean
42
     */
43 6
    public function isAdmin()
44
    {
45 6
        return $this->level >= 10;
46
    }
47
48
    /**
49
     * Test if this user has global read access
50
     * these users have a level of 5, 10 or 11 (demo).
51
     *
52
     * @return boolean
53
     */
54 6
    public function hasGlobalRead()
55
    {
56 6
        return $this->isAdmin() || $this->level == 5;
57
    }
58
59
60
    // ---- Define Reletionships ----
61
62
    /**
63
     * Returns a list of devices this user has access to
64
     */
65 4
    public function devices() {
66 4
        return $this->belongsToMany('App\Models\Device', 'devices_perms', 'user_id', 'device_id');
67
    }
68
69
    /**
70
     * Returns a list of ports this user has access to
71
     */
72 2
    public function ports() {
73 2
        return $this->belongsToMany('App\Models\Port', 'ports_perms', 'user_id', 'port_id');
74
    }
75
76
    /**
77
     * Returns a list of dashboards this user has access to
78
     */
79
    public function dashboards() {
80
        return $this->hasMany('App\Models\Dashboard');
81
    }
82
}
83