function time_verbose($time, $include_seconds = FALSE) { if (is_date_format($time)) { $time = strtotime($time); } if (is_int($time)) { $time = date('H:i:s', $time); } $hms = explode(':', $time); if (empty($hms)) { return $time; } $h = (int) $hms[0]; $m = !empty($hms[1]) ? (int) $hms[1] : 0; $s = !empty($hms[2]) ? (int) $hms[2] : 0; $new_time = ''; if ($h != 0) { $new_time .= $h . 'hrs '; } if ($m != 0) { $new_time .= $m . 'mins '; } if ($include_seconds and $s != 0) { $new_time .= $s . 'secs'; } return $new_time; }
/** * Processes the list view filters and returns an array of parameters * * @access protected * @return array */ protected function _list_process() { $this->load->library('pagination'); $this->load->helper('convert'); $this->load->helper('cookie'); /* PROCESS PARAMS BEGIN */ $filters = array(); $page_state = $this->fuel->admin->get_page_state($this->module_uri); unset($page_state['offset']); $defaults = array(); $defaults['col'] = !empty($this->default_col) ? $this->default_col : $this->display_field; $defaults['order'] = !empty($this->default_order) ? $this->default_order : 'asc'; $defaults['offset'] = 0; $defaults['limit'] = key($this->limit_options); $defaults['search_term'] = ''; $defaults['view_type'] = 'list'; $defaults['extra_filters'] = array(); $defaults['precedence'] = 0; //$defaults['language'] = ''; // custom module filters defaults foreach ($this->filters as $key => $val) { $defaults[$key] = isset($val['default']) ? $val['default'] : NULL; } $posted = array(); if (!empty($_POST) or !empty($_GET)) { $posted['search_term'] = $this->input->get_post('search_term', TRUE); $posted_vars = array('col', 'order', 'limit', 'offset', 'precedence', 'view_type'); foreach ($posted_vars as $val) { if ($this->input->get_post($val)) { $posted[$val] = $this->input->get_post($val, TRUE); } } // custom module filters $extra_filters = array(); foreach ($this->filters as $key => $val) { if (isset($_POST[$key]) or isset($_GET[$key])) { $posted[$key] = $this->input->get_post($key, TRUE); // get the raw key without the comparison operators that the model uses $raw_key = preg_replace(array('#_from$#', '#_fromequal$#', '#_to$#', '#_toequal$#', '#_equal$#'), '', $key); // manipulate the value if it's a date time field if (method_exists($this->model, 'field_type')) { $field_type = $this->model->field_type($raw_key); if (is_date_format($posted[$key]) and $field_type == 'datetime' or $field_type == 'date' and (int) $posted[$key] !== 0) { $date = ($this->input->get_post($key) and is_date_format($this->input->get_post($key))) ? current(explode(" ", $this->input->get_post($key))) : ""; $hr = ($this->input->get_post($key . '_hour') and (int) $this->input->get_post($key . '_hour') > 0 and (int) $this->input->get_post($key . '_hour') < 24) ? $this->input->get_post($key . '_hour') : ""; $min = ($this->input->get_post($key . '_min') and is_numeric($this->input->get_post($key . '_min'))) ? $this->input->get_post($key . '_min') : "00"; $ampm = ($this->input->get_post($key . '_am_pm') and $hr and $min) ? $this->input->get_post($key . '_am_pm') : ""; if (!empty($ampm) and !empty($hr) and $hr > 12) { if ($hr > 24) { $hr = "00"; } else { $hr = (int) $hr - 12; $ampm = "pm"; } } $posted[$key] = $date; if (!empty($hr)) { $posted[$key] .= " " . $hr . ":" . $min . $ampm; } $posted[$key] = date('Y-m-d H:i:s', strtotime($posted[$key])); } } $this->filters[$key]['value'] = $posted[$key]; $extra_filters[$key] = $posted[$key]; } } $posted['extra_filters'] = $extra_filters; } $params = array_merge($defaults, $page_state, $posted); //$params = array_merge($defaults, $uri_params, $posted); if ($params['search_term'] == lang('label_search')) { $params['search_term'] = NULL; } /* PROCESS PARAMS END */ return $params; }
/** * Retrieves an archived value * * @access public * @param int The record ID associated with the archive * @param int The version of the archive to retrieve (optional) * @param boolean Determines whether to return all of the archives fields or just the data field value (optional) * @return array */ public function get_archive($ref_id, $version = NULL, $all_data = FALSE) { $CI =& get_instance(); $CI->load->module_model(FUEL_FOLDER, 'fuel_archives_model'); $CI->load->helper('date'); // best to use ref_id and version because it is more secure $where = array('table_name' => $this->table_name, 'ref_id' => $ref_id, 'version' => $version); $archive = $CI->fuel_archives_model->find_one_array($where); $return = $archive; $return['data'] = array(); if (!empty($archive)) { // check for serialization for backwards compatibility $data = is_serialized_str($archive['data']) ? @unserialize($archive['data']) : json_decode($archive['data'], TRUE); if (!empty($data) and is_array($data)) { foreach ($data as $key => $val) { // reformat dates if (is_date_format($val)) { $date_ts = strtotime($val); $return['data'][$key] = english_date($val); $return['data'][$key . '_hour'] = date('h', $date_ts); $return['data'][$key . '_min'] = date('i', $date_ts); $return['data'][$key . '_ampm'] = date('a', $date_ts); } else { $return['data'][$key] = $val; } } } } return $all_data ? $return : $return['data']; }
/** * Retrieves an archived value * * @access public * @param string * @param int * @param boolean * @return array */ function get_archive($ref_id, $version = NULL, $all_data = FALSE) { $CI =& get_instance(); $CI->load->module_model(FUEL_FOLDER, 'archives_model'); $CI->load->helper('date'); // best to use ref_id and version because it is more secure $where = array('table_name' => $this->table_name, 'ref_id' => $ref_id, 'version' => $version); $archive = $CI->archives_model->find_one_array($where); $return = $archive; $return['data'] = array(); if (!empty($archive)) { $data = unserialize($archive['data']); foreach($data as $key => $val) { // reformat dates if (is_date_format($val)) { $date_ts = strtotime($val); $return['data'][$key] = english_date($val); $return['data'][$key.'_hour'] = date('h', $date_ts); $return['data'][$key.'_min'] = date('i', $date_ts); $return['data'][$key.'_ampm'] = date('a', $date_ts); } else { $return['data'][$key] = $val; } } } return ($all_data) ? $return : $return['data']; }