Jump to content


Kenta Saito

Member Since 01 Mar 2012
Offline Last Active Aug 25 2012 12:30 PM
-----

Topics I've Started

Raw SQL Logging

15 May 2012 - 01:58 AM

Is there "Raw SQL Logging" function in grocery CRUD? (when using ActiveRecord)
(for example, get('users') goes 'SELECT id, name, email FROM users')

I am affraid that if this is not grocery CRUD question, but CodeIgniter question.
But, if grocery CRUD has (or planning) original logging function, it helps.

P.S.
Congratulations version 1.2.2 release!

Regard.

Non-editable page for selected one record

08 May 2012 - 12:58 AM

In grocery CRUD, there are:

- Index of records page
- Editable page for selected one record

Is there "non-editable page for selected one record" ? (only viewing)
(I don't know how do I call this in English, "cut sheet" ?)

For now, I make every fields "readonly", to do that.
Is there better way?

Can I draw 'set_relation' field as readonly?

26 April 2012 - 07:05 AM

A 'set_relation' field is drawn as SELECT.
Can I make it readonly? (like Label)


If I set like below:

$this->crud->set_relation(
	'auth_user_id',
	'auth_users',
	'name'
);
$this->crud->change_field_type('auth_user_id', 'readonly');

'auth_users.auth_user_id' will be drawn.
I just wanna draw 'auth_users.name' as Label.

Is there smart way to do this?

SET type interface with checkbox

12 April 2012 - 06:55 AM

Version: grocery_CRUD_v1.2.zip
See Also: http://www.grocerycr...e-for-set-type/

Attached File  checkbox.png   7.58K   2779 downloads

I made another interface for SET type.
Last time, 'multiple select'. This time, 'checkbox'.

For detail, follow 'See Also' link above.
  • application/controllers/examples.php
Un-unset_column 'special_features'.
Then change 'special_features's type from 'set' to 'set_checkbox'.

diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/application/controllers/examples.php CodeIgniter_2.1.0/application/controllers/examples.php
--- CodeIgniter_2.1.0.orig/application/controllers/examples.php 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/application/controllers/examples.php 2012-04-12 15:40:19.000000000 +0900
@@ -130,7 +130,8 @@
   $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->change_field_type('special_features', 'set_checkbox');
  
   $crud->fields('title', 'description', 'actors' ,  'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features');
  • application/libraries/grocery_crud.php
Add function "get_set_checkbox_input()" to the library (and some peripherals)

diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/application/libraries/grocery_crud.php CodeIgniter_2.1.0/application/libraries/grocery_crud.php
--- CodeIgniter_2.1.0.orig/application/libraries/grocery_crud.php 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/application/libraries/grocery_crud.php 2012-04-12 15:36:00.000000000 +0900
@@ -198,6 +198,12 @@
	 case 'enum':
	  $field_info->input = $this->get_enum_input($field_info,$value);
	 break;
+	case 'set':
+	 $field_info->input = $this->get_set_input($field_info,$value);
+	break;
+	case 'set_checkbox':
+	 $field_info->input = $this->get_set_checkbox_input($field_info,$value);
+	break;
	 case 'relation':
	  $field_info->input = $this->get_relation_input($field_info,$value);
	 break;
@@ -267,6 +273,12 @@
	case 'enum':
	 $value = $this->character_limiter($value,20,"...");
	break;
+   case 'set':
+	$value = $this->character_limiter($value,20,"...");
+   break;
+   case 'set_checkbox':
+	$value = $this->character_limiter($value,20,"...");
+   break;
	case 'relation_n_n':
	 $value = implode(', ' ,$this->get_relation_n_n_selection_array( $value, $this->relation_n_n[$field_info->name] ));
	 $value = $this->character_limiter($value,30,"...");
@@ -359,6 +371,18 @@
	  else
	   $type = 'enum';
	 break;
+	case 'set':	
+	 if($db_type->db_type != 'set')
+	  $type = 'string';
+	 else
+	  $type = 'set';
+	break;
+	case 'set_checkbox':	
+	 if($db_type->db_type != 'set')
+	  $type = 'string';
+	 else
+	  $type = 'set_checkbox';
+	break;
	 case '252':
	 case 'blob':
	 case 'text':
@@ -1667,6 +1691,49 @@
   return $input;
  }

