diff --git a/application/libraries/Grocery_CRUD.php b/application/libraries/Grocery_CRUD.php index b5f2de79..d32f5cab 100755 --- a/application/libraries/Grocery_CRUD.php +++ b/application/libraries/Grocery_CRUD.php @@ -1838,7 +1838,7 @@ protected function showReadForm($state_info) $data->input_fields = $this->get_read_input_fields($data->field_values); $data->unique_hash = $this->get_method_hash(); - $data->fields = $this->get_edit_fields(); + $data->fields = $this->get_read_fields(); $data->hidden_fields = $this->get_edit_hidden_fields(); $data->unset_back_to_list = $this->unset_back_to_list; @@ -2736,11 +2736,13 @@ protected function get_edit_input_fields($field_values = null) protected function get_read_input_fields($field_values = null) { - $fields = $this->get_edit_fields(); + $read_fields = $this->get_read_fields(); + $this->field_types = null; $this->required_fields = null; - foreach ($fields as $field) { + $read_inputs = array(); + foreach ($read_fields as $field) { if (!empty($this->change_field_type) && isset($this->change_field_type[$field->field_name]) && $this->change_field_type[$field->field_name]->type == 'hidden') { @@ -2749,7 +2751,45 @@ protected function get_read_input_fields($field_values = null) $this->field_type($field->field_name, 'readonly'); } - return $this->get_edit_input_fields($field_values); + $fields = $this->get_read_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + if(!isset($this->callback_read_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $primary_key = $this->getStateInfo()->primary_key; + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + case 'hidden': + $this->read_hidden_fields[] = $field_input; + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + } + + $input_fields[$field->field_name] = $field_input; + } + + return $input_fields; } protected function setThemeBasics() @@ -3325,6 +3365,7 @@ class Grocery_CRUD extends grocery_CRUD_States private $columns_checked = false; private $add_fields_checked = false; private $edit_fields_checked = false; + private $read_fields_checked = false; protected $default_theme = 'flexigrid'; protected $language = null; @@ -3337,6 +3378,7 @@ class Grocery_CRUD extends grocery_CRUD_States protected $add_fields = null; protected $edit_fields = null; + protected $read_fields = null; protected $add_hidden_fields = array(); protected $edit_hidden_fields = array(); protected $field_types = null; @@ -3381,6 +3423,7 @@ class Grocery_CRUD extends grocery_CRUD_States protected $unset_columns = null; protected $unset_add_fields = null; protected $unset_edit_fields = null; + protected $unset_read_fields = null; /* Callbacks */ protected $callback_before_insert = null; @@ -3701,6 +3744,7 @@ public function unset_fields() $this->unset_add_fields = $args; $this->unset_edit_fields = $args; + $this->unset_read_fields = $args; return $this; } @@ -3733,6 +3777,20 @@ public function unset_edit_fields() return $this; } + public function unset_read_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_read_fields = $args; + + return $this; + } + /** * Unsets everything that has to do with buttons or links with go back to list message @@ -3806,6 +3864,19 @@ public function edit_fields() return $this; } + public function set_read_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) { + $args = $args[0]; + } + + $this->read_fields = $args; + + return $this; + } + /** * * Changes the displaying label of the field @@ -4105,6 +4176,49 @@ protected function get_edit_fields() return $this->edit_fields; } + /** + * + * Enter description here ... + */ + protected function get_read_fields() + { + if($this->read_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->read_fields)) + { + foreach($this->read_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + else + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + } + } + else + { + $this->read_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_read_field is initialize for this field name + if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) + continue; + + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') + { + if(isset($this->display_as[$field->name])) + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->read_fields_checked = true; + } + return $this->read_fields; + } + public function order_by($order_by, $direction = 'asc') { $this->order_by = array($order_by,$direction); diff --git a/change_log.txt b/change_log.txt index 2d90a4cd..b38130de 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,8 @@ v 1.4.1 #231 - Read page not showing relations. + Add new functions: + - unset_read_fields + - set_read_fields v 1.4.0 #170 - Problem with more than one date inputs at the dialog. #148 - New theme twitter-bootstrap