function shifts() { if ($this->staff_id) { $um = new User_Model(); $um->get_by_id($this->staff_id); $sm = $um->shift; } elseif ($this->location_id) { $lm = new Location_Model(); $lm->get_by_id($this->location_id); $sm = $lm->shift; } else { $sm = new Shift_Model(); } if ($this->start) { $sm->where('date >=', $this->start); } if ($this->end) { $sm->where('date <=', $this->end); } $sm->order_by('date', 'ASC')->order_by('start', 'ASC')->include_related('user', 'id'); return $sm->get(); }
function status() { $args = hc_parse_args(func_get_args()); $count = array(); $this->data['location_id'] = 0; $this->data['staff_id'] = 0; if (isset($args['staff']) && $args['staff']) { $um = new User_Model(); $um->get_by_id($args['staff']); $sm = $um->shift; $this->data['staff_id'] = $args['staff']; } elseif (isset($args['location']) && $args['location']) { $lm = new Location_Model(); $lm->get_by_id($args['location']); $sm = $lm->shift; $this->data['location_id'] = $args['location']; } else { $sm = new Shift_Model(); } /* duration */ $sm->clear(); $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->select_sum('end')->select_sum('start')->get(); $count['duration'] = $sm->end - $sm->start; /* ACTIVE - published with staff */ $sm->clear(); $sm->include_related('user', 'id'); $count['active'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status', SHIFT_MODEL::STATUS_ACTIVE)->where('user_id IS NOT ', 'NULL', FALSE)->count(); /* OPEN - published with no staff */ $sm->clear(); $sm->include_related('user', 'id'); $count['open'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status', SHIFT_MODEL::STATUS_ACTIVE)->where('user_id IS ', 'NULL', FALSE)->count(); /* PENDING - not published with staff */ $sm->clear(); $count['pending'] = $sm->include_related('user', 'id')->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status <>', SHIFT_MODEL::STATUS_ACTIVE)->where('user_id IS NOT ', 'NULL', FALSE)->count(); /* DRAFT - not published with no staff */ $sm->clear(); $sm->include_related('user', 'id'); $count['draft'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->where('status <>', SHIFT_MODEL::STATUS_ACTIVE)->group_start()->or_where('user_id IS ', 'NULL', FALSE)->or_where('user_id', 0)->group_end()->count(); /* total */ $sm->clear(); $count['total'] = $sm->where('date >=', $args['start'])->where('date <=', $args['end'])->count(); $this->data['count'] = $count; $this->data['start_date'] = $args['start']; $this->data['end_date'] = $args['end']; $this->set_include('status'); $this->load->view($this->template, $this->data); }