function staff($id, $display = 'week') { $um = new User_Model(); $um->get_by_id($id); if (!$um->exists()) { return; } $this->data['object'] = $um; $um->shift->where('status', SHIFT_MODEL::STATUS_ACTIVE); /* find min and max date */ $max_date = $um->shift->select_max('date')->get()->date; $min_date = $um->shift->select_min('date')->get()->date; $shifts = $um->shift->get_iterated(); /* compile dates */ $dates = array(); $date = $min_date; $this->hc_time->setDateDb($date); switch ($display) { case 'week': $this->hc_time->setStartWeek(); break; case 'month': $this->hc_time->setStartMonth(); break; } $date = $this->hc_time->formatDate_Db(); while ($date <= $max_date) { switch ($display) { case 'week': $start = $this->hc_time->formatDate_Db(); $this->hc_time->setEndWeek(); $end = $this->hc_time->formatDate_Db(); break; case 'month': $start = $this->hc_time->formatDate_Db(); $this->hc_time->setEndMonth(); $end = $this->hc_time->formatDate_Db(); break; } $dates[$start . '-' . $end] = array('shift_count' => 0, 'shift_duration' => 0, 'timeoff_count' => 0, 'timeoff_duration' => 0); $this->hc_time->modify('+1 day'); $date = $this->hc_time->formatDate_Db(); } foreach ($shifts as $sh) { reset($dates); foreach (array_keys($dates) as $dk) { list($start, $end) = explode('-', $dk); if ($sh->date >= $start && $sh->date <= $end) { $dates[$dk]['shift_count']++; $dates[$dk]['shift_duration'] += $sh->get_duration(); } } } $this->data['dates'] = $dates; $this->data['display'] = $display; // $this->conf['path'] = 'admin/users'; $this->set_include('edit/stats', 'admin/users'); $this->load->view($this->template, $this->data); }
private function _notify($shift, $reason) { $CI =& ci_get_instance(); $text = $shift->view_text(array('user')); $changes = $shift->get_changes(); $staff = $shift->user->get(); $msgs = array(); switch ($reason) { case 'new': if ($staff->exists()) { $msgs['shifts_published'] = array($staff); } break; case 'staff_change': $old_staff = new User_Model(); $old_staff->get_by_id($changes['user_id']); if ($old_staff->exists()) { $msgs['shifts_cancelled'] = array($old_staff); } if ($staff->exists()) { $msgs['shifts_published'] = array($staff); } break; case 'change': if ($staff->exists()) { $msgs['shifts_changed'] = array($staff); } break; } foreach ($msgs as $key => $staffs) { /* compile message */ $msg = new stdClass(); $msg->body = array(); foreach ($text as $ta) { $msg->body[] = $ta[0] . ': ' . $ta[1]; } $msg->subject = lang($key); $msg_id = $CI->hc_notifier->add_message($msg); foreach ($staffs as $staff) { $CI->hc_notifier->enqueue_message($msg_id, $staff, $key); } } }