PluginProbe
ShiftController Employee Shift Scheduling / 2.1.0
ShiftController Employee Shift Scheduling v2.1.0
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.0, at application/modules/wall/controllers/wall.php

223 lines 5.0 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 /* check if schedule for this date exists */
156 if( $end_date )
157 {
158 $start_date = $date;
159 if( $end_date < $start_date )
160 $end_date = $start_date;
161 }
162 else
163 {
164 if( $date )
165 {
166 $this->hc_time->setDateDb( $date );
167 }
168 else
169 {
170 $this->hc_time->setNow();
171 }
172 $this->hc_time->setStartWeek();
173 $start_date = $this->hc_time->formatDate_Db();
174 $this->hc_time->setEndWeek();
175 $end_date = $this->hc_time->formatDate_Db();
176 }
177
178 $this->data['start_date'] = $start_date;
179 $this->data['end_date'] = $end_date;
180
181 $um = new User_Model;
182 $staffs = $um
183 ->where('active', USER_MODEL::STATUS_ACTIVE)
184 ->get()->all;
185 $this->data['staffs'] = array();
186 foreach( $staffs as $sta )
187 {
188 $this->data['staffs'][ $sta->id ] = $sta;
189 }
190
191 /* decide which view */
192 switch( $display )
193 {
194 case 'all':
195 $view = 'index';
196 break;
197
198 case 'staff':
199 $view = 'index_staff';
200 break;
201
202 case 'browse':
203 $view = 'index_browse';
204 break;
205
206 default:
207 $view = 'index';
208 break;
209 }
210
211 $this->data['display'] = $display;
212
213 /* load shifts so that they can be reused in module displays to save queries */
214 $this->_load_shifts( array($start_date, $end_date) );
215
216 $this->set_include( $view );
217 $this->load->view( $this->template, $this->data);
218 return;
219 }
220 }
221
222 /* End of file customers.php */
223 /* Location: ./application/controllers/admin/categories.php */