예제 #1
0
 public function get_form_fields()
 {
     $return = parent::get_form_fields();
     /* remove archived users if any */
     $remove_users = array();
     $um = new User_Model();
     $um->select('id')->where('active', USER_MODEL::STATUS_ARCHIVE)->get();
     foreach ($um as $u) {
         $remove_users[] = $u->id;
     }
     if ($remove_users) {
         reset($remove_users);
         foreach ($remove_users as $rid) {
             unset($return['user']['options'][$rid]);
         }
     }
     /* adjust min and max time */
     $CI =& ci_get_instance();
     $time_min = $CI->app_conf->get('time_min');
     $time_max = $CI->app_conf->get('time_max');
     $time_min = $time_min ? $time_min : 0;
     $time_max = $time_max ? $time_max : 24 * 60 * 60;
     $return['start']['conf']['min'] = $time_min;
     $return['start']['conf']['max'] = $time_max;
     $return['end']['conf']['min'] = $time_min;
     $return['end']['conf']['max'] = $time_max;
     return $return;
 }
예제 #2
0
 function index()
 {
     $args = $this->parse_args(func_get_args());
     $display = isset($args['display']) ? $args['display'] : 'calendar';
     $filter = isset($args['filter']) ? $args['filter'] : 'all';
     $range = isset($args['range']) ? $args['range'] : 'week';
     // or month
     $date = isset($args['start']) ? $args['start'] : '';
     $end_date = isset($args['end']) ? $args['end'] : '';
     $this->data['id'] = isset($args['id']) ? $args['id'] : 0;
     /* check if schedule for this date exists */
     if ($end_date) {
         $start_date = $date;
         if ($end_date < $start_date) {
             $end_date = $start_date;
         }
     } else {
         if ($date) {
             $this->hc_time->setDateDb($date);
         } else {
             $this->hc_time->setNow();
         }
         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;
         }
     }
     $this->data['start_date'] = $start_date;
     $this->data['end_date'] = $end_date;
     $this->data['range'] = $range;
     /* working staff */
     $um = new User_Model();
     $this->data['working_staff'] = $um->get_staff();
     $lm = new Location_Model();
     $locations = $lm->get()->all;
     $this->data['locations'] = array();
     foreach ($locations as $loc) {
         $this->data['locations'][$loc->id] = $loc;
     }
     $this->data['display'] = $display;
     $this->data['filter'] = $filter;
     /* load shifts so that they can be reused in module displays to save queries */
     $filter_staff_id = $filter == 'staff' ? $this->data['id'] : 0;
     $this->_load_shifts(array($start_date, $end_date), $filter_staff_id);
     /* save view */
     $this->session->set_userdata(array('schedule_view' => $args));
     switch ($filter) {
         case 'location':
             if (isset($args['id']) && $args['id']) {
                 $location_id = $args['id'];
             } else {
                 $ids = array_keys($this->data['locations']);
                 $location_id = $ids[0];
             }
             $this->data['current_location'] = $this->data['locations'][$location_id];
             break;
         case 'staff':
             if (isset($args['id']) && $args['id']) {
                 $staff_id = $args['id'];
             } else {
                 $ids = array_keys($this->data['staffs']);
                 $staff_id = $ids[0];
             }
             $this->data['current_staff'] = $this->data['staffs'][$staff_id];
             break;
     }
     /* decide which view */
     switch ($display) {
         case 'calendar':
             switch ($filter) {
                 case 'location':
                     $view = 'index_location';
                     break;
                 case 'staff':
                     $view = 'index_staff';
                     break;
                 default:
                     $view = 'index';
                     break;
             }
             $view = 'index_calendar';
             break;
         case 'browse':
             $view = 'index_browse';
             break;
         case 'exportbrowse':
             return $this->export_browse();
             break;
         case 'exportstats':
         case 'stats':
             $stats_shifts = array();
             $stats_drafts = array();
             reset($this->data['staffs']);
             foreach ($this->data['staffs'] as $sta) {
                 if ($filter == 'staff') {
                     if ($sta->id != $this->data['current_staff']->id) {
                         continue;
                     }
                 }
                 $stats_shifts[$sta->id] = array(0, 0);
                 $stats_drafts[$sta->id] = array(0, 0);
             }
             reset($this->data['shifts']);
             foreach ($this->data['shifts'] as $sh) {
                 if (!$sh->user_id) {
                     continue;
                 }
                 if ($sh->date < $this->data['start_date']) {
                     continue;
                 }
                 if ($sh->date > $this->data['end_date']) {
                     continue;
                 }
                 if ($filter == 'location') {
                     if ($sh->location_id != $this->data['current_location']->id) {
                         continue;
                     }
                 }
                 if ($filter == 'staff') {
                     if ($sh->user_id != $this->data['current_staff']->id) {
                         continue;
                     }
                 }
                 if (!isset($stats_shifts[$sh->user_id])) {
                     continue;
                     //						$stats_shifts[$sh->user_id] = array( 0, 0 );
                     //						$stats_drafts[$sh->user_id] = array( 0, 0 );
                 }
                 if ($sh->status == SHIFT_MODEL::STATUS_ACTIVE) {
                     $stats_shifts[$sh->user_id][0] += 1;
                     $stats_shifts[$sh->user_id][1] += $sh->get_duration();
                 } else {
                     $stats_drafts[$sh->user_id][0] += 1;
                     $stats_drafts[$sh->user_id][1] += $sh->get_duration();
                 }
             }
             /* filter archived staff if they have no shifts */
             $archived_users = array();
             $um = new User_Model();
             $um->select('id')->where('active', USER_MODEL::STATUS_ARCHIVE)->get();
             foreach ($um as $u) {
                 $archived_users[] = $u->id;
             }
             if ($archived_users) {
                 $all_users = array_keys($stats_shifts);
                 foreach ($all_users as $uid) {
                     if (in_array($uid, $archived_users) && $stats_shifts[$uid][0] == 0 && $stats_drafts[$uid][0] == 0) {
                         unset($stats_shifts[$uid]);
                         unset($stats_drafts[$uid]);
                     }
                 }
             }
             $this->data['stats_shifts'] = $stats_shifts;
             $this->data['stats_drafts'] = $stats_drafts;
             /* sort by duration */
             uasort($this->data['stats_shifts'], create_function('$a, $b', 'return ($b[1] - $a[1]);'));
             if ($display == 'exportstats') {
                 return $this->export_stats();
             } else {
                 $view = 'index_stats';
             }
             break;
         default:
             $view = 'index_calendar';
             break;
     }
     $this->set_include($view);
     $this->load->view($this->template, $this->data);
     return;
 }