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 database table used by the model. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | //protected $table = 'employees'; |
||
54 | |||
55 | /** |
||
56 | * The attributes that are mass assignable. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $fillable = ['name', 'email', 'password']; |
||
61 | |||
62 | /** |
||
63 | * The attributes excluded from the model's JSON form. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $hidden = ['password', 'remember_token', 'pivot']; |
||
68 | |||
69 | /** |
||
70 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
71 | */ |
||
72 | 2 | public function company() |
|
76 | |||
77 | /** |
||
78 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
79 | */ |
||
80 | 18 | public function groups() |
|
81 | { |
||
82 | 18 | return $this->belongsToMany('plunner\Group', 'employee_group', 'employee_id'); //needed for planner model |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
87 | */ |
||
88 | public function meetings() |
||
92 | |||
93 | /** |
||
94 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
95 | */ |
||
96 | 2 | public function calendars() |
|
97 | { |
||
98 | 2 | return $this->hasMany('plunner\Calendar'); |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get the e-mail address where password reset links are sent. |
||
103 | * This is needed for multiple user type login |
||
104 | * |
||
105 | * Make email unique |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | 2 | public function getEmailForPasswordReset() |
|
110 | { |
||
111 | 2 | list(, $caller) = debug_backtrace(false); |
|
112 | 2 | if(isset($caller['class'])) |
|
113 | 2 | $caller = explode('\\', $caller['class']); |
|
114 | else |
||
115 | $caller = ''; |
||
116 | |||
117 | //check if this function is called by email sender |
||
118 | 2 | if ((count($caller) && $caller[count($caller) - 1] == 'PasswordBroker') || (defined('HHVM_VERSION') && $caller == '')) |
|
119 | 2 | return $this->email; |
|
120 | //return unique identify for token repository |
||
121 | 2 | return $this->email . $this->company->id; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param Group $group |
||
126 | * @return bool |
||
127 | */ |
||
128 | 8 | public function belongsToGroup(Group $group) |
|
135 | |||
136 | /* |
||
137 | * for a normal employee the policyCheckable methods say if the employee can se or not the element |
||
138 | */ |
||
139 | |||
140 | /** |
||
141 | * @param Group $group |
||
142 | * @return bool |
||
143 | */ |
||
144 | 4 | public function verifyGroup(Group $group) |
|
145 | { |
||
146 | 4 | return $this->belongsToGroup($group); |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * @param Employee $employee |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function verifyEmployee(Employee $employee) |
||
157 | |||
158 | /** |
||
159 | * @param Company $company |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function verifyCompany(Company $company) |
||
166 | } |
||
167 |