| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface SH4_Shifts_IAcl |
| 3 |
{ |
| 4 |
public function checkView( $shiftId ); |
| 5 |
public function checkCreate( $shiftId ); |
| 6 |
public function checkCreateDraft( $shiftId ); |
| 7 |
public function checkCreatePublished( $shiftId ); |
| 8 |
public function checkManager( $shiftId ); |
| 9 |
public function checkEmployeeAssignment( $ids, $employeeId ); |
| 10 |
public function checkChangeTime( $shiftId ); |
| 11 |
} |
| 12 |
|
| 13 |
class SH4_Shifts_Acl implements SH4_Shifts_IAcl |
| 14 |
{ |
| 15 |
public function __construct( |
| 16 |
HC3_Hooks $hooks, |
| 17 |
HC3_Settings $settings, |
| 18 |
|
| 19 |
SH4_App_Query $appQuery, |
| 20 |
SH4_Calendars_Permissions $calendarsPermissions, |
| 21 |
|
| 22 |
SH4_Shifts_Query $shiftsQuery, |
| 23 |
HC3_Auth $auth, |
| 24 |
HC3_IPermission $permission |
| 25 |
) |
| 26 |
{ |
| 27 |
$this->self = $hooks->wrap( $this ); |
| 28 |
|
| 29 |
$this->settings = $hooks->wrap( $settings ); |
| 30 |
$this->appQuery = $hooks->wrap( $appQuery ); |
| 31 |
$this->auth = $hooks->wrap( $auth ); |
| 32 |
$this->permission = $hooks->wrap( $permission ); |
| 33 |
$this->calendarsPermissions = $hooks->wrap( $calendarsPermissions ); |
| 34 |
|
| 35 |
$this->shiftsQuery = $hooks->wrap( $shiftsQuery ); |
| 36 |
} |
| 37 |
|
| 38 |
public function checkDelete( $shiftId ) |
| 39 |
{ |
| 40 |
$return = FALSE; |
| 41 |
|
| 42 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 43 |
|
| 44 |
if( $shift->isDraft() ){ |
| 45 |
if( $this->self->checkDeleteDraft($shiftId) ){ |
| 46 |
$return = TRUE; |
| 47 |
} |
| 48 |
} |
| 49 |
else { |
| 50 |
if( $this->self->checkDeletePublished($shiftId) ){ |
| 51 |
$return = TRUE; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
return $return; |
| 56 |
} |
| 57 |
|
| 58 |
public function checkCreate( $shiftId ) |
| 59 |
{ |
| 60 |
$return = FALSE; |
| 61 |
|
| 62 |
if( $this->self->checkCreateDraft($shiftId) ){ |
| 63 |
$return = TRUE; |
| 64 |
return $return; |
| 65 |
} |
| 66 |
|
| 67 |
if( $this->self->checkCreatePublished($shiftId) ){ |
| 68 |
$return = TRUE; |
| 69 |
return $return; |
| 70 |
} |
| 71 |
|
| 72 |
return $return; |
| 73 |
} |
| 74 |
|
| 75 |
public function checkCreatePublished( $shiftId ) |
| 76 |
{ |
| 77 |
$return = FALSE; |
| 78 |
|
| 79 |
$currentUser = $this->auth->getCurrentUser(); |
| 80 |
$currentUserId = $currentUser->getId(); |
| 81 |
if( ! $currentUserId ){ |
| 82 |
return $return; |
| 83 |
} |
| 84 |
|
| 85 |
if( $this->permission->isAdmin($currentUser) ){ |
| 86 |
$return = TRUE; |
| 87 |
return $return; |
| 88 |
} |
| 89 |
|
| 90 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 91 |
$calendar = $shift->getCalendar(); |
| 92 |
$calendarId = $calendar->getId(); |
| 93 |
|
| 94 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 95 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 96 |
$return = TRUE; |
| 97 |
return $return; |
| 98 |
} |
| 99 |
|
| 100 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 101 |
|
| 102 |
if( ! $meEmployee ){ |
| 103 |
return $return; |
| 104 |
} |
| 105 |
|
| 106 |
$shiftEmployee = $shift->getEmployee(); |
| 107 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 108 |
|
| 109 |
$meEmployeeId = $meEmployee->getId(); |
| 110 |
|
| 111 |
if( $meEmployeeId != $shiftEmployeeId ){ |
| 112 |
return $return; |
| 113 |
} |
| 114 |
|
| 115 |
$calendarsAsEmployee = array(); |
| 116 |
|
| 117 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 118 |
foreach( $employeeCalendars as $thisCalendar ){ |
| 119 |
$thisCalendarId = $thisCalendar->getId(); |
| 120 |
|
| 121 |
if( $this->calendarsPermissions->get($thisCalendar, 'employee_create_own_publish') ){ |
| 122 |
$calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
if( isset($calendarsAsEmployee[$calendarId]) ){ |
| 127 |
$return = TRUE; |
| 128 |
return $return; |
| 129 |
} |
| 130 |
|
| 131 |
return $return; |
| 132 |
} |
| 133 |
|
| 134 |
public function checkDeletePublished( $shiftId ) |
| 135 |
{ |
| 136 |
$return = FALSE; |
| 137 |
|
| 138 |
$currentUser = $this->auth->getCurrentUser(); |
| 139 |
$currentUserId = $currentUser->getId(); |
| 140 |
if( ! $currentUserId ){ |
| 141 |
return $return; |
| 142 |
} |
| 143 |
|
| 144 |
if( $this->permission->isAdmin($currentUser) ){ |
| 145 |
$return = TRUE; |
| 146 |
return $return; |
| 147 |
} |
| 148 |
|
| 149 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 150 |
$calendar = $shift->getCalendar(); |
| 151 |
$calendarId = $calendar->getId(); |
| 152 |
|
| 153 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 154 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 155 |
$return = TRUE; |
| 156 |
return $return; |
| 157 |
} |
| 158 |
|
| 159 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 160 |
|
| 161 |
if( ! $meEmployee ){ |
| 162 |
return $return; |
| 163 |
} |
| 164 |
|
| 165 |
$shiftEmployee = $shift->getEmployee(); |
| 166 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 167 |
|
| 168 |
$meEmployeeId = $meEmployee->getId(); |
| 169 |
|
| 170 |
if( $meEmployeeId != $shiftEmployeeId ){ |
| 171 |
return $return; |
| 172 |
} |
| 173 |
|
| 174 |
$calendarsAsEmployee = array(); |
| 175 |
|
| 176 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 177 |
foreach( $employeeCalendars as $thisCalendar ){ |
| 178 |
$thisCalendarId = $thisCalendar->getId(); |
| 179 |
|
| 180 |
if( $this->calendarsPermissions->get($thisCalendar, 'employee_delete_own_publish') ){ |
| 181 |
$calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
if( isset($calendarsAsEmployee[$calendarId]) ){ |
| 186 |
$return = TRUE; |
| 187 |
return $return; |
| 188 |
} |
| 189 |
|
| 190 |
return $return; |
| 191 |
} |
| 192 |
|
| 193 |
public function checkEditPublished( $shiftId ) |
| 194 |
{ |
| 195 |
$return = FALSE; |
| 196 |
|
| 197 |
$currentUser = $this->auth->getCurrentUser(); |
| 198 |
$currentUserId = $currentUser->getId(); |
| 199 |
if( ! $currentUserId ){ |
| 200 |
return $return; |
| 201 |
} |
| 202 |
|
| 203 |
if( $this->permission->isAdmin($currentUser) ){ |
| 204 |
$return = TRUE; |
| 205 |
return $return; |
| 206 |
} |
| 207 |
|
| 208 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 209 |
$calendar = $shift->getCalendar(); |
| 210 |
$calendarId = $calendar->getId(); |
| 211 |
|
| 212 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 213 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 214 |
$return = TRUE; |
| 215 |
return $return; |
| 216 |
} |
| 217 |
|
| 218 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 219 |
|
| 220 |
if( ! $meEmployee ){ |
| 221 |
return $return; |
| 222 |
} |
| 223 |
|
| 224 |
$shiftEmployee = $shift->getEmployee(); |
| 225 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 226 |
|
| 227 |
$meEmployeeId = $meEmployee->getId(); |
| 228 |
|
| 229 |
if( $meEmployeeId != $shiftEmployeeId ){ |
| 230 |
return $return; |
| 231 |
} |
| 232 |
|
| 233 |
$calendarsAsEmployee = array(); |
| 234 |
|
| 235 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 236 |
foreach( $employeeCalendars as $thisCalendar ){ |
| 237 |
$thisCalendarId = $thisCalendar->getId(); |
| 238 |
|
| 239 |
if( $this->calendarsPermissions->get($thisCalendar, 'employee_edit_own_publish') ){ |
| 240 |
$calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
if( isset($calendarsAsEmployee[$calendarId]) ){ |
| 245 |
$return = TRUE; |
| 246 |
return $return; |
| 247 |
} |
| 248 |
|
| 249 |
return $return; |
| 250 |
} |
| 251 |
|
| 252 |
public function checkChangeTime( $shiftId ) |
| 253 |
{ |
| 254 |
$return = FALSE; |
| 255 |
|
| 256 |
$currentUser = $this->auth->getCurrentUser(); |
| 257 |
$currentUserId = $currentUser->getId(); |
| 258 |
if( ! $currentUserId ){ |
| 259 |
return $return; |
| 260 |
} |
| 261 |
|
| 262 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 263 |
if( $shift->isMultiDay() ){ |
| 264 |
return $return; |
| 265 |
} |
| 266 |
|
| 267 |
if( $shift->isPublished() ){ |
| 268 |
return $this->self->checkEditPublished( $shiftId, $currentUser ); |
| 269 |
} |
| 270 |
else { |
| 271 |
return $this->self->checkEditDraft( $shiftId, $currentUser ); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
public function checkCreateDraft( $shiftId ) |
| 276 |
{ |
| 277 |
$return = FALSE; |
| 278 |
|
| 279 |
$currentUser = $this->auth->getCurrentUser(); |
| 280 |
$currentUserId = $currentUser->getId(); |
| 281 |
if( ! $currentUserId ){ |
| 282 |
return $return; |
| 283 |
} |
| 284 |
|
| 285 |
$noDraft = $this->settings->get('shifts_no_draft') ? TRUE : FALSE; |
| 286 |
if( $noDraft ){ |
| 287 |
return $return; |
| 288 |
} |
| 289 |
|
| 290 |
if( $this->permission->isAdmin($currentUser) ){ |
| 291 |
$return = TRUE; |
| 292 |
return $return; |
| 293 |
} |
| 294 |
|
| 295 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 296 |
$calendar = $shift->getCalendar(); |
| 297 |
$calendarId = $calendar->getId(); |
| 298 |
|
| 299 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 300 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 301 |
$return = TRUE; |
| 302 |
return $return; |
| 303 |
} |
| 304 |
|
| 305 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 306 |
|
| 307 |
if( ! $meEmployee ){ |
| 308 |
return $return; |
| 309 |
} |
| 310 |
|
| 311 |
$shiftEmployee = $shift->getEmployee(); |
| 312 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 313 |
|
| 314 |
$meEmployeeId = $meEmployee->getId(); |
| 315 |
|
| 316 |
if( $meEmployeeId != $shiftEmployeeId ){ |
| 317 |
return $return; |
| 318 |
} |
| 319 |
|
| 320 |
$calendarsAsEmployee = array(); |
| 321 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 322 |
foreach( $employeeCalendars as $thisCalendar ){ |
| 323 |
$thisCalendarId = $thisCalendar->getId(); |
| 324 |
if( $this->calendarsPermissions->get($thisCalendar, 'employee_create_own_draft') ){ |
| 325 |
$calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
if( isset($calendarsAsEmployee[$calendarId]) ){ |
| 330 |
$return = TRUE; |
| 331 |
return $return; |
| 332 |
} |
| 333 |
|
| 334 |
return $return; |
| 335 |
} |
| 336 |
|
| 337 |
public function checkDeleteDraft( $shiftId ) |
| 338 |
{ |
| 339 |
$return = FALSE; |
| 340 |
|
| 341 |
$currentUser = $this->auth->getCurrentUser(); |
| 342 |
$currentUserId = $currentUser->getId(); |
| 343 |
if( ! $currentUserId ){ |
| 344 |
return $return; |
| 345 |
} |
| 346 |
|
| 347 |
$noDraft = $this->settings->get('shifts_no_draft') ? TRUE : FALSE; |
| 348 |
if( $noDraft ){ |
| 349 |
return $return; |
| 350 |
} |
| 351 |
|
| 352 |
if( $this->permission->isAdmin($currentUser) ){ |
| 353 |
$return = TRUE; |
| 354 |
return $return; |
| 355 |
} |
| 356 |
|
| 357 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 358 |
$calendar = $shift->getCalendar(); |
| 359 |
$calendarId = $calendar->getId(); |
| 360 |
|
| 361 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 362 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 363 |
$return = TRUE; |
| 364 |
return $return; |
| 365 |
} |
| 366 |
|
| 367 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 368 |
|
| 369 |
if( ! $meEmployee ){ |
| 370 |
return $return; |
| 371 |
} |
| 372 |
|
| 373 |
$shiftEmployee = $shift->getEmployee(); |
| 374 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 375 |
|
| 376 |
$meEmployeeId = $meEmployee->getId(); |
| 377 |
|
| 378 |
if( $meEmployeeId != $shiftEmployeeId ){ |
| 379 |
return $return; |
| 380 |
} |
| 381 |
|
| 382 |
$calendarsAsEmployee = array(); |
| 383 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 384 |
foreach( $employeeCalendars as $thisCalendar ){ |
| 385 |
$thisCalendarId = $thisCalendar->getId(); |
| 386 |
if( $this->calendarsPermissions->get($thisCalendar, 'employee_delete_own_draft') ){ |
| 387 |
$calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
if( isset($calendarsAsEmployee[$calendarId]) ){ |
| 392 |
$return = TRUE; |
| 393 |
return $return; |
| 394 |
} |
| 395 |
|
| 396 |
return $return; |
| 397 |
} |
| 398 |
|
| 399 |
public function checkEditDraft( $shiftId ) |
| 400 |
{ |
| 401 |
$return = FALSE; |
| 402 |
|
| 403 |
$currentUser = $this->auth->getCurrentUser(); |
| 404 |
$currentUserId = $currentUser->getId(); |
| 405 |
if( ! $currentUserId ){ |
| 406 |
return $return; |
| 407 |
} |
| 408 |
|
| 409 |
$noDraft = $this->settings->get('shifts_no_draft') ? TRUE : FALSE; |
| 410 |
if( $noDraft ){ |
| 411 |
return $return; |
| 412 |
} |
| 413 |
|
| 414 |
if( $this->permission->isAdmin($currentUser) ){ |
| 415 |
$return = TRUE; |
| 416 |
return $return; |
| 417 |
} |
| 418 |
|
| 419 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 420 |
$calendar = $shift->getCalendar(); |
| 421 |
$calendarId = $calendar->getId(); |
| 422 |
|
| 423 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 424 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 425 |
$return = TRUE; |
| 426 |
return $return; |
| 427 |
} |
| 428 |
|
| 429 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 430 |
|
| 431 |
if( ! $meEmployee ){ |
| 432 |
return $return; |
| 433 |
} |
| 434 |
|
| 435 |
$shiftEmployee = $shift->getEmployee(); |
| 436 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 437 |
|
| 438 |
$meEmployeeId = $meEmployee->getId(); |
| 439 |
|
| 440 |
if( $meEmployeeId != $shiftEmployeeId ){ |
| 441 |
return $return; |
| 442 |
} |
| 443 |
|
| 444 |
$calendarsAsEmployee = array(); |
| 445 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 446 |
foreach( $employeeCalendars as $thisCalendar ){ |
| 447 |
$thisCalendarId = $thisCalendar->getId(); |
| 448 |
if( $this->calendarsPermissions->get($thisCalendar, 'employee_edit_own_draft') ){ |
| 449 |
$calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar; |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
if( isset($calendarsAsEmployee[$calendarId]) ){ |
| 454 |
$return = TRUE; |
| 455 |
return $return; |
| 456 |
} |
| 457 |
|
| 458 |
return $return; |
| 459 |
} |
| 460 |
|
| 461 |
public function checkManager( $ids ) |
| 462 |
{ |
| 463 |
$return = FALSE; |
| 464 |
|
| 465 |
$currentUser = $this->auth->getCurrentUser(); |
| 466 |
$currentUserId = $currentUser->getId(); |
| 467 |
if( ! $currentUserId ){ |
| 468 |
return $return; |
| 469 |
} |
| 470 |
|
| 471 |
if( $this->permission->isAdmin($currentUser) ){ |
| 472 |
$return = TRUE; |
| 473 |
return $return; |
| 474 |
} |
| 475 |
|
| 476 |
$ids = HC3_Functions::unglueArray( $ids ); |
| 477 |
$shifts = $this->shiftsQuery->findManyById( $ids ); |
| 478 |
|
| 479 |
foreach( $shifts as $shift ){ |
| 480 |
$calendar = $shift->getCalendar(); |
| 481 |
$calendarId = $calendar->getId(); |
| 482 |
|
| 483 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 484 |
|
| 485 |
// check calendar |
| 486 |
if( ! isset($calendarsAsManager[$calendarId]) ){ |
| 487 |
return $return; |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
$return = TRUE; |
| 492 |
return $return; |
| 493 |
} |
| 494 |
|
| 495 |
public function checkEmployeeAssignment( $ids, $employeeId ) |
| 496 |
{ |
| 497 |
$return = FALSE; |
| 498 |
|
| 499 |
$currentUser = $this->auth->getCurrentUser(); |
| 500 |
if( ! $this->self->checkManager( $ids, $currentUser ) ){ |
| 501 |
return $return; |
| 502 |
} |
| 503 |
|
| 504 |
// check if open shifts are allowed |
| 505 |
if( ! $employeeId ){ |
| 506 |
$ids = HC3_Functions::unglueArray( $ids ); |
| 507 |
$shifts = $this->shiftsQuery->findManyById( $ids ); |
| 508 |
|
| 509 |
foreach( $shifts as $shift ){ |
| 510 |
$calendar = $shift->getCalendar(); |
| 511 |
|
| 512 |
$employees = $this->appQuery->findEmployeesForCalendar( $calendar ); |
| 513 |
if( ! isset($employees[0]) ){ |
| 514 |
return $return; |
| 515 |
} |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
$return = TRUE; |
| 520 |
return $return; |
| 521 |
} |
| 522 |
|
| 523 |
public function checkView( $shiftId ) |
| 524 |
{ |
| 525 |
$return = FALSE; |
| 526 |
|
| 527 |
$shift = $this->shiftsQuery->findById( $shiftId ); |
| 528 |
if( ! ($shift && $shift->getId()) ){ |
| 529 |
return $return; |
| 530 |
} |
| 531 |
|
| 532 |
$calendar = $shift->getCalendar(); |
| 533 |
$calendarId = $calendar->getId(); |
| 534 |
|
| 535 |
$currentUser = $this->auth->getCurrentUser(); |
| 536 |
$currentUserId = $currentUser->getId(); |
| 537 |
if( ! $currentUserId ){ |
| 538 |
if( $shift->isOpen() ){ |
| 539 |
$permName = $shift->isPublished() ? 'visitor_view_open_publish' : 'visitor_view_open_draft'; |
| 540 |
} |
| 541 |
else { |
| 542 |
$permName = $shift->isPublished() ? 'visitor_view_others_publish' : 'visitor_view_others_draft'; |
| 543 |
} |
| 544 |
|
| 545 |
$perm = $this->calendarsPermissions->get( $calendar, $permName ); |
| 546 |
if( $perm ){ |
| 547 |
$return = TRUE; |
| 548 |
} |
| 549 |
|
| 550 |
return $return; |
| 551 |
} |
| 552 |
|
| 553 |
if( $this->permission->isAdmin($currentUser) ){ |
| 554 |
$return = TRUE; |
| 555 |
return $return; |
| 556 |
} |
| 557 |
|
| 558 |
$calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 559 |
if( isset($calendarsAsManager[$calendarId]) ){ |
| 560 |
$return = TRUE; |
| 561 |
return $return; |
| 562 |
} |
| 563 |
|
| 564 |
$calendarsAsViewer = $this->appQuery->findCalendarsViewedByUser( $currentUser ); |
| 565 |
if( isset($calendarsAsViewer[$calendarId]) ){ |
| 566 |
$return = TRUE; |
| 567 |
return $return; |
| 568 |
} |
| 569 |
|
| 570 |
$meEmployee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 571 |
if( ! $meEmployee ){ |
| 572 |
// treat as visitor |
| 573 |
if( $shift->isOpen() ){ |
| 574 |
$permName = $shift->isPublished() ? 'visitor_view_open_publish' : 'visitor_view_open_draft'; |
| 575 |
} |
| 576 |
else { |
| 577 |
$permName = $shift->isPublished() ? 'visitor_view_others_publish' : 'visitor_view_others_draft'; |
| 578 |
} |
| 579 |
$perm = $this->calendarsPermissions->get( $calendar, $permName ); |
| 580 |
if( $perm ){ |
| 581 |
$return = TRUE; |
| 582 |
} |
| 583 |
return $return; |
| 584 |
} |
| 585 |
|
| 586 |
$employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee ); |
| 587 |
// if( ! isset($employeeCalendars[$calendarId]) ){ |
| 588 |
// return $return; |
| 589 |
// } |
| 590 |
|
| 591 |
$shiftEmployee = $shift->getEmployee(); |
| 592 |
$shiftEmployeeId = $shiftEmployee->getId(); |
| 593 |
|
| 594 |
$meEmployeeId = $meEmployee->getId(); |
| 595 |
|
| 596 |
if( $meEmployeeId == $shiftEmployeeId ){ |
| 597 |
$return = TRUE; |
| 598 |
return $return; |
| 599 |
} |
| 600 |
|
| 601 |
if( isset($employeeCalendars[$calendarId]) ){ |
| 602 |
if( $shift->isOpen() ){ |
| 603 |
$permName = $shift->isPublished() ? 'employee_view_open_publish' : 'employee_view_open_draft'; |
| 604 |
} |
| 605 |
else { |
| 606 |
$permName = $shift->isPublished() ? 'employee_view_others_publish' : 'employee_view_others_draft'; |
| 607 |
} |
| 608 |
} |
| 609 |
else { |
| 610 |
if( $shift->isOpen() ){ |
| 611 |
$permName = $shift->isPublished() ? 'employee2_view_open_publish' : 'employee2_view_open_draft'; |
| 612 |
} |
| 613 |
else { |
| 614 |
$permName = $shift->isPublished() ? 'employee2_view_others_publish' : 'employee2_view_others_draft'; |
| 615 |
} |
| 616 |
} |
| 617 |
$perm = $this->calendarsPermissions->get( $calendar, $permName ); |
| 618 |
|
| 619 |
if( $perm ){ |
| 620 |
$return = TRUE; |
| 621 |
} |
| 622 |
|
| 623 |
return $return; |
| 624 |
} |
| 625 |
} |