1 | <?php |
||
31 | class Company extends Model implements AuthenticatableContract, |
||
32 | AuthorizableContract, |
||
33 | CanResetPasswordContract, |
||
34 | PolicyCheckable |
||
35 | { |
||
36 | use Authenticatable, Authorizable, CanResetPassword; |
||
37 | |||
38 | /** |
||
39 | * The attributes that are mass assignable. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $fillable = ['name', 'email', 'password']; |
||
44 | |||
45 | /** |
||
46 | * The attributes excluded from the model's JSON form. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $hidden = ['password', 'remember_token']; |
||
51 | |||
52 | /** |
||
53 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
54 | */ |
||
55 | 195 | public function employees() |
|
56 | { |
||
57 | 195 | return $this->hasMany(Employee::class); |
|
58 | } |
||
59 | |||
60 | 84 | public function groups() |
|
61 | { |
||
62 | 84 | return $this->hasMany(Group::class); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param Group $group |
||
67 | * @return bool |
||
68 | */ |
||
69 | 24 | public function verifyGroup(Group $group) |
|
70 | { |
||
71 | 24 | return $group->company_id === $this->id; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param Employee $employee |
||
76 | * @return bool |
||
77 | */ |
||
78 | 24 | public function verifyEmployee(Employee $employee) |
|
79 | { |
||
80 | 24 | return $employee->company_id === $this->id; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param Company $company |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function verifyCompany(Company $company) |
||
88 | { |
||
89 | return $company->id === $this->id; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @param Calendar $calendar |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function verifyCalendar(Calendar $calendar) |
||
97 | { |
||
98 | //TODO test this |
||
99 | return $calendar->employee->company->id == $this->id; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param Timeslot $timeslot |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function verifyTimeslot(Timeslot $timeslot) |
||
107 | { |
||
108 | //TODO implement and test this |
||
109 | return false; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @param Meeting $meeting |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function verifyMeeting(Meeting $meeting) |
||
117 | { |
||
118 | //TODO implement and test this |
||
119 | return false; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param MeetingTimeslot $meetingTimeslot |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function verifyMeetingTimeslot(MeetingTimeslot $meetingTimeslot) |
||
127 | { |
||
128 | //TODO implement and test this |
||
129 | return false; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param \DateTime $from |
||
134 | * @param \DateTime $to |
||
135 | * @return \Illuminate\Support\Collection |
||
136 | */ |
||
137 | 6 | public function getEmployeesTimeSlots($from, $to) |
|
149 | |||
150 | /** |
||
151 | * @param \DateTime $from |
||
152 | * @param \DateTime $to |
||
153 | * @return \Illuminate\Support\Collection |
||
154 | */ |
||
155 | 9 | public function getMeetingsTimeSlots($from, $to) |
|
156 | { |
||
157 | 9 | return \DB::table('meetings') |
|
158 | 9 | ->join('groups', 'meetings.group_id', '=', 'groups.id') |
|
159 | 9 | ->join('meeting_timeslots', 'meetings.id', '=', 'meeting_timeslots.meeting_id') |
|
160 | 9 | ->where('meeting_timeslots.time_start', '>=', $from) |
|
161 | 9 | ->where('meeting_timeslots.time_end', '<=', $to) |
|
162 | 9 | ->where('groups.company_id', '=', $this->id) |
|
163 | 9 | ->where('meetings.start_time', '=', NULL) |
|
164 | 9 | ->select('meetings.id', 'meetings.duration', 'meeting_timeslots.time_start', 'meeting_timeslots.time_end') |
|
165 | 9 | ->get(); |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * @param array $users |
||
170 | * @param array $meetings |
||
171 | * @return \Illuminate\Support\Collection |
||
172 | */ |
||
173 | 6 | public function getUsersMeetings(array $users, array $meetings) |
|
186 | } |
||
187 |