+ protected function get_set_input($field_info,$value)
+ {
+  $selected_options = array();
+  if ( ! empty($value))
+  {
+   foreach (explode(',', $value) as $v) $selected_options[$v] = TRUE;
+  }
+
+  $input = "<select multiple onchange=\"var v = ''; for (var i in this.options) if (this.options[i].selected) v += (v == '' ? '' : ',') + this.options[i].value; this.nextSibling.value = v;\">";
+  
+  $options_array = explode("','",substr($field_info->db_max_length,1,-1));
+  foreach($options_array as $option)
+  {
+   $selected = !empty($value) && isset($selected_options[$option]) ? "selected='selected'" : '';
+   $input .= "<option value='$option' $selected >$option</option>";
+  }
+
+  $input .= "</select>";
+  $input .= "<input type='hidden' name='{$field_info->name}' value='$value' />";
+  return $input;
+ }
+
+ protected function get_set_checkbox_input($field_info,$value)
+ {
+  $selected_options = array();
+  if ( ! empty($value))
+  {
+   foreach (explode(',', $value) as $v) $selected_options[$v] = TRUE;
+  }
+
+  $input = '<div>';
+  $options_array = explode("','",substr($field_info->db_max_length,1,-1));
+  foreach($options_array as $option)
+  {
+   $selected = !empty($value) && isset($selected_options[$option]) ? "checked='checked'" : '';
+   $input .= "<input type=\"checkbox\" value=\"$option\" $selected onchange=\"var v = ''; var c = this.parentNode.childNodes; for (var i in c) if (c[i].value !== undefined && c[i].checked) v += (v == '' ? '' : ',') + c[i].value; this.parentNode.nextSibling.value = v;\" />$option ";
+  }
+
+  $input .= "</div>";
+  $input .= "<input type='hidden' name='{$field_info->name}' value='$value' />";
+  return $input;
+ }
+
  protected function get_relation_input($field_info,$value)
  {
   $this->set_css('assets/grocery_crud/css/jquery_plugins/chosen/chosen.css');

An interface for SET type

07 April 2012 - 02:05 AM

Version: grocery_CRUD_v1.2.zip
See Also: http://www.grocerycr...tion-n-n-field/

Attached File  set.png   14.47K   1385 downloads

grocery CRUD "examples" has a "SET" type field in "film" table.
(`special_features` set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL)

I made an interface for SET type. (for Add and Edit action)
  • application/controllers/examples.php
In default, the field 'special_features' is in unset_columns.
So, allow to display this field first. (and searching works too)

diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/application/controllers/examples.php CodeIgniter_2.1.0/application/controllers/examples.php
--- CodeIgniter_2.1.0.orig/application/controllers/examples.php 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/application/controllers/examples.php 2012-04-07 10:40:28.000000000 +0900
@@ -130,7 +130,7 @@
   $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');
  • application/libraries/grocery_crud.php
Add function "get_set_input()" to the library (and some peripherals)

diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/application/libraries/grocery_crud.php CodeIgniter_2.1.0/application/libraries/grocery_crud.php
--- CodeIgniter_2.1.0.orig/application/libraries/grocery_crud.php	2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/application/libraries/grocery_crud.php	2012-04-07 10:38:30.000000000 +0900
@@ -197,6 +197,8 @@
				 break;			
				 case 'enum':
					 $field_info->input = $this->get_enum_input($field_info,$value);
+				case 'set':
+					$field_info->input = $this->get_set_input($field_info,$value);
				 break;
				 case 'relation':
					 $field_info->input = $this->get_relation_input($field_info,$value);
@@ -266,6 +268,8 @@
			 break;
			 case 'enum':
				 $value = $this->character_limiter($value,20,"...");
+			case 'set':
+				$value = $this->character_limiter($value,20,"...");
			 break;	
			 case 'relation_n_n':
				 $value = implode(', ' ,$this->get_relation_n_n_selection_array( $value, $this->relation_n_n[$field_info->name] ));
@@ -358,6 +362,11 @@
						 $type = 'string';
					 else
						 $type = 'enum';
+				case 'set':					
+					if($db_type->db_type != 'set')
+						$type = 'string';
+					else
+						$type = 'set';
				 break;
				 case '252':
				 case 'blob':
@@ -1667,6 +1676,28 @@
		 return $input;
	 }	
	
+	protected function get_set_input($field_info,$value)
+	{		
+		$selected_options = array();
+		if ( ! empty($value))
+		{
+			foreach (explode(',', $value) as $v) $selected_options[$v] = TRUE;
+		}
+
+		$input = "<select multiple onchange=\"var v = ''; for (var i in this.options) if (this.options[i].selected) v += (v == '' ? '' : ',') + this.options[i].value; this.nextSibling.value = v;\">";
+			
+		$options_array = explode("','",substr($field_info->db_max_length,1,-1));
+		foreach($options_array as $option)
+		{
+			$selected = !empty($value) && isset($selected_options[$option]) ? "selected='selected'" : '';
+			$input .= "<option value='$option' $selected >$option</option>";	
+		}
+		
+		$input .= "</select>";
+		$input .= "<input type='hidden' name='{$field_info->name}' />";
+		return $input;
+	}	
+	
	 protected function get_relation_input($field_info,$value)
	 {
		 $this->set_css('assets/grocery_crud/css/jquery_plugins/chosen/chosen.css');