protected function format_row_values($row_values)
 {
     $ci = get_instance();
     if (empty($this->columns) || empty($row_values)) {
         return false;
     }
     $row = array();
     $ci->load->helper('date');
     $ci->load->helper('constantfinder');
     foreach ($this->columns as $column_index => $column) {
         if (!$column->visible_in_outputtypes) {
             continue;
         }
         if (preg_match('/_datetime/', $column->get_aliased_field())) {
             $row[] = unix_to_human($row_values[$column_index], '%d/%m/%Y %h:%i%a');
         } else {
             if (preg_match('/_date$/', $column->get_aliased_field())) {
                 $row[] = unix_to_human($row_values[$column_index]);
             } else {
                 if ($column->constant_prefix) {
                     $row[] = get_lang_for_constant_value($column->constant_prefix, $row_values[$column_index]);
                 } else {
                     if (count($this->columns) != count($row_values)) {
                         throw new Exception('Error: mismatch of number of columns defined (' . count($this->columns) . ') and actual columns! (' . count($row_values) . ')');
                     }
                     if (is_null($row_values[$column_index])) {
                         $row_values[$column_index] = '';
                     }
                     $row[] = $row_values[$column_index];
                 }
             }
         }
     }
     return $row;
 }
Пример #2
0
 /**
  * Returns an array for the current model indexed by ID
  * @param string $name_field The field that will be used as the option labels
  * @param string $null_option If false or null, no null option. Otherwise uses the given string for null index
  * @param closure $label_function An optional function that can perform additional formatting on the label
  * @param string $optgroups If false, optgroups not used. If a string is given, the matching field from the DB table will be used to group items by category, ready to be used in HTML optgroups
  * @param string $optgroup_constant_prefix If the grouping variable is an int represented by a constant, this prefix will obtain the matching lang string
  * @return array
  */
 public function get_dropdown($name_field, $null_option = true, $label_function = false, $optgroups = false, $optgroup_constant_prefix = null, $null_value = null, $order_by = null, $where = null)
 {
     $options = array();
     if (!empty($where)) {
         $this->db->where($where);
     }
     if (!empty($null_option)) {
         if ($null_option === true) {
             $null_option = '-- Select One --';
         }
         $options[$null_value] = $null_option;
     }
     if (!empty($order_by)) {
         $this->db->order_by($order_by);
     }
     $this->db->select($this->table . '.*', false);
     $objects = $this->get();
     if (is_array($objects)) {
         foreach ($objects as $object) {
             $label = $label_function ? $label_function($object) : $object->{$name_field};
             if ($optgroups) {
                 $optgroup_label = empty($optgroup_constant_prefix) ? $object->{$optgroups} : ucfirst(get_lang_for_constant_value($optgroup_constant_prefix, $object->{$optgroups}));
                 if (empty($options[$optgroup_label])) {
                     $options[$optgroup_label] = array();
                 }
                 $options[$optgroup_label][$object->id] = $label;
             } else {
                 $options[$object->id] = $label;
             }
         }
     }
     return $options;
 }
Пример #3
0
 public function get_lang_for_constant_value($constant_prefix, $value)
 {
     echo get_lang_for_constant_value($constant_prefix, $value);
 }
Пример #4
0
 function delete_contact($contact_id)
 {
     if (!IS_AJAX) {
         show_error("This page can only be accessed through an AJAX request!");
         return false;
     }
     $contact = $this->user_contact_model->get($contact_id);
     $result = $this->user_contact_model->delete($contact_id);
     $data['message'] = 'The ' . get_lang_for_constant_value('USERS_CONTACT_TYPE_', $contact->type) . ' has been successfully deleted';
     $data['type'] = 'success';
     echo json_encode($data);
 }