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