コード例 #1
0
ファイル: shifts.php プロジェクト: RVRKC/Hackathon_2015
 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);
 }
コード例 #2
0
ファイル: wall.php プロジェクト: RVRKC/Hackathon_2015
 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);
     }
 }
コード例 #3
0
ファイル: schedules.php プロジェクト: RVRKC/Hackathon_2015
 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);
 }