PluginProbe
ShiftController Employee Shift Scheduling / 2.1.2
ShiftController Employee Shift Scheduling v2.1.2
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 / application / modules / wall / controllers / wall.php

wall.php in ShiftController Employee Shift Scheduling 2.1.2, at application/modules/wall/controllers/wall.php

229 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3 class Wall_wall_controller extends Front_controller
4 {
5 function __construct()
6 {
7 $this->conf = array(
8 'path' => 'wall',
9 );
10 parent::__construct();
11 $this->load->library( 'hc_time' );
12
13 /* check user level */
14 $user_level = $this->app_conf->get('wall_schedule_display');
15 if( $user_level )
16 {
17 $this->check_level( $user_level );
18 }
19 }
20
21 private function _load_shifts( $date = 0, $staff_id = 0 )
22 {
23 if( $staff_id )
24 {
25 $um = new User_Model;
26 $um->get_by_id( $staff_id );
27 $shift_model = $um->shift;
28 $timeoff_model = $um->timeoff;
29 }
30 else
31 {
32 $shift_model = new Shift_Model;
33 $timeoff_model = new Timeoff_Model;
34 }
35
36 if( $date )
37 {
38 if( is_array($date) ) // to-from
39 {
40 $this->hc_time->setDateDb( $date[1] );
41 $this->hc_time->modify( '+1 day' );
42 $tomorrow = $this->hc_time->formatDate_Db();
43 $this->hc_time->setDateDb( $date[0] );
44 $this->hc_time->modify( '-1 day' );
45 $yesterday = $this->hc_time->formatDate_Db();
46 }
47 else
48 {
49 $this->hc_time->setDateDb( $date );
50 $this->hc_time->modify( '+1 day' );
51 $tomorrow = $this->hc_time->formatDate_Db();
52 $this->hc_time->setDateDb( $date );
53 $this->hc_time->modify( '-1 day' );
54 $yesterday = $this->hc_time->formatDate_Db();
55 }
56
57 $shift_model->where('date <=', $tomorrow);
58 $shift_model->where('date >=', $yesterday);
59
60 $timeoff_model->where('date <', $tomorrow);
61 $timeoff_model->where('date_end >', $yesterday);
62 }
63
64 $shift_model
65 ->include_related( 'location', 'show_order' )
66 ->include_related( 'location', 'id' )
67 ->include_related( 'location', 'name' )
68 ->include_related( 'user', 'id' )
69 ->order_by( 'date', 'ASC' )
70 ->order_by( 'start', 'ASC' )
71 ->order_by( 'location_show_order', 'ASC' );
72
73 $shift_model->where('user_id IS NOT ', 'NULL', FALSE);
74 $shift_model->where('status', SHIFT_MODEL::STATUS_ACTIVE);
75
76 $this->data['shifts'] = $shift_model
77 ->get()->all;
78
79 //$shift_model->check_last_query();
80
81 $this->data['timeoffs'] = $timeoff_model
82 ->where_in('status', array(TIMEOFF_MODEL::STATUS_ACTIVE))
83 ->include_related( 'user', 'id' )
84 ->order_by( 'date', 'ASC' )
85 ->order_by( 'start', 'ASC' )
86 ->get()->all;
87
88 /* load the shifts group ids count and dates*/
89 $groups = $shift_model
90 ->select( 'group_id, COUNT(id) AS count, MIN(date) AS min_date, MAX(date) AS max_date' )
91 ->group_by( 'group_id' )
92 ->get();
93
94 $this->data['shift_groups'] = array();
95 foreach( $groups as $g )
96 {
97 if( ! $g->group_id )
98 continue;
99 $this->data['shift_groups'][$g->group_id] = array(
100 'count' => $g->count,
101 'min_date' => $g->min_date,
102 'max_date' => $g->max_date,
103 );
104 }
105 }
106
107 function day( $date )
108 {
109 $this->data['display'] = 'all';
110 $sm = new Shift_Model;
111
112 /* load shifts if needed */
113 if( ! isset($this->data['shifts']) )
114 {
115 $this->_load_shifts( $date );
116 }
117
118 /* filter all shifts */
119 $this->data['my_shifts'] = array();
120 foreach( $this->data['shifts'] as $sh )
121 {
122 if( $sh->date > $date )
123 break;
124 if( $sh->date < $date )
125 continue;
126 $this->data['my_shifts'][] = $sh;
127 }
128
129 $um = new User_Model;
130 $staffs = $um->get()->all;
131 $this->data['staffs'] = array();
132 foreach( $staffs as $sta )
133 {
134 $this->data['staffs'][ $sta->id ] = $sta;
135 }
136
137 $this->data['date'] = $date;
138
139 $this->set_include( 'day' );
140 $this->load->view( $this->template, $this->data);
141 }
142
143 function browse()
144 {
145 $start = $this->input->post( 'start' );
146 $end = $this->input->post( 'end' );
147 $redirect_to = array( $this->conf['path'], 'index/browse', $start, $end );
148 $this->redirect( $redirect_to );
149 return;
150 }
151
152 function index( $date = '', $end_date = '' )
153 {
154 $display = 'all';
155 $range = 'month'; // may also be 'week'
156
157 /* check if schedule for this date exists */
158 if( $end_date )
159 {
160 $start_date = $date;
161 if( $end_date < $start_date )
162 $end_date = $start_date;
163 }
164 else
165 {
166 if( $date )
167 {
168 $this->hc_time->setDateDb( $date );
169 }
170 else
171 {
172 $this->hc_time->setNow();
173 }
174
175 // $this->hc_time->setStartWeek();
176 $this->hc_time->setStartMonth();
177 $start_date = $this->hc_time->formatDate_Db();
178 // $this->hc_time->setEndWeek();
179 $this->hc_time->setEndMonth();
180 $end_date = $this->hc_time->formatDate_Db();
181 }
182
183 $this->data['start_date'] = $start_date;
184 $this->data['end_date'] = $end_date;
185 $this->data['range'] = $range;
186
187 $um = new User_Model;
188 $staffs = $um
189 ->where('active', USER_MODEL::STATUS_ACTIVE)
190 ->get()->all;
191 $this->data['staffs'] = array();
192 foreach( $staffs as $sta )
193 {
194 $this->data['staffs'][ $sta->id ] = $sta;
195 }
196
197 /* decide which view */
198 switch( $display )
199 {
200 case 'all':
201 $view = 'index';
202 break;
203
204 case 'staff':
205 $view = 'index_staff';
206 break;
207
208 case 'browse':
209 $view = 'index_browse';
210 break;
211
212 default:
213 $view = 'index';
214 break;
215 }
216
217 $this->data['display'] = $display;
218
219 /* load shifts so that they can be reused in module displays to save queries */
220 $this->_load_shifts( array($start_date, $end_date) );
221
222 $this->set_include( $view );
223 $this->load->view( $this->template, $this->data);
224 return;
225 }
226 }
227
228 /* End of file customers.php */
229 /* Location: ./application/controllers/admin/categories.php */