Permalink
Browse files

Method set_relation - New feature to add more than one fields to the …

…title of the related table.
  • Loading branch information...
1 parent 4f17731 commit f9df00089f135c9534ae76fbd7159a0a4feb7d72 @scoumbourdis scoumbourdis committed Dec 8, 2011
Showing with 37 additions and 13 deletions.
  1. +1 −1 application/controllers/examples.php
  2. +35 −11 application/libraries/grocery_crud.php
  3. +1 −1 change_log.txt
@@ -130,8 +130,8 @@ function film_management()
$crud->set_table('film');
$crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname','priority');
$crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name');
+ $crud->unset_columns('special_features','description');
- $crud->unset_columns('description');
$crud->fields('title', 'description', 'actors' , 'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features');
$output = $crud->render();
@@ -471,9 +471,20 @@ protected function set_ajax_list_queries($state_info = null)
if(!empty($state_info->search))
{
+ if(!empty($this->relation))
+ foreach($this->relation as $relation_name => $relation_values)
+ $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values);
+
if($state_info->search->field != null)
{
- $this->like($state_info->search->field , $state_info->search->text);
+ if(isset($temp_relation[$state_info->search->field]))
+ if(is_array($temp_relation[$state_info->search->field]))
+ foreach($temp_relation[$state_info->search->field] as $search_field)
+ $this->or_like($search_field , $state_info->search->text);
+ else
+ $this->like($temp_relation[$state_info->search->field] , $state_info->search->text);
+ else
+ $this->like($state_info->search->field , $state_info->search->text);
}
else
{
@@ -486,22 +497,17 @@ protected function set_ajax_list_queries($state_info = null)
unset($columns[$num_row]);
#endregion
- if(!empty($this->relation))
- {
- $temp_relation = array();
- foreach($this->relation as $relation_name => $relation_values)
- $temp_relation[$this->_unique_field_name($relation_name)] = $this->_unique_field_name($relation_values[2]);
- }
-
$search_text = $state_info->search->text;
foreach($columns as $column)
- {
if(isset($temp_relation[$column->field_name]))
- $this->or_like($temp_relation[$column->field_name], $search_text);
+ if(is_array($temp_relation[$column->field_name]))
+ foreach($temp_relation[$column->field_name] as $search_field)
+ $this->or_like($search_field, $search_text);
+ else
+ $this->or_like($temp_relation[$column->field_name], $search_text);
else
$this->or_like($column->field_name, $search_text);
- }
}
}
}
@@ -790,6 +796,24 @@ protected function db_update($state_info)
}
}
+ protected function _get_field_names_to_search(array $relation_values)
+ {
+ if(!strstr($relation_values[2],'{'))
+ return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2];
+ else
+ {
+ $relation_values[2] = ' '.$relation_values[2].' ';
+ $temp1 = explode('{',$relation_values[2]);
+ unset($temp1[0]);
+
+ $field_names_array = array();
+ foreach($temp1 as $field)
+ list($field_names_array[]) = explode('}',$field);
+
+ return $field_names_array;
+ }
+ }
+
protected function _unique_join_name($field_name)
{
return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number
View
@@ -1,5 +1,5 @@
v.1.1.5
- Method set_relation - feature to add more than one field to the title of the related table.
+ Method set_relation - New feature to add more than one fields to the title of the related table.
Adding Timestamp as an automatic date and time field.
Change the business logic of adding js and css files. This is really useful for a future feature with multiple tables in the same view.
A temporary solution for the search for All that have a relation_n_n.

0 comments on commit f9df000

Please sign in to comment.