PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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
shiftcontroller / sh4 / calendars / html / admin / controller / employees.php

employees.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/calendars/html/admin/controller/employees.php

58 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 #[AllowDynamicProperties]
3 class SH4_Calendars_Html_Admin_Controller_Employees
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7 HC3_Post $post,
8
9 SH4_Employees_Query $employeesQuery,
10 SH4_Calendars_Query $calendarsQuery,
11
12 SH4_App_Query $appQuery,
13 SH4_App_Command $appCommand
14 )
15 {
16 $this->post = $hooks->wrap( $post );
17
18 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
19 $this->employeesQuery = $hooks->wrap( $employeesQuery );
20
21 $this->appQuery = $hooks->wrap( $appQuery );
22 $this->appCommand = $hooks->wrap( $appCommand );
23 }
24
25 public function execute( $calendarId )
26 {
27 $calendar = $this->calendarsQuery->findById( $calendarId );
28
29 $currentEmployees = $this->appQuery->findEmployeesForCalendar( $calendar );
30 $currentEmployeesIds = array_keys( $currentEmployees );
31
32 $employeesIds = $this->post->get('employee');
33 if( ! $employeesIds ){
34 $employeesIds = array();
35 }
36
37 $toAddIds = array_diff( $employeesIds, $currentEmployeesIds );
38 $toRemoveIds = array_diff( $currentEmployeesIds, $employeesIds );
39
40 if( $toAddIds ){
41 $toAdd = $this->employeesQuery->findManyActiveById( $toAddIds );
42
43 foreach( $toAdd as $employee ){
44 $this->appCommand->addEmployeeToCalendar( $employee, $calendar );
45 }
46 }
47
48 if( $toRemoveIds ){
49 $toRemove = $this->employeesQuery->findManyActiveById( $toRemoveIds );
50 foreach( $toRemove as $employee ){
51 $this->appCommand->removeEmployeeFromCalendar( $employee, $calendar );
52 }
53 }
54
55 $return = array( 'admin/calendars', '__Calendar Updated__' );
56 return $return;
57 }
58 }