예제 #1
0
 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);
 }
예제 #2
0
 public function up()
 {
     /* remove trades table and set the trade column for shifts for pending trades */
     if (!$this->db->field_exists('has_trade', 'shifts')) {
         $this->dbforge->add_column('shifts', array('has_trade' => array('type' => 'TINYINT', 'null' => FALSE, 'default' => 0)));
     }
     if ($this->db->table_exists('trades')) {
         // TRADE_MODEL:STATUS_PENDING - set the trade column
         $this->db->where('status', 1);
         $this->db->select('shift_id');
         $query = $this->db->get('trades');
         foreach ($query->result_array() as $row) {
             $sm = new Shift_Model();
             $sm->get_by_id($row['shift_id']);
             $sm->has_trade = 1;
             $sm->save();
         }
         // TRADE_MODEL:STATUS_APPROVED - remove current user
         $this->db->where('status', 2);
         $this->db->select('shift_id');
         $query = $this->db->get('trades');
         foreach ($query->result_array() as $row) {
             $sm = new Shift_Model();
             $sm->get_by_id($row['shift_id']);
             $sm->user->get();
             $sm->delete($sm->user, 'user');
             $sm->save();
         }
         // TRADE_MODEL:STATUS_ACCEPTED - switch the shift to the new user
         $this->db->where('status', 3);
         $this->db->select(array('shift_id', 'to_user_id'));
         $query = $this->db->get('trades');
         foreach ($query->result_array() as $row) {
             $sm = new Shift_Model();
             $sm->get_by_id($row['shift_id']);
             $um = new User_Model();
             $um->get_by_id($row['to_user_id']);
             $sm->save(array('user' => $um));
         }
         // TRADE_MODEL:STATUS_DENIED - DO NOTHING
         //			$this->db->where('status', 4);
         // TRADE_MODEL:STATUS_COMPLETED - DO NOTHING
         //			$this->db->where('status', 5);
     }
     /* now delete the trades table */
     if ($this->db->table_exists('trades')) {
         $this->dbforge->drop_table('trades');
     }
 }
예제 #3
0
 function index($user_id = 0)
 {
     /* load */
     $this->{$this->model}->include_related('user', 'email')->include_related('user', 'first_name')->include_related('user', 'last_name');
     if ($user_id) {
         $this->{$this->model}->where_related('user', 'id', $user_id);
         $user = new User_Model();
         $user->get_by_id($user_id);
         $this->data['object'] = $user;
     }
     $this->data['user_id'] = $user_id;
     $this->data['entries'] = $this->{$this->model}->get()->all;
     if ($user_id) {
         $this->inherit_views('admin/users/edit');
     }
     $this->set_include('loginlog');
     $this->load->view($this->template, $this->data);
 }
예제 #4
0
 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();
 }
예제 #5
0
 private function _load_shifts($dates = array(), $staff_id = array(), $location_id = array(), $within = FALSE)
 {
     if ($staff_id && count($staff_id) == 1) {
         $um = new User_Model();
         $um->get_by_id($staff_id[0]);
         $shift_model = $um->shift;
         $timeoff_model = $um->timeoff;
     } else {
         $shift_model = new Shift_Model();
         $timeoff_model = new Timeoff_Model();
     }
     if ($dates) {
         $shift_model->where_in('date', $dates);
     }
     $shift_model->include_related('location', 'show_order')->include_related('location', 'id')->include_related('location', 'name')->include_related('user', 'id')->order_by('date', 'ASC')->order_by('start', 'ASC')->order_by('location_show_order', 'ASC');
     if ($location_id) {
         $shift_model->where_related('location', 'id', $location_id);
     }
     $shift_model->group_start();
     $shift_model->where('status', SHIFT_MODEL::STATUS_ACTIVE);
     if ($this->auth->check() && $this->app_conf->get('staff_pick_shifts')) {
         //				$shift_model->or_where('user_id IS ', 'NULL', FALSE);
     } else {
         $shift_model->where('user_id IS NOT ', 'NULL', FALSE);
     }
     $shift_model->group_end();
     $this->data['shifts'] = $shift_model->get()->all;
     if ($within !== FALSE) {
         $ok_shifts = array();
         if ($dates) {
             $day_starts = array();
             reset($dates);
             foreach ($dates as $d) {
                 $this->hc_time->setDateDb($d);
                 $day_starts[$d] = $this->hc_time->getStartDay();
             }
         }
         $now = time();
         $time_from = $now;
         $this->hc_time->setTimestamp($time_from);
         if (strlen($within) && $within) {
             $this->hc_time->modify('+ ' . $within);
         }
         $time_to = $this->hc_time->getTimestamp();
         foreach ($this->data['shifts'] as $sh) {
             if (!isset($day_starts[$sh->date])) {
                 $this->hc_time->setDateDb($sh->date);
                 $day_starts[$sh->date] = $this->hc_time->getStartDay();
             }
             $shift_start = $day_starts[$sh->date] + $sh->start;
             $shift_end = $day_starts[$sh->date] + $sh->end;
             $shift_ok = FALSE;
             if ($shift_end > $time_from && $shift_start < $time_to) {
                 $shift_ok = TRUE;
             }
             if ($shift_ok) {
                 $ok_shifts[] = $sh;
             }
         }
         $this->data['shifts'] = $ok_shifts;
     }
     $this->data['timeoffs'] = $timeoff_model->where_in('status', array(TIMEOFF_MODEL::STATUS_ACTIVE))->include_related('user', 'id')->order_by('date', 'ASC')->order_by('start', 'ASC')->get()->all;
     /* load the shifts group ids count and dates*/
     $groups = $shift_model->select('group_id, COUNT(id) AS count, MIN(date) AS min_date, MAX(date) AS max_date')->group_by('group_id')->get();
     $this->data['shift_groups'] = array();
     foreach ($groups as $g) {
         if (!$g->group_id) {
             continue;
         }
         $this->data['shift_groups'][$g->group_id] = array('count' => $g->count, 'min_date' => $g->min_date, 'max_date' => $g->max_date);
     }
 }
예제 #6
0
}
if ($default_user_id) {
    $this->hc_form->set_default('assign', 'now');
}
?>

<?php 
echo $this->hc_form->input(array('name' => 'assign', 'type' => 'hidden'));
?>

<?php 
if ($default_user_id && !is_array($default_user_id)) {
    ?>
	<?php 
    $default_user = new User_Model();
    $default_user->get_by_id($default_user_id);
    $fields['user']['type'] = 'hidden';
    ?>
	<?php 
    echo $this->hc_form->input($fields['user']);
    echo Hc_html::wrap_input(lang('user_level_staff'), $default_user->title(TRUE));
} else {
    ?>
	<?php 
    $default_assign = $this->hc_form->get_default('assign');
    echo Hc_html::wrap_input($fields['user']['label'], array('', Hc_bootstrap::nav_tabs(array('later' => lang('common_select_later'), 'now' => lang('common_select_now')), $default_assign, 'assign', '', 'style="margin: 0 0;"')));
    ?>

	<?php 
    unset($fields['user']['options'][0]);
    $fields['user']['extra']['multiple'] = 'multiple';
예제 #7
0
 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);
         }
     }
 }
예제 #8
0
 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);
 }