PluginProbe
ShiftController Employee Shift Scheduling / 4.9.59
ShiftController Employee Shift Scheduling v4.9.59
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
← All changes | sh4/app/query.php +67 -111 4.9.75 → 4.9.59 View file →
@@ -24,17 +24,8 @@
24 24 class SH4_App_Query implements SH4_App_IQuery
25 25 {
26 26 public $self, $settings, $permission, $shiftTypesQuery, $calendarsQuery, $employeesQuery, $cp, $t, $usersQuery, $crudFactory;
27 27
28 - public $repoEmployee = array();
29 - public $repoActiveEmployee = array();
30 - public $repoActiveCalendar = array();
31 - public $repoShiftType = array();
32 - public $repoUser = array();
33 -
34 - public $repoEmployeeUser = array();
35 - public $repoUserEmployee = array();
36 -
37 28 public function __construct(
38 29 HC3_Settings $settings,
39 30 HC3_IPermission $permission,
40 31
@@ -60,32 +51,8 @@
60 51 $this->usersQuery = $hooks->wrap( $usersQuery );
61 52 $this->cp = $hooks->wrap( $cp );
62 53
63 54 $this->self = $hooks->wrap( $this );
64 -
65 - // employee
66 - $this->repoActiveEmployee = $this->employeesQuery->findActive();
67 - $this->repoEmployee = $this->repoActiveEmployee;
68 -
69 - // calendar
70 - $this->repoActiveCalendar = $this->calendarsQuery->findActive();
71 -
72 - // shift type
73 - $this->repoShiftType = $this->shiftTypesQuery->findAll();
74 -
75 - // employee-user
76 - global $wpdb;
77 - $sql = 'SELECT post_id AS employee_id, meta_value AS user_id FROM ' . $wpdb->postmeta . ' wpostmeta' . ' JOIN ' . $wpdb->posts . ' wposts ON wposts.ID = wpostmeta.post_id WHERE wpostmeta.meta_key="user_id" AND wposts.post_type="sh4_employee"';
78 - $res = $wpdb->get_results( $sql, ARRAY_A );
79 - foreach( $res as $e ){
80 - if( ! $e['employee_id'] ) continue;
81 - $this->repoEmployeeUser[ $e['employee_id'] ] = $e['user_id'];
82 - $this->repoUserEmployee[ $e['user_id'] ] = $e['employee_id'];
83 - }
84 -
85 - if( $this->repoUserEmployee ){
86 - $this->repoUser = $this->usersQuery->findManyById( array_keys($this->repoUserEmployee) );
87 - }
88 55 }
89 56
90 57 public function findCalendarsForChange( SH4_Shifts_Model $shift )
91 58 {
@@ -289,11 +256,10 @@
289 256 }
290 257
291 258 public function findCalendarsManagedByUser( HC3_Users_Model $user )
292 259 {
293 - // $ret = $this->calendarsQuery->findActive();
294 - // $ret = $this->self->filterCalendarsManagedByUser( $ret, $user );
295 - $ret = $this->self->filterCalendarsManagedByUser( $this->repoActiveCalendar, $user );
260 + $ret = $this->calendarsQuery->findActive();
261 + $ret = $this->self->filterCalendarsManagedByUser( $ret, $user );
296 262 return $ret;
297 263 }
298 264
299 265 public function filterCalendarsViewedByUser( array $ret, HC3_Users_Model $user )
@@ -316,11 +282,10 @@
316 282 }
317 283
318 284 public function findCalendarsViewedByUser( HC3_Users_Model $user )
319 285 {
320 - // $ret = $this->calendarsQuery->findActive();
321 - // $ret = $this->self->filterCalendarsViewedByUser( $ret, $user );
322 - $ret = $this->self->filterCalendarsViewedByUser( $this->repoActiveCalendar, $user );
286 + $ret = $this->calendarsQuery->findActive();
287 + $ret = $this->self->filterCalendarsViewedByUser( $ret, $user );
323 288 return $ret;
324 289 }
325 290
326 291 public function findManagersForCalendar( SH4_Calendars_Model $calendar )
@@ -389,36 +354,34 @@
389 354 }
390 355
391 356 public function findEmployeesForCalendar( SH4_Calendars_Model $calendar )
392 357 {
393 - $ret = array();
358 + $return = array();
394 359
395 360 $calendarId = $calendar->getId();
396 361 $settingName = 'calendar_' . $calendarId . '_employee';
397 362
398 - $listEmployeeId = $this->settings->get( $settingName, true );
399 - if( $listEmployeeId ){
400 - $ret = array_intersect_key( $this->repoActiveEmployee, array_combine($listEmployeeId, $listEmployeeId) );
401 - // $ret = $this->employeesQuery->findManyActiveById( $listEmployeeId );
363 + $employeesIds = $this->settings->get( $settingName, TRUE );
364 + if( $employeesIds ){
365 + $return = $this->employeesQuery->findManyActiveById( $employeesIds );
402 366 }
403 367
404 - return $ret;
368 + return $return;
405 369 }
406 370
407 371 public function findShiftTypesForCalendar( SH4_Calendars_Model $calendar )
408 372 {
409 - $ret = array();
373 + $return = array();
410 374
411 375 $calendarId = $calendar->getId();
412 376 $settingName = 'calendar_' . $calendarId . '_shifttype';
413 377
414 - $listShiftTypeId = $this->settings->get( $settingName, true );
415 - if( $listShiftTypeId ){
416 - // $ret = $this->shiftTypesQuery->findManyById( $listShiftTypeId );
417 - $ret = array_intersect_key( $this->repoShiftType, array_combine($listShiftTypeId, $listShiftTypeId) );
378 + $shiftTypesIds = $this->settings->get( $settingName, TRUE );
379 + if( $shiftTypesIds ){
380 + $return = $this->shiftTypesQuery->findManyById( $shiftTypesIds );
418 381 }
419 382
420 - return $ret;
383 + return $return;
421 384 }
422 385
423 386 public function filterCalendarsForEmployee( array $ret, SH4_Employees_Model $employee )
424 387 {
@@ -437,103 +400,96 @@
437 400 }
438 401
439 402 public function findCalendarsForEmployee( SH4_Employees_Model $employee )
440 403 {
441 - // $ret = $this->calendarsQuery->findActive();
442 - // $ret = $this->self->filterCalendarsForEmployee( $ret, $employee );
443 - $ret = $this->self->filterCalendarsForEmployee( $this->repoActiveCalendar, $employee );
404 + $ret = $this->calendarsQuery->findActive();
405 + $ret = $this->self->filterCalendarsForEmployee( $ret, $employee );
444 406 return $ret;
445 407 }
446 408
447 409 public function findAllUsersWithEmployee()
448 410 {
449 - $ret = array();
411 + $return = array();
450 412
451 - $usersIds = array_keys( $this->repoUserEmployee );
413 + $crud = $this->crudFactory->make('employee');
452 414
453 - // $crud = $this->crudFactory->make('employee');
415 + $args = array();
416 + $results = $crud->read( $args );
417 + if( ! $results ){
418 + return $return;
419 + }
454 420
455 - // $args = array();
456 - // $results = $crud->read( $args );
457 - // if( ! $results ){
458 - // return $ret;
459 - // }
421 + $usersIds = array();
422 + foreach( $results as $r ){
423 + $userId = array_key_exists('user_id', $r) ? $r['user_id'] : NULL;
424 + if( ! $userId ){
425 + continue;
426 + }
427 + $usersIds[ $userId ] = $userId;
428 + }
460 429
461 - // $usersIds = array();
462 - // foreach( $results as $r ){
463 - // $userId = array_key_exists('user_id', $r) ? $r['user_id'] : NULL;
464 - // if( ! $userId ){
465 - // continue;
466 - // }
467 - // $usersIds[ $userId ] = $userId;
468 - // }
469 -
470 430 if( ! $usersIds ){
471 - return $ret;
431 + return $return;
472 432 }
473 433
474 - $ret = $this->usersQuery->findManyById( $usersIds );
475 - return $ret;
434 + $return = $this->usersQuery->findManyById( $usersIds );
435 + return $return;
476 436 }
477 437
478 438 public function findUserByEmployee( SH4_Employees_Model $employee )
479 439 {
480 - $ret = null;
440 + $return = NULL;
481 441
482 442 $employeeId = $employee->getId();
483 443 if( ! $employeeId ){
484 - return $ret;
444 + return $return;
485 445 }
486 446
487 - $userId = isset( $this->repoEmployeeUser[$employeeId] ) ? $this->repoEmployeeUser[$employeeId] : null;
447 + $crud = $this->crudFactory->make('employee');
448 + $args = array();
449 + $args[] = array('id', '=', $employeeId );
450 + $results = $crud->read( $args );
488 451
489 - // $crud = $this->crudFactory->make('employee');
490 - // $args = array();
491 - // $args[] = array('id', '=', $employeeId );
492 - // $results = $crud->read( $args );
452 + if( ! $results ){
453 + return $return;
454 + }
493 455
494 - // if( ! $results ){
495 - // return $ret;
496 - // }
456 + $results = array_shift( $results );
457 + $userId = array_key_exists('user_id', $results) ? $results['user_id'] : NULL;
497 458
498 - // $results = array_shift( $results );
499 - // $userId = array_key_exists('user_id', $results) ? $results['user_id'] : null;
500 -
501 459 if( ! $userId ){
502 - return $ret;
460 + return $return;
503 461 }
504 462
505 - // $ret = $this->usersQuery->findById( $userId );
506 -
507 - if( ! isset($this->repoUser[$userId]) ){
508 - $this->repoUser[$userId] = $this->usersQuery->findById( $userId );
509 - }
510 - $ret = $this->repoUser[$userId];
511 -
512 - return $ret;
463 + $return = $this->usersQuery->findById( $userId );
464 + return $return;
513 465 }
514 466
515 - public function findEmployeeByUserId( $userId )
467 + public function findEmployeeByUser( HC3_Users_Model $user )
516 468 {
517 - $ret = null;
469 + $return = NULL;
470 +
471 + $userId = $user->getId();
518 472 if( ! $userId ){
519 - return $ret;
473 + return $return;
520 474 }
521 475
522 - $employeeId = isset( $this->repoUserEmployee[$userId] ) ? $this->repoUserEmployee[$userId] : null;
523 - if( ! $employeeId ){
524 - return $ret;
476 + $crud = $this->crudFactory->make('employee');
477 + $args = array();
478 + $args[] = array('user_id', '=', $userId );
479 + $results = $crud->read( $args );
480 +
481 + if( ! $results ){
482 + return $return;
525 483 }
526 484
527 - if( ! isset($this->repoEmployee[$employeeId]) ){
528 - $this->repoEmployee[$employeeId] = $this->employeesQuery->findById( $employeeId );
485 + $results = array_shift( $results );
486 + $employeeId = array_key_exists('id', $results) ? $results['id'] : NULL;
487 +
488 + if( ! $employeeId ){
489 + return $return;
529 490 }
530 - $ret = $this->repoEmployee[$employeeId];
531 491
532 - return $ret;
533 - }
534 -
535 - public function findEmployeeByUser( HC3_Users_Model $user )
536 - {
537 - return $this->self->findEmployeeByUserId( $user->getId() );
492 + $return = $this->employeesQuery->findById( $employeeId );
493 + return $return;
538 494 }
539 495 }