Completed
Push — master ( 4b2855...383ea8 )
by claudio
04:18
created

Employee::company()   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 0
crap 1
1
<?php
2
3
namespace plunner;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Auth\Authenticatable;
7
use Illuminate\Auth\Passwords\CanResetPassword;
8
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
9
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
10
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
11
use Illuminate\Foundation\Auth\Access\Authorizable;
12
13
/**
14
 * plunner\Employee
15
 *
16
 * @property integer $id
17
 * @property string $name
18
 * @property string $email
19
 * @property string $password
20
 * @property integer $company_id
21
 * @property string $remember_token
22
 * @property \Carbon\Carbon $created_at
23
 * @property \Carbon\Carbon $updated_at
24
 * @property-read \plunner\Company $company
25
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Group[] $groups
26
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereId($value)
27
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereName($value)
28
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereEmail($value)
29
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee wherePassword($value)
30
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereCompanyId($value)
31
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereRememberToken($value)
32
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereCreatedAt($value)
33
 * @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereUpdatedAt($value)
34
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Meeting[] $meetings
35
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Calendar[] $calendars
36
 */
37
class Employee extends Model implements AuthenticatableContract,
38
                                        AuthorizableContract,
39
                                        CanResetPasswordContract,
40
                                        PolicyCheckable
41
{
42
    use Authenticatable, Authorizable, CanResetPassword;
43
44
    /**
45
     * The database table used by the model.
46
     *
47
     * @var string
48
     */
49
    //protected $table = 'employees';
50
51
    /**
52
     * The attributes that are mass assignable.
53
     *
54
     * @var array
55
     */
56
    protected $fillable = ['name', 'email', 'password'];
57
58
    /**
59
     * The attributes excluded from the model's JSON form.
60
     *
61
     * @var array
62
     */
63
    protected $hidden = ['password', 'remember_token'];
64
65
    /**
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
67
     */
68 2
    public function company()
69
    {
70 2
        return $this->belongsTo('plunner\Company');
71
    }
72
73
    /**
74
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
75
     */
76
    public function groups()
77
    {
78
        return $this->belongsToMany('plunner\Group', 'employee_groups');
79
    }
80
81
    /**
82
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
83
     */
84
    public function meetings()
85
    {
86
        return $this->belongsToMany('plunner\Meeting');
87
    }
88
89
    /**
90
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
91
     */
92
    public function calendars()
93
    {
94
        return $this->hasMany('App\Calendar');
95
    }
96
97
    /**
98
     * Get the e-mail address where password reset links are sent.
99
     * This is needed for multiple user type login
100
     *
101
     * Make email unique
102
     *
103
     * @return string
104
     */
105 2
    public function getEmailForPasswordReset()
106
    {
107 2
        return $this->email.$this->company->id;
108
    }
109
110
    /**
111
     * @param Group $group
112
     * @return bool
113
     */
114
    public function verifyGroup(Group $group)
115
    {
116
        return $this->groups()->where('id', $group->id)->first()->exists;
117
    }
118
119
    /**
120
     * @param Employee $employee
121
     * @return bool
122
     */
123
    public function verifyEmployee(Employee $employee)
124
    {
125
        return $employee->id === $this->id;
126
    }
127
128
    /**
129
     * @param Company $company
130
     * @return bool
131
     */
132
    public function verifyCompany(Company $company)
133
    {
134
        return $company->id === $this->company_id;
135
    }
136
}
137