| 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 |
/* check how many locations do we have */ |
| 21 |
$lm = new Location_Model; |
| 22 |
$location_count = $lm->count(); |
| 23 |
$this->data['location_count'] = $location_count; |
| 24 |
} |
| 25 |
|
| 26 |
private function _load_shifts( $date = 0, $staff_id = 0 ) |
| 27 |
{ |
| 28 |
if( $staff_id ) |
| 29 |
{ |
| 30 |
$um = new User_Model; |
| 31 |
$um->get_by_id( $staff_id ); |
| 32 |
$shift_model = $um->shift; |
| 33 |
$timeoff_model = $um->timeoff; |
| 34 |
} |
| 35 |
else |
| 36 |
{ |
| 37 |
$shift_model = new Shift_Model; |
| 38 |
$timeoff_model = new Timeoff_Model; |
| 39 |
} |
| 40 |
|
| 41 |
if( $date ) |
| 42 |
{ |
| 43 |
if( is_array($date) ) // to-from |
| 44 |
{ |
| 45 |
$this->hc_time->setDateDb( $date[1] ); |
| 46 |
$this->hc_time->modify( '+1 day' ); |
| 47 |
$tomorrow = $this->hc_time->formatDate_Db(); |
| 48 |
$this->hc_time->setDateDb( $date[0] ); |
| 49 |
$this->hc_time->modify( '-1 day' ); |
| 50 |
$yesterday = $this->hc_time->formatDate_Db(); |
| 51 |
} |
| 52 |
else |
| 53 |
{ |
| 54 |
$this->hc_time->setDateDb( $date ); |
| 55 |
$this->hc_time->modify( '+1 day' ); |
| 56 |
$tomorrow = $this->hc_time->formatDate_Db(); |
| 57 |
$this->hc_time->setDateDb( $date ); |
| 58 |
$this->hc_time->modify( '-1 day' ); |
| 59 |
$yesterday = $this->hc_time->formatDate_Db(); |
| 60 |
} |
| 61 |
|
| 62 |
$shift_model->where('date <=', $tomorrow); |
| 63 |
$shift_model->where('date >=', $yesterday); |
| 64 |
|
| 65 |
$timeoff_model->where('date <', $tomorrow); |
| 66 |
$timeoff_model->where('date_end >', $yesterday); |
| 67 |
} |
| 68 |
|
| 69 |
$shift_model |
| 70 |
->include_related( 'location', 'show_order' ) |
| 71 |
->include_related( 'location', 'id' ) |
| 72 |
->include_related( 'location', 'name' ) |
| 73 |
->include_related( 'user', 'id' ) |
| 74 |
->order_by( 'date', 'ASC' ) |
| 75 |
->order_by( 'start', 'ASC' ) |
| 76 |
->order_by( 'location_show_order', 'ASC' ); |
| 77 |
|
| 78 |
$shift_model->group_start(); |
| 79 |
$shift_model->where('status', SHIFT_MODEL::STATUS_ACTIVE); |
| 80 |
if( |
| 81 |
$this->auth->check() && |
| 82 |
$this->app_conf->get('staff_pick_shifts') |
| 83 |
) |
| 84 |
{ |
| 85 |
$shift_model->or_where('user_id IS ', 'NULL', FALSE); |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
$shift_model->where('user_id IS NOT ', 'NULL', FALSE); |
| 90 |
} |
| 91 |
$shift_model->group_end(); |
| 92 |
|
| 93 |
$this->data['shifts'] = $shift_model |
| 94 |
->get()->all; |
| 95 |
|
| 96 |
//$shift_model->check_last_query(); |
| 97 |
|
| 98 |
$this->data['timeoffs'] = $timeoff_model |
| 99 |
->where_in('status', array(TIMEOFF_MODEL::STATUS_ACTIVE)) |
| 100 |
->include_related( 'user', 'id' ) |
| 101 |
->order_by( 'date', 'ASC' ) |
| 102 |
->order_by( 'start', 'ASC' ) |
| 103 |
->get()->all; |
| 104 |
|
| 105 |
/* load the shifts group ids count and dates*/ |
| 106 |
$groups = $shift_model |
| 107 |
->select( 'group_id, COUNT(id) AS count, MIN(date) AS min_date, MAX(date) AS max_date' ) |
| 108 |
->group_by( 'group_id' ) |
| 109 |
->get(); |
| 110 |
|
| 111 |
$this->data['shift_groups'] = array(); |
| 112 |
foreach( $groups as $g ) |
| 113 |
{ |
| 114 |
if( ! $g->group_id ) |
| 115 |
continue; |
| 116 |
$this->data['shift_groups'][$g->group_id] = array( |
| 117 |
'count' => $g->count, |
| 118 |
'min_date' => $g->min_date, |
| 119 |
'max_date' => $g->max_date, |
| 120 |
); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
function day( $date ) |
| 125 |
{ |
| 126 |
$args = $this->parse_args( func_get_args() ); |
| 127 |
$range = isset($args['range']) ? $args['range'] : 'week'; // or month |
| 128 |
|
| 129 |
$this->data['range'] = $range; |
| 130 |
|
| 131 |
$this->data['display'] = 'all'; |
| 132 |
$sm = new Shift_Model; |
| 133 |
|
| 134 |
/* load shifts if needed */ |
| 135 |
if( ! isset($this->data['shifts']) ) |
| 136 |
{ |
| 137 |
$this->_load_shifts( $date ); |
| 138 |
} |
| 139 |
|
| 140 |
/* filter all shifts */ |
| 141 |
$this->data['my_shifts'] = array(); |
| 142 |
foreach( $this->data['shifts'] as $sh ) |
| 143 |
{ |
| 144 |
if( $sh->date > $date ) |
| 145 |
break; |
| 146 |
if( $sh->date < $date ) |
| 147 |
continue; |
| 148 |
$this->data['my_shifts'][] = $sh; |
| 149 |
} |
| 150 |
|
| 151 |
$um = new User_Model; |
| 152 |
$staffs = $um->get()->all; |
| 153 |
$this->data['staffs'] = array(); |
| 154 |
foreach( $staffs as $sta ) |
| 155 |
{ |
| 156 |
$this->data['staffs'][ $sta->id ] = $sta; |
| 157 |
} |
| 158 |
|
| 159 |
$this->data['date'] = $date; |
| 160 |
|
| 161 |
$this->set_include( 'day' ); |
| 162 |
$this->load->view( $this->template, $this->data); |
| 163 |
} |
| 164 |
|
| 165 |
function browse() |
| 166 |
{ |
| 167 |
$start = $this->input->post( 'start' ); |
| 168 |
$end = $this->input->post( 'end' ); |
| 169 |
$redirect_to = array( $this->conf['path'], 'index/browse', $start, $end ); |
| 170 |
$this->redirect( $redirect_to ); |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
function index() |
| 175 |
{ |
| 176 |
$args = $this->parse_args( func_get_args() ); |
| 177 |
|
| 178 |
$display = 'all'; |
| 179 |
$range = isset($args['range']) ? $args['range'] : 'week'; // or month |
| 180 |
$date = isset($args['start']) ? $args['start'] : ''; |
| 181 |
$end_date = ''; |
| 182 |
|
| 183 |
/* check if schedule for this date exists */ |
| 184 |
if( $end_date ) |
| 185 |
{ |
| 186 |
$start_date = $date; |
| 187 |
if( $end_date < $start_date ) |
| 188 |
$end_date = $start_date; |
| 189 |
} |
| 190 |
else |
| 191 |
{ |
| 192 |
if( $date ) |
| 193 |
{ |
| 194 |
$this->hc_time->setDateDb( $date ); |
| 195 |
} |
| 196 |
else |
| 197 |
{ |
| 198 |
$this->hc_time->setNow(); |
| 199 |
} |
| 200 |
|
| 201 |
switch( $range ) |
| 202 |
{ |
| 203 |
case 'week': |
| 204 |
$this->hc_time->setStartWeek(); |
| 205 |
$start_date = $this->hc_time->formatDate_Db(); |
| 206 |
$this->hc_time->setEndWeek(); |
| 207 |
$end_date = $this->hc_time->formatDate_Db(); |
| 208 |
break; |
| 209 |
|
| 210 |
case 'month': |
| 211 |
$this->hc_time->setStartMonth(); |
| 212 |
$start_date = $this->hc_time->formatDate_Db(); |
| 213 |
$this->hc_time->setEndMonth(); |
| 214 |
$end_date = $this->hc_time->formatDate_Db(); |
| 215 |
break; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
$this->data['start_date'] = $start_date; |
| 220 |
$this->data['end_date'] = $end_date; |
| 221 |
$this->data['range'] = $range; |
| 222 |
|
| 223 |
$um = new User_Model; |
| 224 |
$staffs = $um->get_staff(); |
| 225 |
$this->data['staffs'] = array(); |
| 226 |
foreach( $staffs as $sta ) |
| 227 |
{ |
| 228 |
$this->data['staffs'][ $sta->id ] = $sta; |
| 229 |
} |
| 230 |
|
| 231 |
/* decide which view */ |
| 232 |
switch( $display ) |
| 233 |
{ |
| 234 |
case 'all': |
| 235 |
$view = 'index'; |
| 236 |
break; |
| 237 |
|
| 238 |
case 'staff': |
| 239 |
$view = 'index_staff'; |
| 240 |
break; |
| 241 |
|
| 242 |
case 'browse': |
| 243 |
$view = 'index_browse'; |
| 244 |
break; |
| 245 |
|
| 246 |
default: |
| 247 |
$view = 'index'; |
| 248 |
break; |
| 249 |
} |
| 250 |
|
| 251 |
$this->data['display'] = $display; |
| 252 |
|
| 253 |
/* load shifts so that they can be reused in module displays to save queries */ |
| 254 |
$this->_load_shifts( array($start_date, $end_date) ); |
| 255 |
|
| 256 |
$this->set_include( $view ); |
| 257 |
$this->load->view( $this->template, $this->data); |
| 258 |
return; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
/* End of file customers.php */ |
| 263 |
/* Location: ./application/controllers/admin/categories.php */ |