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');
     }
 }
示例#2
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();
 }
示例#3
0
 function index()
 {
     $args = $this->parse_args(func_get_args());
     $args = array_merge($this->default_params, $args);
     $display = 'all';
     $location_id = array();
     $supplied_location_id = isset($args['location']) ? $args['location'] : '';
     if (strlen($supplied_location_id)) {
         if (strpos($supplied_location_id, ',') !== FALSE) {
             $location_id = explode(',', $supplied_location_id);
             array_walk($location_id, 'intval');
         } else {
             if ($location_id) {
                 $location_id = array($supplied_location_id);
             } else {
                 $location_id = $supplied_location_id;
             }
             // 0 for all
         }
     }
     $staff_id = array();
     $supplied_staff_id = isset($args['staff']) ? $args['staff'] : '';
     if ($supplied_staff_id) {
         if (strpos($supplied_staff_id, ',') !== FALSE) {
             $staff_id = explode(',', $supplied_staff_id);
             array_walk($staff_id, 'intval');
         } elseif ($supplied_staff_id == '_current_user_id_') {
             if ($this->auth && $this->auth->user()) {
                 $staff_id = array($this->auth->user()->id);
             }
         } else {
             $staff_id = array($supplied_staff_id);
         }
     }
     $within = FALSE;
     /* whithin now */
     if (isset($args['within'])) {
         $within = $args['within'];
         if (strlen($within)) {
             $within = urldecode($within);
         }
         $this->hc_time->setNow();
         $start_date = $this->hc_time->formatDate_Db();
         $within_from = $this->hc_time->getTimestamp();
         if ($within) {
             $this->hc_time->modify($within);
         }
         $end_date = $this->hc_time->formatDate_Db();
         $within_to = $this->hc_time->getTimestamp();
         $this->data['within_from'] = $within_from;
         $this->data['within_to'] = $within_to;
     } else {
         if (isset($args['start'])) {
             $start_date = $args['start'];
         } else {
             $start_date = $this->hc_time->setNow()->formatDate_Db();
         }
         if (isset($args['end'])) {
             $end_date = $args['end'];
         } else {
             $end_date = '';
         }
         $this->hc_time->setDateDb($start_date);
         $range = isset($args['range']) ? $args['range'] : '';
         if ($range) {
             switch ($range) {
                 case 'week':
                     $this->hc_time->setStartWeek();
                     $start_date = $this->hc_time->formatDate_Db();
                     $this->hc_time->setEndWeek();
                     $end_date = $this->hc_time->formatDate_Db();
                     break;
                 case 'month':
                     $this->hc_time->setStartMonth();
                     $start_date = $this->hc_time->formatDate_Db();
                     $this->hc_time->setEndMonth();
                     $end_date = $this->hc_time->formatDate_Db();
                     break;
                 default:
                     $this->hc_time->modify('+' . $range);
                     $this->hc_time->modify('-1 day');
                     $end_date = $this->hc_time->formatDate_Db();
                     break;
             }
         }
     }
     /* find dates that we have shifts */
     $shift_model = new Shift_Model();
     $shift_model->select('date');
     $shift_model->where('date >=', $start_date);
     if ($end_date) {
         $shift_model->where('date <=', $end_date);
     }
     $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();
     if ($location_id) {
         $shift_model->where_related('location', 'id', $location_id);
     }
     if ($staff_id) {
         $shift_model->where_related('user', 'id', $staff_id);
     }
     $shift_model->distinct();
     //		$shift_model->limit( 3 );
     $shift_model->order_by('date', 'ASC');
     $shift_model->order_by('start', 'ASC');
     $shift_model->get();
     //		$shift_model->check_last_query();
     //		exit;
     $dates = array();
     foreach ($shift_model as $s) {
         $dates[] = $s->date;
     }
     $this->data['dates'] = $dates;
     /* preload staff information */
     $um = new User_Model();
     $staffs = $um->get_staff();
     $this->data['staffs'] = array();
     foreach ($staffs as $sta) {
         $this->data['staffs'][$sta->id] = $sta;
     }
     /* preload location information */
     $lm = new Location_Model();
     $locations = $lm->get()->all;
     $this->data['locations'] = array();
     foreach ($locations as $loc) {
         $this->data['locations'][$loc->id] = $loc;
     }
     $this->data['location_id'] = $location_id;
     $this->data['display'] = $display;
     $this->data['within'] = $within;
     /* load shifts so that they can be reused in module displays to save queries */
     $this->_load_shifts($dates, $staff_id, $location_id, $within);
     $view = 'index';
     $this->set_include($view);
     $this->load->view($this->template, $this->data);
     return;
 }
