Show
Ignore:
Timestamp:
01/12/06 05:24:23 (6 years ago)
Author:
john
Message:

added scaffolding generator

Location:
trunk/trax/vendor/trax/action_view/helpers
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r110 r113  
    33 
    44class ActiveRecordHelper extends Helpers { 
     5     
     6    public $scaffolding = 0; 
    57 
    68    # Returns a default input tag for the type of object returned by the method. Example 
     
    911    #     <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 
    1012    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);         
    1218    } 
    1319 
     
    110116 
    111117    function all_input_tags($record, $record_name, $options) { 
     118        //if($record_name) $this->object_name = $record_name; 
    112119        $input_block = (isset($options['input_block']) ? $options['input_block'] : $this->default_input_block()); 
    113120        $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            } 
    121130        }  
    122131        return $contents; 
     
    124133 
    125134    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     
    129142    function to_tag($object_name, $attribute_name, $options = array()) { 
    130143        $this->object_name = $object_name; 
    131144        $this->attribute_name = $attribute_name; 
    132         #this will be fixed once the column object is developed 
    133145        $form = new FormHelper($object_name, $attribute_name); 
    134146        switch($this->column_type()) { 
     
    164176            $results = $this->error_wrapping($results, $this->object()->errors[$this->attribute_name]); 
    165177        } 
     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        } 
    166215        return $results; 
    167216    } 
     
    277326} 
    278327 
     328function 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 
    279334?> 
  • trunk/trax/vendor/trax/action_view/helpers/date_helper.php

    r107 r113  
    6060        return $number > 9 ? $number : "0$number"; 
    6161    } 
     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    }            
    6274 
    6375    # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. 
     
    297309} 
    298310 
     311function 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 
     317function 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 
    299323?> 
  • trunk/trax/vendor/trax/action_view/helpers/form_helper.php

    r106 r113  
    247247} 
    248248 
     249function boolean_select($object, $field, $options = array()) { 
     250    $form = new FormHelper($object, $field); 
     251    return $form->to_boolean_select_tag($options);         
     252} 
     253 
    249254?>