Completed
Push — master ( c6be7b...ac3a6a )
by claudio
03:59
created

Employee::meetings()   A

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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 3
    public function groups()
77
    {
78 3
        return $this->belongsToMany('plunner\Group', 'employee_group', 'employee_id'); //needed for planner model
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 3
    public function belongsToGroup(Group $group)
115
    {
116 3
        $group = $this->groups()->where('id', $group->id)->first();
117 3
        if(is_object($group) && $group->exists)
118 3
            return true;
119 3
        return false;
120
    }
121
122
    /**
123
     * @param Group $group
124
     * @return bool
125
     */
126
    public function verifyGroup(Group $group)
127
    {
128
        return false; //$this->belongsToGroup($group);
129
    }
130
131
    /**
132
     * @param Employee $employee
133
     * @return bool
134
     */
135
    public function verifyEmployee(Employee $employee)
136
    {
137
        return false; //$employee->id === $this->id;
138
    }
139
140
    /**
141
     * @param Company $company
142
     * @return bool
143
     */
144
    public function verifyCompany(Company $company)
145
    {
146
        return false; //$company->id === $this->company_id;
147
    }
148
}
149