PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / shifts / controller / date.php

date.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/shifts/controller/date.php

132 lines 3.3 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 class SH4_Shifts_Controller_Date
3 {
4 public function __construct(
5 HC3_Hooks $hooks,
6 HC3_Post $post,
7 HC3_Time $t,
8
9 SH4_Shifts_Conflicts $conflicts,
10 HC3_Auth $auth,
11 HC3_IPermission $permission,
12 SH4_App_Query $appQuery,
13 SH4_Calendars_Permissions $calendarsPermissions,
14
15 SH4_ShiftTypes_Query $shiftTypesQuery,
16
17 SH4_Shifts_Query $query,
18 SH4_Shifts_Command $command,
19 SH4_Employees_Query $employees
20 )
21 {
22 $this->post = $post;
23 $this->t = $t;
24
25 $this->shiftTypesQuery = $hooks->wrap($shiftTypesQuery);
26
27 $this->query = $hooks->wrap($query);
28 $this->command = $hooks->wrap($command);
29 $this->employees = $hooks->wrap($employees);
30
31 $this->auth = $hooks->wrap( $auth );
32 $this->permission = $hooks->wrap( $permission );
33 $this->conflicts = $hooks->wrap($conflicts);
34 $this->appQuery = $hooks->wrap( $appQuery );
35 $this->calendarsPermissions = $hooks->wrap( $calendarsPermissions );
36 }
37
38 public function execute( $shiftId )
39 {
40 $shift = $this->query->findById( $shiftId );
41
42 $date = $this->post->get('date');
43
44 if( NULL === $date ){
45 $to = 'schedule';
46 $msg = '__Required Field__';
47 $ret = array( $to, $msg, TRUE );
48 return $ret;
49 }
50
51 $timeStart = $shift->getStartInDay();
52 $timeEnd = $shift->getEndInDay();
53
54 $startBreak = $shift->getBreakStartInDay();
55 $endBreak = $shift->getBreakEndInDay();
56
57 $start = $this->t->setDateDb( $date )
58 ->modify( '+' . $timeStart . ' seconds' )
59 ->formatDateTimeDb()
60 ;
61 $end = $this->t->setDateDb( $date )
62 ->modify( '+' . $timeEnd . ' seconds' )
63 ->formatDateTimeDb()
64 ;
65
66 if( NULL !== $startBreak ){
67 $startBreak = $this->t->setDateDb( $date )
68 ->modify( '+' . $startBreak . ' seconds' )
69 ->formatDateTimeDb()
70 ;
71 }
72 if( NULL !== $endBreak ){
73 $endBreak = $this->t->setDateDb( $date )
74 ->modify( '+' . $endBreak . ' seconds' )
75 ->formatDateTimeDb()
76 ;
77 }
78
79 // check if it creates a conflict
80 $calendar = $shift->getCalendar();
81 $calendarId = $calendar->getId();
82
83 // $testModel = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $shift->getEmployee(), $startBreak, $endBreak );
84 $testModel = new SH4_Shifts_Model( $shift->getId(), $calendar, $start, $end, $shift->getEmployee(), $startBreak, $endBreak );
85 $conflicts = $this->conflicts->get( $testModel );
86
87 $allowed = TRUE;
88 if( $conflicts ){
89 $isManager = FALSE;
90
91 $currentUser = $this->auth->getCurrentUser();
92 $currentUserId = $currentUser->getId();
93 if( $currentUserId ){
94 if( $this->permission->isAdmin($currentUser) ){
95 $isManager = TRUE;
96 }
97 else {
98 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
99 if( isset($calendarsAsManager[$calendarId]) ){
100 $isManager = TRUE;
101 }
102 }
103 }
104
105 if( ! $isManager ){
106 if( ! $this->calendarsPermissions->get($calendar, 'employee_create_own_conflicts') ){
107 $allowed = FALSE;
108 }
109 }
110 }
111
112 $to = $this->post->get( 'back' );
113 if( $to ){
114 $to = json_decode( $to, TRUE );
115 }
116 else {
117 $to = array( 'schedule', array() );
118 }
119
120 if( $allowed ){
121 $this->command->reschedule( $shift, $start, $end, $startBreak, $endBreak );
122 $msg = '__Shift Rescheduled__';
123 $return = array( $to, $msg );
124 }
125 else {
126 $msg = '__You cannot create new shifts with conflicts.__';
127 $return = array( $to, $msg, TRUE );
128 }
129
130 return $return;
131 }
132 }