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 / employees / html / admin / controller / calendars.php

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

57 lines 1.5 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_Employees_Html_Admin_Controller_Calendars
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( $employeeId )
26 {
27 $employee = $this->employeesQuery->findById( $employeeId );
28
29 $current = $this->appQuery->findCalendarsForEmployee( $employee );
30 $currentIds = array_keys( $current );
31
32 $newIds = $this->post->get('calendar');
33 if( ! $newIds ){
34 $newIds = array();
35 }
36
37 $toAddIds = array_diff( $newIds, $currentIds );
38 $toRemoveIds = array_diff( $currentIds, $newIds );
39
40 if( $toAddIds ){
41 $toAdd = $this->calendarsQuery->findManyActiveById( $toAddIds );
42 foreach( $toAdd as $calendar ){
43 $this->appCommand->addEmployeeToCalendar( $employee, $calendar );
44 }
45 }
46
47 if( $toRemoveIds ){
48 $toRemove = $this->calendarsQuery->findManyActiveById( $toRemoveIds );
49 foreach( $toRemove as $calendar ){
50 $this->appCommand->removeEmployeeFromCalendar( $employee, $calendar );
51 }
52 }
53
54 $return = array( 'admin/employees', '__Employee Updated__' );
55 return $return;
56 }
57 }