示例#4
0
 function index()
 {
     $my_user_id = $this->auth->user()->id;
     $this->hc_time->setNow();
     $today = $this->hc_time->formatDate_Db();
     $args = $this->parse_args(func_get_args());
     $display = isset($args['display']) ? $args['display'] : 'my';
     if (isset($args['start'])) {
         $start_date = $args['start'];
     } else {
         // last month
         $this->hc_time->setNow();
         //			$this->hc_time->modify( '-1 month' );
         $this->hc_time->setStartMonth();
         $start_date = $this->hc_time->formatDate_Db();
     }
     if (isset($args['end'])) {
         $end_date = $args['end'];
     } else {
         // last month
         $this->hc_time->setNow();
         //			$this->hc_time->modify( '-1 month' );
         $this->hc_time->setEndMonth();
         $end_date = $this->hc_time->formatDate_Db();
     }
     $location_id = 0;
     switch ($display) {
         case 'list':
         case 'my':
             $sm = $this->auth->user()->shift;
             break;
         case 'pickup':
             $sm = new Shift_Model();
             if (isset($args['location'])) {
                 $location_id = $args['location'];
             }
             break;
     }
     $sm->include_related('location', 'show_order')->include_related('location', 'id')->include_related('location', 'name')->include_related('user', 'id')->where('status', SHIFT_MODEL::STATUS_ACTIVE)->order_by('date', 'ASC')->order_by('start', 'ASC')->order_by('location_show_order', 'ASC');
     if ($location_id) {
         $sm->where('location_id', $location_id);
     }
     switch ($display) {
         case 'pickup':
         case 'my':
             $sm->where('date >=', $today);
             break;
         case 'list':
             $sm->where('date >=', $start_date);
             $sm->where('date <=', $end_date);
             break;
     }
     switch ($display) {
         case 'pickup':
             $sm->include_related('user', 'id')->group_start()->or_group_start()->where('user_id <> ', $my_user_id)->where('has_trade <>', 0)->group_end();
             $staff_can_pickup = $this->app_conf->get('staff_pick_shifts');
             if ($staff_can_pickup) {
                 $sm->or_group_start()->or_where('user_id IS ', 'NULL', FALSE)->or_where('user_id', 0)->group_end();
             }
             $sm->group_end();
             break;
     }
     $this->data['shifts'] = $sm->get()->all;
     // timeoffs
     $this->data['timeoffs'] = $this->auth->user()->timeoff->where('date_end >=', $today)->where('status', TIMEOFF_MODEL::STATUS_ACTIVE)->order_by('date', 'ASC')->get()->all;
     $this->data['display'] = $display;
     // view file
     switch ($display) {
         case 'pickup':
         case 'my':
             $view_file = 'index';
             break;
         case 'list':
             $view_file = 'index_browse';
             break;
     }
     $this->data['start_date'] = $start_date;
     $this->data['end_date'] = $end_date;
     $this->data['location_id'] = $location_id;
     $lm = new Location_Model();
     $locations = $lm->get()->all;
     $this->data['locations'] = array();
     foreach ($locations as $loc) {
         $this->data['locations'][$loc->id] = $loc;
     }
     $this->set_include($view_file);
     $this->load->view($this->template, $this->data);
 }
示例#5
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);
 }