Changeset 113 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 01/12/06 05:24:23 (6 years ago)
- Location:
- trunk/trax/vendor/trax/action_view/helpers
- Files:
-
- 3 modified
-
active_record_helper.php (modified) (6 diffs)
-
date_helper.php (modified) (2 diffs)
-
form_helper.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php
r110 r113 3 3 4 4 class ActiveRecordHelper extends Helpers { 5 6 public $scaffolding = 0; 5 7 6 8 # Returns a default input tag for the type of object returned by the method. Example … … 9 11 # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 10 12 function input($object_name, $attribute_name, $options = array()) { 11 return $this->to_tag($object_name, $attribute_name, $options); 13 return $this->to_tag($object_name, $attribute_name, $options); 14 } 15 16 function input_scaffolding($object_name, $attribute_name, $options = array()) { 17 return $this->to_scaffold_tag($object_name, $attribute_name, $options); 12 18 } 13 19 … … 110 116 111 117 function all_input_tags($record, $record_name, $options) { 118 //if($record_name) $this->object_name = $record_name; 112 119 $input_block = (isset($options['input_block']) ? $options['input_block'] : $this->default_input_block()); 113 120 $contents = ''; 114 foreach($record->content_columns as $column) { 115 //$contents .= "<p><label for=\"".$record_name."_".$column['name']."\">"; 116 //$contents .= Inflector::humanize($column['name']) . ":</label><br />"; 117 //$contents .= input($record_name, $column['name']) . "</p>\n"; 118 if(!in_array($column['name'], $record->primary_keys)) { 119 eval($input_block) . "\n"; 120 } 121 if(is_array($record->content_columns)) { 122 foreach($record->content_columns as $column) { 123 //$contents .= "<p><label for=\"".$record_name."_".$column['name']."\">"; 124 //$contents .= Inflector::humanize($column['name']) . ":</label><br />"; 125 //$contents .= input($record_name, $column['name']) . "</p>\n"; 126 if(!in_array($column['name'], $record->primary_keys)) { 127 eval($input_block) . "\n"; 128 } 129 } 121 130 } 122 131 return $contents; … … 124 133 125 134 function default_input_block() { 126 return '$contents .= "<p><label for=\"{$record_name}_{$column[\'name\']}\">" . Inflector::humanize($column[\'name\']) . ":</label><br />" . input($record_name, $column[\'name\']) . "</p>";'; 127 } 128 135 if($this->scaffolding) { 136 return '$contents .= "<p><label for=\"{$record_name}_{$column[\'name\']}\">" . Inflector::humanize($column[\'name\']) . ":</label><br/>\n<?= " . input_scaffolding($record_name, $column[\'name\']) . " ?></p>\n";'; 137 } else { 138 return '$contents .= "<p><label for=\"{$record_name}_{$column[\'name\']}\">" . Inflector::humanize($column[\'name\']) . ":</label><br/>\n" . input($record_name, $column[\'name\']) . "</p>\n";'; 139 } 140 } 141 129 142 function to_tag($object_name, $attribute_name, $options = array()) { 130 143 $this->object_name = $object_name; 131 144 $this->attribute_name = $attribute_name; 132 #this will be fixed once the column object is developed133 145 $form = new FormHelper($object_name, $attribute_name); 134 146 switch($this->column_type()) { … … 164 176 $results = $this->error_wrapping($results, $this->object()->errors[$this->attribute_name]); 165 177 } 178 return $results; 179 } 180 181 function to_scaffold_tag($object_name, $attribute_name, $options = array()) { 182 $this->object_name = $object_name; 183 $this->attribute_name = $attribute_name; 184 switch($this->column_type()) { 185 case 'string': 186 case 'varchar': 187 case 'varchar2': 188 $field_type = (eregi("password", $this->attribute_name) ? "password" : "text"); 189 $results = $field_type."_field(\"$object_name\", \"$attribute_name\")"; 190 break; 191 case 'text': 192 case 'blob': 193 $results = "text_area(\"$object_name\", \"$attribute_name\")"; 194 break; 195 case 'integer': 196 case 'int': 197 case 'number': 198 case 'float': 199 $results = "text_field(\"$object_name\", \"$attribute_name\")"; 200 break; 201 case 'date': 202 $results = "date_select(\"$object_name\", \"$attribute_name\")"; 203 break; 204 case 'datetime': 205 $results = "datetime_select(\"$object_name\", \"$attribute_name\")"; 206 break; 207 case 'boolean': 208 case 'bool': 209 $results = "boolean_select(\"$object_name\", \"$attribute_name\")"; 210 break; 211 } 212 if(count($this->object()->errors)) { 213 $results = $this->error_wrapping($results, $this->object()->errors[$this->attribute_name]); 214 } 166 215 return $results; 167 216 } … … 277 326 } 278 327 328 function input_scaffolding() { 329 $ar_helper = new ActiveRecordHelper(); 330 $args = func_get_args(); 331 return call_user_func_array(array($ar_helper, 'input_scaffolding'), $args); 332 } 333 279 334 ?> -
trunk/trax/vendor/trax/action_view/helpers/date_helper.php
r107 r113 60 60 return $number > 9 ? $number : "0$number"; 61 61 } 62 63 # datetime_select("post", "written_on") 64 # datetime_select("post", "written_on", array("start_year" => 1995)) 65 function datetime_select($options = array()) { 66 return $this->to_datetime_select_tag($options); 67 } 68 69 # datetime_select("post", "written_on") 70 # datetime_select("post", "written_on", array("start_year" => 1995)) 71 function date_select($options = array()) { 72 return $this->to_date_select_tag($options); 73 } 62 74 63 75 # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. … … 297 309 } 298 310 311 function datetime_select($object, $attribute, $options = array()) { 312 $date_helper = new DateHelper($object, $attribute); 313 $args = func_get_args(); 314 return call_user_func_array(array($date_helper, 'datetime_select'), $options); 315 } 316 317 function date_select($object, $attribute, $options = array()) { 318 $date_helper = new DateHelper($object, $attribute); 319 $args = func_get_args(); 320 return call_user_func_array(array($date_helper, 'date_select'), $options); 321 } 322 299 323 ?> -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
r106 r113 247 247 } 248 248 249 function boolean_select($object, $field, $options = array()) { 250 $form = new FormHelper($object, $field); 251 return $form->to_boolean_select_tag($options); 252 } 253 249 254 ?>
