1 | <?php |
||
41 | class Employee extends Model implements AuthenticatableContract, |
||
42 | AuthorizableContract, |
||
43 | CanResetPasswordContract, |
||
44 | PolicyCheckable |
||
45 | { |
||
46 | use Authenticatable, Authorizable, CanResetPassword; |
||
47 | |||
48 | /** |
||
49 | * The attributes that are mass assignable. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $fillable = ['name', 'email', 'password']; |
||
54 | |||
55 | /** |
||
56 | * The attributes excluded from the model's JSON form. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $hidden = ['password', 'remember_token', 'pivot']; |
||
61 | |||
62 | /** |
||
63 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
64 | */ |
||
65 | 2 | public function company() |
|
69 | |||
70 | /** |
||
71 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
72 | */ |
||
73 | 18 | public function groups() |
|
77 | |||
78 | /** |
||
79 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
80 | */ |
||
81 | 14 | public function calendars() |
|
82 | { |
||
83 | 14 | return $this->hasMany('plunner\Calendar'); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * meetings where the user participates |
||
88 | * to get all meetings where the user can go user groups with meetings |
||
89 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
90 | */ |
||
91 | 2 | public function meetings(){ |
|
92 | //TODO durign the inserting chek if the meeting is of a group of the user |
||
93 | 2 | return $this->belongsToMany(Meeting::class); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get the e-mail address where password reset links are sent. |
||
98 | * This is needed for multiple user type login |
||
99 | * |
||
100 | * Make email unique |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 2 | public function getEmailForPasswordReset() |
|
118 | |||
119 | /** |
||
120 | * @param Group $group |
||
121 | * @return bool |
||
122 | */ |
||
123 | 8 | public function belongsToGroup(Group $group) |
|
130 | |||
131 | /* |
||
132 | * for a normal employee the policyCheckable methods say if the employee can se or not the element |
||
133 | */ |
||
134 | |||
135 | /** |
||
136 | * @param Group $group |
||
137 | * @return bool |
||
138 | */ |
||
139 | 4 | public function verifyGroup(Group $group) |
|
140 | { |
||
141 | 4 | return $this->belongsToGroup($group); |
|
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param Employee $employee |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function verifyEmployee(Employee $employee) |
||
149 | { |
||
150 | return $employee->company_id === $this->company_id; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @param Company $company |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function verifyCompany(Company $company) |
||
158 | { |
||
159 | return $company->id === $this->company_id; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * the employee can modify a calendar |
||
164 | * @param Calendar $calendar |
||
165 | * @return bool |
||
166 | */ |
||
167 | 8 | public function verifyCalendar(Calendar $calendar) |
|
172 | } |
||
173 |