Show
Ignore:
Timestamp:
04/20/06 10:20:30 (6 years ago)
Author:
haas
Message:

DateHelper? docs and tests

Location:
trunk/trax/vendor/trax/action_view
Files:
5 modified

Legend:

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

    r196 r198  
    5757     *  Current controller object 
    5858     * 
    59      *  Local copy of $GLOBALS['current_controller_object'] 
     59     *  Local copy of $GLOBALS['current_controller_object']<br /> 
     60     *  <b>NB:</b> {@link object()} faults if this does not contain a 
     61     *  valid instance of ActionController. 
    6062     *  @var ActionController 
    6163     */ 
     
    103105        //  Copy controller information from $GLOBALS 
    104106        $this->controller_name = 
    105             array_key_exists('current_controller_name',$GLOBALS) 
     107            (array_key_exists('current_controller_name',$GLOBALS) 
     108             && $GLOBALS['current_controller_name']) 
    106109            ? $GLOBALS['current_controller_name'] : null; 
    107110        $this->controller_path = 
    108             array_key_exists('current_controller_path', $GLOBALS) 
     111            (array_key_exists('current_controller_path', $GLOBALS) 
     112             && $GLOBALS['current_controller_path']) 
    109113            ? $GLOBALS['current_controller_path'] : null; 
    110114        $this->controller_object = 
    111             array_key_exists('current_controller_object', $GLOBALS) 
     115            (array_key_exists('current_controller_object', $GLOBALS) 
     116             && $GLOBALS['current_controller_object']) 
    112117            ? $GLOBALS['current_controller_object'] : null; 
    113118        if($auto_index) { 
     
    131136     */ 
    132137    protected function value() { 
    133         if (!array_key_exists($this->object_name, $_REQUEST) 
    134             || !array_key_exists($this->attribute_name, 
     138        if (array_key_exists($this->object_name, $_REQUEST) 
     139            && array_key_exists($this->attribute_name, 
    135140                                 $_REQUEST[$this->object_name])) { 
     141            $value = $_REQUEST[$this->object_name][$this->attribute_name]; 
     142        } else { 
     143 
     144            //  Attribute value not found in $_REQUEST.  Find the 
     145            //  ActiveRecord subclass instance and query it. 
    136146            $object = $this->object(); 
    137147            if(is_object($object) && $this->attribute_name) { 
     
    143153 
    144154    /** 
    145      *  @todo Document this method 
    146      *  @param string object_name 
     155     *  Given the name of an ActiveRecord subclass, find an instance 
     156     * 
     157     *  Finds the AR instance from the ActionController instance. 
     158     *  Assumes that if a $object_name is defined either as the 
     159     *  argument or an instance variable, then there must be 
     160     *  a controller object instance which points to a single instance 
     161     *  of the ActiveRecord. 
     162     *  <b>FIXME:</b> Handle errors better. 
     163     *  @param string Name of an ActiveRecord subclass or null 
     164     *  @return mixed Instance of the subclass, or null if 
     165     *                object not available. 
    147166     *  @uses controller_object 
     167     *  @uses object_name 
    148168     */ 
    149169    protected function object($object_name = null) { 
    150170        $object_name = $object_name ? $object_name : $this->object_name; 
    151         if($object_name) { 
     171        if($object_name 
     172           && isset($this->controller_object) 
     173           && isset($this->controller_object->$object_name)) { 
    152174            return $this->controller_object->$object_name; 
    153175        } 
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r196 r198  
    3737     
    3838    /** 
    39      *  @todo Document this variable 
    40      */ 
    41     public $scaffolding = 0; 
     39     *  Whether to generate scaffolding HTML 
     40     * 
     41     *  Set to true in {@link form_scaffolding.phtml}.  If true 
     42     *  generate HTML scaffold otherwise generate final HTML 
     43     *  @var boolean 
     44     */ 
     45    public $scaffolding = false; 
    4246 
    4347    /** 
     
    231235        $form = new FormHelper($object_name, $attribute_name); 
    232236        switch($this->column_type()) { 
    233             case 'string': 
    234             case 'varchar': 
    235             case 'varchar2': 
    236                 $field_type = (eregi("password", $this->attribute_name) ? "password" : "text"); 
    237                 $results = $form->to_input_field_tag($field_type, $options); 
    238                 break; 
    239             case 'text': 
    240             case 'blob': 
    241                 $results = $form->to_text_area_tag($options); 
    242                 break; 
    243             case 'integer': 
    244             case 'int': 
    245             case 'number': 
    246             case 'float': 
    247                 $results = $form->to_input_field_tag("text", $options); 
    248                 break; 
    249             case 'date': 
    250                 $form = new DateHelper($object_name, $attribute_name); 
    251                 $results = $form->to_date_select_tag($options); 
    252                 break; 
    253             case 'datetime': 
    254                 $results = $this->to_datetime_select_tag($options); 
    255                 break; 
    256             case 'boolean': 
    257             case 'bool': 
    258                 $results = $form->to_boolean_select_tag($options); 
    259                 break; 
     237        case 'string': 
     238        case 'varchar': 
     239        case 'varchar2': 
     240            $field_type = (eregi("password", $this->attribute_name) ? "password" : "text"); 
     241            $results = $form->to_input_field_tag($field_type, $options); 
     242            break; 
     243 
     244        case 'text': 
     245        case 'blob': 
     246            $results = $form->to_text_area_tag($options); 
     247            break; 
     248 
     249        case 'integer': 
     250        case 'int': 
     251        case 'number': 
     252        case 'float': 
     253        case 'real': 
     254            $results = $form->to_input_field_tag("text", $options); 
     255            break; 
     256 
     257        case 'date': 
     258            $form = new DateHelper($object_name, $attribute_name); 
     259            $results = $form->to_date_select_tag($options); 
     260            break; 
     261 
     262        case 'datetime': 
     263        case 'timestamp': 
     264            $results = $this->to_datetime_select_tag($options); 
     265            break; 
     266 
     267        case 'boolean': 
     268        case 'bool': 
     269            $results = $form->to_boolean_select_tag($options); 
     270            break; 
     271 
    260272        } 
    261273        if(count($this->object()->errors)) { 
     
    270282     *  @uses attribute_name 
    271283     *  @uses column_type() 
     284     *  @uses error_wrapping 
    272285     *  @uses object() 
    273286     *  @uses object_name 
     
    277290        $this->attribute_name = $attribute_name; 
    278291        switch($this->column_type()) { 
    279             case 'string': 
    280             case 'varchar': 
    281             case 'varchar2': 
    282                 $field_type = (eregi("password", $this->attribute_name) ? "password" : "text"); 
    283                 $results = $field_type."_field(\"$object_name\", \"$attribute_name\")"; 
    284                 break; 
    285             case 'text': 
    286             case 'blob': 
    287                 $results = "text_area(\"$object_name\", \"$attribute_name\")"; 
    288                 break; 
    289             case 'integer': 
    290             case 'int': 
    291             case 'number': 
    292             case 'float': 
    293                 $results = "text_field(\"$object_name\", \"$attribute_name\")"; 
    294                 break; 
    295             case 'date': 
    296                 $results = "date_select(\"$object_name\", \"$attribute_name\")"; 
    297                 break; 
    298             case 'datetime': 
    299                 $results = "datetime_select(\"$object_name\", \"$attribute_name\")"; 
    300                 break; 
    301             case 'boolean': 
    302             case 'bool': 
    303                 $results = "boolean_select(\"$object_name\", \"$attribute_name\")"; 
    304                 break; 
    305     default: 
     292        case 'string': 
     293        case 'varchar': 
     294        case 'varchar2': 
     295            $field_type = (eregi("password", $this->attribute_name) ? "password" : "text"); 
     296            $results = $field_type."_field(\"$object_name\", \"$attribute_name\")"; 
     297            break; 
     298 
     299        case 'text': 
     300        case 'blob': 
     301            $results = "text_area(\"$object_name\", \"$attribute_name\")"; 
     302            break; 
     303 
     304        case 'integer': 
     305        case 'int': 
     306        case 'number': 
     307        case 'float': 
     308        case 'real': 
     309            $results = "text_field(\"$object_name\", \"$attribute_name\")"; 
     310            break; 
     311 
     312        case 'date': 
     313            $results = "date_select(\"$object_name\", \"$attribute_name\")"; 
     314            break; 
     315 
     316        case 'year': 
     317            $results = "year_select(\"$object_name\", \"$attribute_name\")"; 
     318            break; 
     319 
     320        case 'datetime': 
     321        case 'timestamp': 
     322            $results = "datetime_select(\"$object_name\", \"$attribute_name\")"; 
     323            break; 
     324 
     325        case 'time': 
     326            $results = "time_select(\"$object_name\", \"$attribute_name\")"; 
     327            break; 
     328 
     329        case 'boolean': 
     330        case 'bool': 
     331            $results = "boolean_select(\"$object_name\", \"$attribute_name\")"; 
     332            break; 
     333 
     334        default: 
     335            echo "No case statement for ".$this->column_type()."\n"; 
    306336        } 
    307337        if(count($this->object()->errors)) { 
    308             $results = $this->error_wrapping($results, $this->object()->errors[$this->attribute_name]); 
     338            $results = $this->error_wrapping($results,  
     339                              $this->object()->errors[$this->attribute_name]); 
    309340        } 
    310341        return $results; 
     
    343374    function content_tag_without_error_wrapping() { 
    344375        $args = func_get_args(); 
    345         return call_user_func_array(array(parent, 'content_tag'), $args); 
     376        return call_user_func_array('content_tag', $args); 
    346377    } 
    347378 
     
    355386    function content_tag($name, $value, $options = array()) { 
    356387        if (count($this->object()->errors)) { 
    357             return $this->error_wrapping($this->content_tag_without_error_wrapping($name, $value, $options), $this->object()->errors[$this->attribute_name]); 
     388            return $this->error_wrapping( 
     389          $this->content_tag_without_error_wrapping($name, $value, $options), 
     390            array_key_exists($this->attribute_name,$this->object()->errors) 
     391            ? true : false); 
    358392        } else { 
    359             return $this->content_tag_without_error_wrapping($name, $value, $options); 
     393            return $this->content_tag_without_error_wrapping($name, $value, 
     394                                                             $options); 
    360395        } 
    361396    } 
  • trunk/trax/vendor/trax/action_view/helpers/date_helper.php

    r196 r198  
    3030 
    3131/** 
    32  * 
    33  *  @todo Document this class 
     32 *  Utility to help build HTML pulldown menus for date and time 
    3433 */ 
    3534class DateHelper extends Helpers { 
    3635 
    3736    /** 
    38      *  @todo Document this variable 
     37     *  Year values parsed from $_REQUEST 
     38     * 
     39     *  Set by {@link check_request_for_value()}.  An array whose keys 
     40     *  are the names of attributes of the {@link ActiveRecord} 
     41     *  subclass named by {@link $object_name}, and whose values are 
     42     *  the strings parsed from $_REQUEST. 
     43     *  @var string[] 
    3944     */ 
    4045    public $request_years; 
    4146 
    4247    /** 
    43      *  Month value parsed from $_REQUEST 
     48     *  Month values parsed from $_REQUEST 
     49     * 
     50     *  Set by {@link check_request_for_value()}.  An array whose keys 
     51     *  are the names of attributes of the {@link ActiveRecord} 
     52     *  subclass named by {@link $object_name}, and whose values are 
     53     *  the strings parsed from $_REQUEST. 
     54     *  @var string[] 
    4455     */ 
    4556    public $request_months = array(); 
    4657 
    4758    /** 
    48      *  @todo Document this variable 
     59     *  Day of month values parsed from $_REQUEST 
     60     * 
     61     *  Set by {@link check_request_for_value()}.  An array whose keys 
     62     *  are the names of attributes of the {@link ActiveRecord} 
     63     *  subclass named by {@link $object_name}, and whose values are 
     64     *  the strings parsed from $_REQUEST. 
     65     *  @var string[] 
    4966     */ 
    5067    public $request_days; 
    5168 
    5269    /** 
    53      *  @todo Document this variable 
     70     *  Hour values parsed from $_REQUEST 
     71     * 
     72     *  Set by {@link check_request_for_value()}.  An array whose keys 
     73     *  are the names of attributes of the {@link ActiveRecord} 
     74     *  subclass named by {@link $object_name}, and whose values are 
     75     *  the strings parsed from $_REQUEST. 
     76     *  @var string[] 
    5477     */ 
    5578    public $request_hours; 
    5679 
    5780    /** 
    58      *  @todo Document this variable 
     81     *  Minute values parsed from $_REQUEST 
     82     * 
     83     *  Set by {@link check_request_for_value()}.  An array whose keys 
     84     *  are the names of attributes of the {@link ActiveRecord} 
     85     *  subclass named by {@link $object_name}, and whose values are 
     86     *  the strings parsed from $_REQUEST. 
     87     *  @var string[] 
    5988     */ 
    6089    public $request_minutes; 
    6190 
    6291    /** 
    63      *  @todo Document this variable 
     92     *  Second values parsed from $_REQUEST 
     93     * 
     94     *  Set by {@link check_request_for_value()}.  An array whose keys 
     95     *  are the names of attributes of the {@link ActiveRecord} 
     96     *  subclass named by {@link $object_name}, and whose values are 
     97     *  the strings parsed from $_REQUEST. 
     98     *  @var string[] 
    6499     */ 
    65100    public $request_seconds; 
    66101 
    67102    /** 
    68      *  @todo Document this variable 
     103     *  <b>FIXME:</b>  Dead code? 
    69104     */ 
    70105    public $selected_years = array(); 
    71106 
    72107    /** 
    73      *  @todo Document this method 
     108     *  Constructor 
     109     * 
     110     *  Construct an instance of Helpers with the same arguments 
     111     *  @param string Name of an ActiveRecord subclass 
     112     *  @param string Name of an attribute of $object 
    74113     */ 
    75114    function __construct($object_name = null, $attribute_name = null) { 
     
    78117     
    79118    /** 
    80      *  @todo Document this method 
     119     *  Check whether $_REQUEST holds value for this attribute 
     120     * 
     121     *  Called with the name of an ActiveRecord subclass in 
     122     *  $this->object_name and the name of one of its attributes in 
     123     *  $this->attribute_name.  Check whether $_REQUEST contains a 
     124     *  value for this attribute; if so return it. 
     125     *  @return mixed String value if attribute was found in 
     126     *                $_REQUEST, otherwise false 
    81127     *  @uses attribute_name 
    82128     *  @uses object_name 
     
    89135     */ 
    90136    private function check_request_for_value() { 
    91         if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 
    92             # check if this a date / datetime 
    93             if($year_value = $_REQUEST[$this->object_name][$this->attribute_name."(1i)"]) { 
    94                 $this->request_years[$this->attribute_name] = $year_value;     
    95             } 
    96             if($month_value = $_REQUEST[$this->object_name][$this->attribute_name."(2i)"]) { 
    97                 $this->request_months[$this->attribute_name] = $month_value;     
    98             } 
    99             if($day_value = $_REQUEST[$this->object_name][$this->attribute_name."(3i)"]) { 
    100                 $this->request_days[$this->attribute_name] = $day_value;     
    101             } 
    102             if($minute_value = $_REQUEST[$this->object_name][$this->attribute_name."(4i)"]) { 
    103                 $this->request_minutes[$this->attribute_name] = $minute_value;     
    104             }    
    105             if($hour_value = $_REQUEST[$this->object_name][$this->attribute_name."(5i)"]) { 
    106                 $this->request_hours[$this->attribute_name] = $hour_value;     
    107             }               
    108             if($second_value = $_REQUEST[$this->object_name][$this->attribute_name."(6i)"]) { 
    109                 $this->request_seconds[$this->attribute_name] = $second_value;     
    110             }                                                                    
     137        //error_log("check_request_for_value().  object name='" 
     138        //          . $this->object_name ."'  attribute name = '" 
     139        //          . $this->attribute_name ."'"); 
     140 
     141        //  If $_REQUEST[$this->object_name] does not exist, 
     142        //  return false immediately 
     143        if (!isset($_REQUEST) || !is_array($_REQUEST) 
     144            || !array_key_exists($this->object_name, $_REQUEST)) { 
     145            return false; 
     146        } 
     147 
     148        //  $_REQUEST[$this->object_name] exists. 
     149        //  Look for the requested attribute 
     150        if (array_key_exists($this->attribute_name, 
     151                             $_REQUEST[$this->object_name])) { 
     152 
     153            //  Requested attribute found, return it 
     154            return $_REQUEST[$this->object_name][$this->attribute_name]; 
     155        } 
     156 
     157        //  There is an element $_REQUEST[$this->object_name] but not 
     158        //  $_REQUEST[$this->object_name][$this->attribute_name] so 
     159        //  check for the individual components of a date/time 
     160 
     161        //  Keep track of whether we find any components 
     162        $found = false; 
     163 
     164        //    Check for year component 
     165        if (array_key_exists($this->attribute_name."(1i)", 
     166                             $_REQUEST[$this->object_name])) { 
     167            $this->request_years[$this->attribute_name] = 
     168                $_REQUEST[$this->object_name][$this->attribute_name."(1i)"]; 
     169            $found = true; 
     170        } 
     171 
     172        //    Check for month component 
     173        if (array_key_exists($this->attribute_name."(2i)", 
     174                             $_REQUEST[$this->object_name])) { 
     175            $this->request_months[$this->attribute_name] = 
     176                $_REQUEST[$this->object_name][$this->attribute_name."(2i)"]; 
     177            $found = true; 
     178        } 
     179 
     180        //    Check for day component 
     181        if (array_key_exists($this->attribute_name."(3i)", 
     182                             $_REQUEST[$this->object_name])) { 
     183            $this->request_days[$this->attribute_name] = 
     184                $_REQUEST[$this->object_name][$this->attribute_name."(3i)"]; 
     185            $found = true; 
     186        } 
     187 
     188        //    Check for hour component 
     189        if (array_key_exists($this->attribute_name."(4i)", 
     190                             $_REQUEST[$this->object_name])) { 
     191            $this->request_hours[$this->attribute_name] = 
     192                $_REQUEST[$this->object_name][$this->attribute_name."(4i)"]; 
     193            $found = true; 
    111194        }    
    112         return $value;      
    113     } 
    114  
    115     /** 
    116      *  @todo Document this method 
    117      *  @param string   Type of select 
    118      *  @param string[] Options to appear in the select 
    119      *  @param string    
     195 
     196        //    Check for minute component 
     197        if (array_key_exists($this->attribute_name."(5i)", 
     198                             $_REQUEST[$this->object_name])) { 
     199            $this->request_minutes[$this->attribute_name] = 
     200                $_REQUEST[$this->object_name][$this->attribute_name."(5i)"]; 
     201            $found = true; 
     202        }               
     203 
     204        //    Check for second component 
     205        if (array_key_exists($this->attribute_name."(6i)", 
     206                             $_REQUEST[$this->object_name])) { 
     207            $this->request_seconds[$this->attribute_name] = 
     208                $_REQUEST[$this->object_name][$this->attribute_name."(6i)"]; 
     209            $found = true; 
     210        }                                                                    
     211        return $found; 
     212    } 
     213 
     214    /** 
     215     *  Generate HTML/XML for select to enclose option list 
     216     * 
     217     *  @param string   Name attribute for <samp><select name=... ></samp> 
     218     *  @param string   <samp><option>...</option><samp> list 
     219     *  @param string   Prefix of name attribute, to be enclosed in 
     220     *                  square brackets 
    120221     *  @param boolean  Whether to include a blank in the list of 
    121222     *                  select options   
    122      *  @param boolean  Whether to ignore type 
     223     *  @param boolean  Whether to discard the type 
     224     *  @return string  Generated HTML 
    123225     */ 
    124226    private function select_html($type, $options, $prefix = null, 
     
    148250 
    149251    /** 
    150      * 
    151      *  @todo Document this method 
     252     *  Get attribute value from $_REQUEST if there, otherwise from database 
     253     * 
     254     *  When called, {@link $object_name} describes the 
     255     *  {@link ActiveRecord} subclass and {@link $attribute_name} 
     256     *  describes the attribute whose value is desired. 
     257     * 
     258     *  An attempt is made to find the value in $_REQUEST, where it 
     259     *  would be found after the browser POSTed a form.  If no value 
     260     *  is found there, then the database is accessed for the value. 
     261     *  When accessing the database, the assumption is made that the 
     262     *  {@link ActionController} object refers to a single 
     263     *  {@link ActiveRecord} subclass object which correctly 
     264     *  identifies the table and record containing the attribute 
     265     *  value. 
     266     *  @return mixed Attribute value if found 
     267     *  @uses check_request_for_value() 
     268     *  @uses attribute_name 
     269     *  @uses object() 
     270     *  @uses ActiveRecord::send() 
    152271     */ 
    153272    protected function value() { 
     273        //error_log("DateHelper::value()  object name={$this->object_name}" 
     274        //          . "   attribute name={$this->attribute_name}"); 
     275 
     276        //  First try to get attribute value from $_REQUEST 
    154277        if(!$value = $this->check_request_for_value()) { 
     278 
     279            //  Value not found in $_REQUEST so we need to 
     280            //  go to the database.  Assume that the controller 
     281            //  points to the right ActiveRecord object 
    155282            $object = $this->object(); 
    156283            if(is_object($object) && $this->attribute_name) { 
     
    162289     
    163290    /** 
    164      *  @todo Document this method 
     291     *  Call to_expiration_date_select_tag() 
     292     * 
     293     *  Alias for {@link to_expiration_date_select_tag()} 
     294     *  @param mixed[]  Output format options 
     295     *  @return string Generated HTML 
     296     *  @uses to_expiration_date_select_tag() 
    165297     */ 
    166298    function expiration_date_select($options = array()) { 
     
    169301         
    170302    /** 
    171      *   datetime_select("post", "written_on") 
    172      *   datetime_select("post", "written_on", array("start_year" => 1995)) 
    173      *  @todo Document this method 
     303     *  Call to_datetime_select_tag() 
     304     * 
     305     *  Alias for {@link to_datetime_select_tag()} 
     306     *  @param mixed[]  Output format options 
     307     *  @return string Generated HTML 
     308     *  @uses to_datetime_select_tag() 
    174309     */ 
    175310    function datetime_select($options = array()) {      
     
    178313     
    179314    /** 
    180      *   datetime_select("post", "written_on") 
    181      *   datetime_select("post", "written_on", array("start_year" => 1995)) 
    182      *  @todo Document this method 
     315     *  Call to_date_select_tag() 
     316     * 
     317     *  Alias for {@link to_date_select_tag()} 
     318     *  @param mixed[]  Output format options 
     319     *  @return string Generated HTML 
     320     *  @uses to_date_select_tag() 
    183321     */ 
    184322    function date_select($options = array()) {    
     323        //error_log("date_select() object=$this->object_name" 
     324        //          . "   attribute=$this->attribute_name"); 
    185325        return $this->to_date_select_tag($options); 
    186326    }   
    187327     
    188328    /** 
    189      *  @todo Document this method 
    190      *  @uses select_html 
     329     *  Generate HTML/XML for expiration month and year selector 
     330     *  pulldowns 
     331     * 
     332     *  Generates HTML for a month and year pulldown.  The year 
     333     *  pulldown has a range of years from the initially selected year 
     334     *  to seven years after. 
     335     * 
     336     *  When called, $_REQUEST[] may have initial date values in 
     337     *  fields with default names of 'expiration_month' and 
     338     *  'expiration_year'.  If these values exist they override the 
     339     *  first parameter. 
     340     *  @param string   Date to display as initially selected if none 
     341     *    was found in $_REQUEST[].  If omitted, default value is the 
     342     *    current calendar date.<b>FIXME:</b> this doesn't work 
     343     *  @param mixed[]  Output format options: 
     344     *  <ul> 
     345     *    <li><samp>'field_seperator' => '</samp><i>somestring</i><samp>'</samp><br /> 
     346     *      String to insert between the month and year selectors.  If 
     347     *      none is specified, default value is <samp>' / '</samp></li> 
     348     *    <li><samp>'month_before_year' => 'false'<br /> 
     349     *      Output year selector first, then month selector. 
     350     *      If option not specified, the month selector will be output 
     351     *      first.</li> 
     352     *    <li><samp>'month_name' =>'</samp><i>somestring</i><samp>'</samp><br /> 
     353     *      Set the name of the generated month selector to 
     354     *      <i>somestring</i>.  If option not specified, default name is 
     355     *      <samp>expiration_month</samp></li> 
     356     *    <li><samp>'year_name' => '</samp><i>somestring</i><samp>'</samp><br /> 
     357     *      Set the name of the generated year selector to 
     358     *      <i>somestring</i>.  If option not specified, default name is 
     359     *      <samp>expiration_year</samp></li> 
     360     *  </ul> 
     361     *  @return string Generated HTML 
     362     *  @uses select_html() 
     363     *  @uses select_month() 
     364     *  @uses select_year() 
    191365     */ 
    192366    function select_expiration_date($date = null, $options = array()) { 
     367//        error_log("select_expiration_date('" 
     368//                  . (is_null($date) ? 'null' : $date) 
     369//                  ."', " . var_export($options,true)); 
    193370        $options['month_before_year'] = true;       
    194371        $options['use_month_numbers'] = true;    
     
    196373        $options['end_year'] = date("Y") + 7; 
    197374        $options['field_seperator'] = " / ";         
    198         $options['field_name'] = $options['year_name'] ? $options['year_name'] : "expiration_year";  
    199         $date = ($_REQUEST[$options['field_name']]) ? date("Y-m-d", strtotime($_REQUEST[$options['field_name']]."-01-01")) : date("Y-m-d"); 
     375 
     376        //  Find name and initial value of year field, 
     377        //  then generate year selector pulldown 
     378        $options['field_name'] = array_key_exists('year_name',$options) 
     379            ? $options['year_name'] : "expiration_year";  
     380        $date = array_key_exists($options['field_name'], $_REQUEST) 
     381            ? date("Y-m-d", 
     382                   strtotime($_REQUEST[$options['field_name']]."-01-01")) 
     383            : date("Y-m-d"); 
    200384        $year_select = $this->select_year($date, $options); 
    201         $options['field_name'] = $options['month_name'] ? $options['month_name'] : "expiration_month"; 
    202         $date = ($_REQUEST[$options['field_name']]) ? date("Y-m-d", strtotime("2006-".$_REQUEST[$options['field_name']]."-01")) : date("Y-m-d"); 
     385 
     386        //  Find name and initial value of month field, 
     387        //  then generate year selector pulldown 
     388        $options['field_name'] = array_key_exists('month_name',$options) 
     389            ? $options['month_name'] : "expiration_month"; 
     390        $date = array_key_exists($options['field_name'], $_REQUEST) 
     391            ? date("Y-m-d", 
     392                   strtotime("2006-".$_REQUEST[$options['field_name']]."-01")) 
     393            : date("Y-m-d"); 
    203394        $month_select = $this->select_month($date, $options); 
     395 
     396        //  Output month and year selectors in desired order 
    204397        if($options['month_before_year']) { 
    205             $select_html =  $month_select . $options['field_seperator'] .  $year_select;      
     398            $select_html =  $month_select . $options['field_seperator'] 
     399                .  $year_select;      
    206400        } else { 
    207             $select_html =  $year_select . $options['field_seperator'] .  $month_select; 
     401            $select_html =  $year_select . $options['field_seperator'] 
     402                .  $month_select; 
    208403        } 
    209404        return $select_html; 
     
    211406 
    212407    /** 
    213      * Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. 
    214      *  @todo Document this method 
     408     *  Generate HTML/XML for year, month and day selector pull-down menus 
     409     * 
     410     *  Returns <samp><select>...</select></samp> HTML with options 
     411     *  for a number of years, months and days.  The first argument, 
     412     *  if present, specifies the initially selected date.  The second 
     413     *  argument controls the format of the generated HTML. 
     414     * 
     415     *  Examples: 
     416     *  <ul> 
     417     *   <li><samp>select_date();</samp><br /> Generates a group of 
     418     *     three pulldown menus in the order year, month and day with 
     419     *     the current date initially selected.</li>  
     420     *   <li> 
     421     *  <samp>select_date('August 4, 1998');</samp><br /> Generates a 
     422     *    group of   three pulldown menus in the order year, month and 
     423     *    day with the date August 4, 1998 initially selected.</li>  
     424     *  </ul> 
     425     * 
     426     *  @param string   Date to display as initially selected if none 
     427     *    was found in 
     428     *    {@link $request_years}[{@link $attribute_name}], 
     429     *    {@link $request_months}[{@link $attribute_name}] and 
     430     *    {@link $request_days}[{@link $attribute_name}]. 
     431     *    Character string is any US English date representation 
     432     *    supported by {@link strtotime()}.  If omitted, the 
     433     *    current date is initially selected. 
     434     * 
     435     *  @param mixed[] Output format options are all of the options of 
     436     *    {@link select_year()}, {@link select_month()} and 
     437     *    {@link select_day()}. 
     438     *  @return string  Generated HTML 
     439     *  @uses select_day() 
     440     *  @uses select_month() 
     441     *  @uses select_year() 
    215442     */ 
    216443    function select_date($date = null, $options = array()) { 
     
    222449 
    223450    /** 
    224      * Returns a set of html select-tags (one for year, month, day, hour, and minute) preselected the +datetime+. 
    225      *  @todo Document this method 
     451     *  Generate HTML/XML for year-month-day-hour-minute selector pulldowns 
     452     * 
     453     *  Returns <samp><select>...</select></samp> HTML with options 
     454     *  for a number of years, months, days, hours and minutes.  The 
     455     *  first argument, if present, specifies the initially selected 
     456     *  date.  The second argument controls the format of the 
     457     *  generated HTML. 
     458     * 
     459     *  Examples: 
     460     *  <ul> 
     461     *   <li><samp>select_datetime();</samp><br /> Generates a group of 
     462     *     five pulldown menus in the order year, month, day, hour and 
     463     *     minute with the current date and time initially 
     464     *    selected.</li>  
     465     *   <li> 
     466     *  <samp>select_datetime('1998-04-08 13:21:17');</samp><br /> 
     467     *    Generates a group of five pulldown menus in the order year, 
     468     *    month, day, hour and minute with the date/time 
     469     *    1998 August 4 13:21 initially selected.</li>  
     470     *  </ul> 
     471     * 
     472     *  @param string   Date/time to display as initially selected. 
     473     *    Character string is any US English date representation 
     474     *    supported by {@link strtotime()}.  If omitted, the 
     475     *    current date/time is initially selected. 
     476     * 
     477     *  @param mixed[] Output format options are all of the options of 
     478     *    {@link select_year()}, {@link select_month()}, 
     479     *    {@link select_day()}, {@link select_hour()} and 
     480     *    {@link select_minute()}.  
     481     *  @return string  Generated HTML 
     482     *  @uses select_day() 
     483     *  @uses select_hour() 
     484     *  @uses select_minute() 
     485     *  @uses select_month() 
     486     *  @uses select_year() 
    226487     */ 
    227488    function select_datetime($datetime = null, $options = array()) { 
     
    235496 
    236497    /** 
    237      * Returns a set of html select-tags (one for hour and minute) 
    238      *  @todo Document this method 
     498     *  Generate HTML/XML for hour, minute and second selector pull-down menus 
     499     * 
     500     *  Returns <samp><select>...</select></samp> HTML with options 
     501     *  for a number of hours, minutes and seconds.  The first argument, 
     502     *  if present, specifies the initially selected time.  The second 
     503     *  argument controls the format of the generated HTML. 
     504     * 
     505     *  Examples: 
     506     *  <ul> 
     507     *   <li><samp>select_time();</samp><br /> Generates two pulldown 
     508     *     menus in the order hour : minute with 
     509     *     the current time initially selected.</li>  
     510     *   <li> 
     511     *  <samp>select_time('August 4, 1998 8:12');</samp><br /> Generates 
     512     *    two pulldown menus in the order hour : minute with the  
     513     *    time 8:12 initially selected.</li>  
     514     *  </ul> 
     515     * 
     516     *  @param string   Time to display as initially selected if none 
     517     *    was found in 
     518     *    {@link $request_hours}[{@link $attribute_name}], 
     519     *    {@link $request_minutes}[{@link $attribute_name}] and 
     520     *    {@link $request_seconds}[{@link $attribute_name}]. 
     521     *    Character string is any US English date/time representation 
     522     *    supported by {@link strtotime()}.  If omitted, the 
     523     *    current time is initially selected. 
     524     * 
     525     *  @param mixed[] Output format options are all of the options of 
     526     *    {@link select_hour()}, {@link select_minute()} and 
     527     *    {@link select_second()}. 
     528     *  @return string  Generated HTML 
     529     *  @uses select_hour() 
     530     *  @uses select_minute() 
     531     *  @uses select_second() 
    239532     */ 
    240533    function select_time($datetime = null, $options = array()) { 
    241534        $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; 
    242535        return $this->select_hour($datetime, $options) . 
    243                $this->select_minute(datetime, options) . 
    244                ($options['include_seconds'] ? $this->select_second($datetime, $options) : ''); 
    245     } 
    246  
    247     /** 
    248      *  Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. 
    249      *  The <tt>second</tt> can also be substituted for a second number. 
    250      *  Override the field name using the <tt>:field_name</tt> option, 'second' by default. 
    251      *  @todo Document this method 
    252      *  @uses select_html 
    253      */ 
    254     function select_second($datetime, $options = array()) { 
     536               $this->select_minute($datetime, $options) . 
     537            (array_key_exists('include_seconds', $options) 
     538             && $options['include_seconds'] 
     539             ? $this->select_second($datetime, $options) : ''); 
     540    } 
     541 
     542    /** 
     543     *  Generate HTML/XML for second selector pull-down menu 
     544     * 
     545     *  Returns <samp><select>...</select></samp> HTML with an option 
     546     *  for each of the sixty seconds.  The first argument, if 
     547     *  present, specifies the initially selected second.  The second 
     548     *  argument controls the format of the generated HTML. 
     549     * 
     550     *  Examples: 
     551     *  <ul> 
     552     *   <li><samp>select_second();</samp><br /> 
     553     *     Generates menu '00', '01', ..., '59'.  Initially selected 
     554     *     second is the second in 
     555     *     {@link $request_seconds}[{@link $attribute_name}], or if that 
     556     *     is not defined, the current second.</li> 
     557     *   <li><samp>select_second(null,array('include_blank' => true));</samp> 
     558     *    <br />Generates menu ' ', '00', '01',..., '59'.  Initially 
     559     *    selected second same as above.</li> 
     560     *  </ul> 
     561     * 
     562     *  @param string  Initially selected second as two-digit number. 
     563     *  If a value for this field is specified in 
     564     *  {@link $request_seconds}[{@link $attribute_name}], then that second 
     565     *  is initially selected regardless of the value of this argument. 
     566     *  Otherwise, if the first argument is present and is a character 
     567     *  string of two decimal digits with a value in the range 
     568     *  '00'..'59' then that second is initially selected.  If this 
     569     *  argument is absent or invalid, the current second is 
     570     *  initially selected. 
     571     *  @param mixed[] Output format options: 
     572     *  <ul> 
     573     *    <li><samp>'include_blank' => true</samp> Show a blank 
     574     *      as the first option.</li> 
     575     *    <li><samp>'field_name' => '</samp><i>somestring</i><samp>'</samp> 
     576     *      Generate output<br /> 
     577     *      <samp><select name="</samp><i>somestring</i><samp>">...</select></samp> . 
     578     *      <br />If absent, generate output<br /> 
     579     *      <samp><select name="second">...</select></samp>.</li> 
     580     *    <li><samp>'discard_type' => ???</samp> FIXME</li> 
     581     *    <li><samp>'prefix' => ???</samp> FIXME</li> 
     582     *  </ul> 
     583     * 
     584     *  @return string  Generated HTML 
     585     *  @uses attribute_name 
     586     *  @uses leading_zero_on_single_digits() 
     587     *  @uses request_seconds 
     588     *  @uses select_html() 
     589     */ 
     590    function select_second($datetime=null, $options = array()) { 
     591        //error_log("select_second() \$datetime=$datetime  \$options=" 
     592        //          .var_export($options,true)); 
    255593        $second_options = ""; 
    256594         
     
    269607            "<option value=\"".$this->leading_zero_on_single_digits($second)."\">".$this->leading_zero_on_single_digits($second)."</option>\n"; 
    270608        } 
    271         $field_name = ($options['field_name']) ? $options['field_name'] : 'second'; 
    272         return $this->select_html($field_name, $second_options, $options['prefix'], $options['include_blank'], $options['discard_type']); 
    273     } 
    274  
    275     /** 
    276      *  Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. 
    277      *  Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected 
    278      *  The <tt>minute</tt> can also be substituted for a minute number. 
    279      *  Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 
    280      *  @todo Document this method 
    281      *  @uses select_html 
    282      */ 
    283     function select_minute($datetime, $options = array()) { 
     609        $field_name = array_key_exists('field_name',$options) 
     610                       ? $options['field_name'] : 'second'; 
     611        return $this->select_html($field_name, $second_options, 
     612                                  array_key_exists('prefix',$options) 
     613                                  ? $options['prefix'] : null, 
     614                                  array_key_exists('include_blank',$options) 
     615                                  ? $options['include_blank'] : false, 
     616                                  array_key_exists('discard_type',$options) 
     617                                  ? $options['discard_type'] : false); 
     618    } 
     619 
     620    /** 
     621     *  Generate HTML/XML for minute selector pull-down menu 
     622     * 
     623     *  Returns <samp><select>...</select></samp> HTML with an option 
     624     *  for each of the sixty minutes.  The first argument, if 
     625     *  present, specifies the initially selected minute.  The second 
     626     *  argument controls the format of the generated HTML. 
     627     * 
     628     *  Examples: 
     629     *  <ul> 
     630     *   <li><samp>select_minute();</samp><br /> 
     631     *     Generates menu '00', '01', ..., '59'.  Initially selected 
     632     *     minute is the minute in 
     633     *     {@link $request_minutes}[{@link $attribute_name}], or if that 
     634     *     is not defined, the current minute.</li> 
     635     *   <li><samp>select_minute(null,array('include_blank' => true));</samp> 
     636     *    <br />Generates menu ' ', '00', '01',..., '59'.  Initially 
     637     *    selected minute same as above.</li> 
     638     *  </ul> 
     639     * 
     640     *  @param string  Initially selected minute as two-digit number. 
     641     *  If a value for this field is specified in 
     642     *  {@link $request_minutes}[{@link $attribute_name}], then that minute 
     643     *  is initially selected regardless of the value of this argument. 
     644     *  Otherwise, if the first argument is present and is a character 
     645     *  string of two decimal digits with a value in the range 
     646     *  '00'..'59' then that minute is initially selected.  If this 
     647     *  argument is absent or invalid, the current minute is 
     648     *  initially selected. 
     649     *  @param mixed[] Output format options: 
     650     *  <ul> 
     651     *    <li><samp>'include_blank' => true</samp> Show a blank 
     652     *      as the first option.</li> 
     653     *    <li><samp>'field_name' => '</samp><i>somestring</i><samp>'</samp> 
     654     *      Generate output<br /> 
     655     *      <samp><select name="</samp><i>somestring</i><samp>">...</select></samp> . 
     656     *      <br />If absent, generate output<br /> 
     657     *      <samp><select name="minute">...</select></samp>.</li> 
     658     *    <li><samp>'discard_type' => ???</samp> FIXME</li> 
     659     *    <li><samp>'prefix' => ???</samp> FIXME</li> 
     660     *  </ul> 
     661     * 
     662     *  @return string  Generated HTML 
     663     *  @uses attribute_name 
     664     *  @uses leading_zero_on_single_digits() 
     665     *  @uses request_minutes 
     666     *  @uses select_html() 
     667     */ 
     668    function select_minute($datetime=null, $options = array()) { 
    284669        $minute_options = ""; 
    285670         
     
    298683            "<option value=\"".$this->leading_zero_on_single_digits($minute)."\">".$this->leading_zero_on_single_digits($minute)."</option>\n"; 
    299684        } 
    300         $field_name = ($options['field_name']) ? $options['field_name'] : 'minute'; 
    301         return $this->select_html($field_name, $minute_options, $options['prefix'], $options['include_blank'], $options['discard_type']); 
    302     } 
    303  
    304     /** 
    305      *  Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. 
    306      *  The <tt>hour</tt> can also be substituted for a hour number. 
    307      *  Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 
    308      *  @todo Document this method 
    309      *  @uses select_html 
    310      */ 
    311     function select_hour($datetime, $options = array()) { 
     685        $field_name = array_key_exists('field_name', $options) 
     686            ? $options['field_name'] : 'minute'; 
     687        return $this->select_html($field_name, $minute_options, 
     688                                  array_key_exists('prefix', $options) 
     689                                  ? $options['prefix'] : null, 
     690                                  array_key_exists('include_blank', $options) 
     691                                  ? $options['include_blank'] : false, 
     692                                  array_key_exists('discard_type', $options) 
     693                                  ? $options['discard_type'] : false); 
     694    } 
     695 
     696    /** 
     697     *  Generate HTML/XML for hour selector pull-down menu 
     698     * 
     699     *  Returns <samp><select>...</select></samp> HTML with an option 
     700     *  for each of the twenty-four hours.  The first argument, if 
     701     *  present, specifies the initially selected hour.  The second 
     702     *  argument controls the format of the generated HTML. 
     703     * 
     704     *  Examples: 
     705     *  <ul> 
     706     *   <li><samp>select_hour();</samp><br /> 
     707     *     Generates menu '00', '01', ..., '23'.  Initially selected 
     708     *     hour is the hour in 
     709     *     {@link $request_hours}[{@link $attribute_name}], or if that 
     710     *     is not defined, the current hour.</li> 
     711     *   <li><samp>select_hour(null,array('include_blank' => true));</samp> 
     712     *    <br />Generates menu ' ', '00', '01',..., '23'.  Initially 
     713     *    selected hour same as above.</li> 
     714     *  </ul> 
     715     * 
     716     *  @param string  Initially selected hour as two-digit number. 
     717     *  If a value for this field is specified in 
     718     *  {@link $request_hours}[{@link $attribute_name}], then that hour 
     719     *  is initially selected regardless of the value of this argument. 
     720     *  Otherwise, if the first argument is present and is a character 
     721     *  string of two decimal digits with a value in the range 
     722     *  '00'..'23' then that hour is initially selected.  If this 
     723     *  argument is absent or invalid, the current hour is 
     724     *  initially selected. 
     725     *  @param mixed[] Output format options: 
     726     *  <ul> 
     727     *    <li><samp>'include_blank' => true</samp> Show a blank 
     728     *      as the first option.</li> 
     729     *    <li><samp>'field_name' => '</samp><i>somestring</i><samp>'</samp> 
     730     *      Generate output<br /> 
     731     *      <samp><select name="</samp><i>somestring</i><samp>">...</select></samp> . 
     732     *      <br />If absent, generate output<br /> 
     733     *      <samp><select name="hour">...</select></samp>.</li> 
     734     *    <li><samp>'discard_type' => ???</samp> FIXME</li> 
     735     *    <li><samp>'prefix' => ???</samp> FIXME</li> 
     736     *  </ul> 
     737     * 
     738     *  @return string  Generated HTML 
     739     *  @uses attribute_name 
     740     *  @uses leading_zero_on_single_digits() 
     741     *  @uses request_hours 
     742     *  @uses select_html() 
     743     */ 
     744    function select_hour($datetime=null, $options = array()) { 
     745        //error_log("DateTime::select_hour() \$datetime=$datetime \$options=" 
     746        //          .var_export($options,true)); 
    312747        $hour_options = ""; 
    313748         
     749        //  If a value for this attribute was parsed from $_REQUEST, 
     750        //  use it as initially selected and ignore first argument 
    314751        if($this->request_hours[$this->attribute_name]) { 
    315752            $datetime_hour = $this->request_hours[$this->attribute_name];     
    316         } elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 
     753        } 
     754 
     755        //  No value in $_REQUEST so look at the first argument. 
     756        //  If it is valid use it as initially selected 
     757        elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 
    317758            $datetime_hour = $datetime; 
    318         } else {                   
     759        } 
     760 
     761        //  First argument is missing or invalid, 
     762        //  initially select current hour 
     763        else {                   
    319764            $datetime = $datetime ? $datetime : date("Y-m-d H:i:s");  
    320765            $datetime_hour = date("H",strtotime($datetime));  
    321766        } 
    322767 
     768        //  Generate <option>...</option> HTML for each hour 
    323769        for($hour = 0; $hour <= 23; $hour++) { 
    324              
    325770            $hour_options .= ($datetime && ($datetime_hour == $hour)) ? 
    326771            "<option value=\"".$this->leading_zero_on_single_digits($hour)."\"  selected=\"selected\">".$this->leading_zero_on_single_digits($hour)."</option>\n" : 
    327772            "<option value=\"".$this->leading_zero_on_single_digits($hour)."\">".$this->leading_zero_on_single_digits($hour)."</option>\n"; 
    328773        } 
    329         $field_name = ($options['field_name']) ? $options['field_name'] : 'hour'; 
    330         return $this->select_html($field_name, $hour_options, $options['prefix'], $options['include_blank'], $options['discard_type']); 
    331     } 
    332  
    333     /** 
    334      *  Returns a select tag with options for each of the days 1 through 31 with the current day selected. 
    335      *  The <tt>date</tt> can also be substituted for a hour number. 
    336      *  Override the field name using the <tt>:field_name</tt> option, 'day' by default. 
    337      *  @todo Document this method 
    338      *  @uses leading_zero_on_single_digits 
     774 
     775        //  Return finished HTML 
     776        $field_name = array_key_exists('field_name', $options) 
     777            ? $options['field_name'] : 'hour'; 
     778        return $this->select_html($field_name, $hour_options, 
     779                                  array_key_exists('prefix', $options) 
     780                                  ? $options['prefix'] : null, 
     781                                  array_key_exists('include_blank', $options) 
     782                                  ? $options['include_blank'] : false, 
     783                                  array_key_exists('discard_type', $options) 
     784                                  ? $options['discard_type'] : false); 
     785    } 
     786 
     787    /** 
     788     *  Generate HTML/XML for day selector pull-down menu 
     789     * 
     790     *  Returns <samp><select>...</select></samp> HTML with an option 
     791     *  for each of the thirty-one days.  The first argument, if 
     792     *  present, specifies the initially selected day.  The second 
     793     *  argument controls the format of the generated HTML. 
     794     * 
     795     * 
     796     *  Examples: 
     797     *  <ul> 
     798     *   <li><samp>select_day();</samp><br /> 
     799     *     Generates menu '01', '02', ..., '31'.  Initially selected 
     800     *     day is the day in 
     801     *     {@link $request_days}[{@link $attribute_name}], or if that 
     802     *     is not defined, the current calendar day.</li> 
     803     *   <li><samp>select_day(null,array('include_blank' => true));</samp> 
     804     *    <br />Generates menu ' ', '01', '02',..., '31'.  Initially 
     805     *    selected day same as above.</li> 
     806     *  </ul> 
     807     * 
     808     *  @param string  Initially selected day as two-digit number. 
     809     *  If a value for this field is specified in 
     810     *  {@link $request_days}[{@link $attribute_name}], then that day 
     811     *  is initially selected regardless of the value of this argument. 
     812     *  Otherwise, if the first argument is present and is a character 
     813     *  string of two decimal digits with a value in the range 
     814     *  '01'..'31' then that day is initially selected.  Otherwise, if 
     815     *  the first argument is a date in some US English date format, 
     816     *  the day of the month from that date is initially selected.  If 
     817     *  this argument is absent or invalid, the current calendar day 
     818     *  is initially selected. 
     819     *  @param mixed[] Output format options: 
     820     *  <ul> 
     821     *    <li><samp>'include_blank' => true</samp> Show a blank 
     822     *      as the first option.</li> 
     823     *    <li><samp>'field_name' => '</samp><i>somestring</i><samp>'</samp> 
     824     *      Generate output<br /> 
     825     *      <samp><select name="</samp><i>somestring</i><samp>">...</select></samp> . 
     826     *      <br />If absent, generate output<br /> 
     827     *      <samp><select name="day">...</select></samp>.</li> 
     828     *    <li><samp>'discard_type' => ???</samp> FIXME</li> 
     829     *    <li><samp>'prefix' => ???</samp> FIXME</li> 
     830     *  </ul> 
     831     * 
     832     *  @return string  Generated HTML 
     833     *  @uses attribute_name 
     834     *  @uses leading_zero_on_single_digits() 
    339835     *  @uses request_days 
    340      *  @uses select_html 
    341      */ 
    342     function select_day($datetime, $options = array()) { 
     836     *  @uses select_html() 
     837     */ 
     838    function select_day($datetime=null, $options = array()) { 
    343839        $day_options = ""; 
    344840         
     841        //  If a value for this attribute was parsed from $_REQUEST, 
     842        //  use it as initially selected and ignore first argument 
    345843        if($this->request_days[$this->attribute_name]) { 
    346844            $datetime_day = $this->request_days[$this->attribute_name];     
    347         } elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 
     845        } 
     846 
     847        //  No value in $_REQUEST so look at the first argument. 
     848        //  If it is valid use it as initially selected 
     849        elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 
    348850            $datetime_day = $datetime; 
    349         } else {                   
     851        } 
     852 
     853        //  First argument is missing or invalid, 
     854        //  initially select current day 
     855        else {                   
    350856            $datetime = $datetime ? $datetime : date("Y-m-d H:i:s");  
    351857            $datetime_day = date("d",strtotime($datetime));   
    352858        } 
    353859         
     860        //  Generate <option>...</option> HTML for each day 
    354861        for($day = 1; $day <= 31; $day++) {         
    355862            $day_options .= ($datetime && ($datetime_day == $day)) ? 
     
    357864            "<option value=\"".$this->leading_zero_on_single_digits($day)."\">".$this->leading_zero_on_single_digits($day)."</option>\n"; 
    358865        } 
     866 
     867        //  Return finished HTML 
    359868        $field_name = array_key_exists('field_name', $options) 
    360869            ? $options['field_name'] : 'day'; 
    361870        return $this->select_html($field_name, $day_options, 
    362                                   $options['prefix'], 
     871                                  array_key_exists('prefix',$options) 
     872                                  ? $options['prefix'] : null, 
    363873                                  array_key_exists('include_blank', $options) 
    364874                                  ? $options['include_blank'] : false, 
    365                                   $options['discard_type']); 
     875                                  array_key_exists('discard_type', $options) 
     876                                  ? $options['discard_type'] : false); 
    366877    } 
    367878 
     
    374885     *  argument controls the format of the generated HTML. 
    375886     * 
    376      *  <b>First argument: initially selected month</b> If a value for 
    377      *  this field is specified in 
    378      *  <samp>$_REQUEST[</samp><i>classname</i><samp>][</samp><i>attributename</i><samp>]</samp> 
    379      *  and <samp>$_REQUEST</samp> has been parsed by a previous call 
    380      *  to {@link check_request_for_value()}, then that month 
    381      *  is initially selected regardless of the argument value. 
     887     * 
     888     *  Examples: 
     889     *  <ul> 
     890     *   <li><samp>select_month();</samp> Generates menu January, 
     891     *    February etc.</li> 
     892     *   <li><samp>select_month(null,array('use_month_number' => true));</samp> 
     893     *    Generates menu 1, 2 etc.</li> 
     894     *   <li><samp>select_month(null,array('add_month_number' => true));</samp> 
     895     *    Generates menu 1 - January, 2 - February etc.</li> 
     896     *  </ul> 
     897     * 
     898     *  @param string  Initially selected month as two-digit number. 
     899     *  If a value for this field is specified in 
     900     *  {@link $request_months}[{@link $attribute_name}], then that month 
     901     *  is initially selected regardless of the value of this argument. 
    382902     *  Otherwise, if the first argument is present and is a character 
    383903     *  string of two decimal digits with a value in the range 
    384      *  '01'..'12' then that month is initially selected.  If this 
    385      *  argument is absent or invalid, the current calendar month is 
    386      *  initially selected. 
    387      * 
    388      *  <b>Second argument: output format</b> If omitted, visible 
    389      *  months are shown as 'January' through 'December'.  If  
    390      *  <samp>use_month_number</samp> is specified (as 
    391      *  <samp>array('use_month_number' => 1)</samp>) then the name of 
    392      *  the month is replaced by the month number.  If 
    393      *  <samp>add_month_number</samp> is specified the month number is 
    394      *  shown before the month name.  In all cases the value sent to 
    395      *  the server is the two digit month number in the range 
    396      *  '01'..'12'. 
    397      * 
    398      *  Other options:<br /> 
    399      *  <b>field_name</b> if present  (as 
    400      *  <samp>array('field_name' => 'somestring')</samp> generate<br /> 
    401      *  <samp><select name="somestring">...</samp> otherwise generate<br /> 
    402      *  <samp><select name="month">...</samp>.<br /> 
    403      *  <b>Also:</b> {@link select_html()} options. 
    404      * 
    405      *  Examples: 
    406      *  <ul> 
    407      *   <li><samp>select_month();</samp> Generates menu January, 
    408      *    February etc.</li> 
    409      *   <li><samp>select_month(null,array('use_month_number' => 1));</samp> 
    410      *    Generates menu 1, 2 etc.</li> 
    411      *   <li><samp>select_month(null,array('add_month_number' => 1));</samp> 
    412      *    Generates menu 1 - January, 2 - February etc.</li> 
    413      *  </ul> 
    414      * 
    415      *  @param string  Selected month as two-digit number 
    416      *  @param string[] Output format options 
     904     *  '01'..'12' then that month is initially selected.  Otherwise, 
     905     *  if the first argument is a date in some US English date 
     906     *  format, the month from that date is initially selected. If 
     907     *  this argument is absent or invalid, the current calendar month 
     908     *  is initially selected. 
     909     *  @param mixed[] Output format options: 
     910     *  <ul> 
     911     *    <li><samp>'include_blank' => true</samp> Show a blank 
     912     *      as the first option.</li> 
     913     *    <li><samp>'use_month_number' => true</samp> Show months in 
     914     *      the menu by their month number (1, 2 ...).  Default is to 
     915     *      show English month name (January, February ...).</li> 
     916     *    <li><samp>'add_month_number' => true</samp> Show both month 
     917     *      number and month name in the menu.</li> 
     918     *    <li><samp>'field_name' => '</samp><i>somestring</i><samp>'</samp> 
     919     *      Generate output<br /> 
     920     *      <samp><select name="</samp><i>somestring</i><samp>">...</select></samp> . 
     921     *      <br />If absent, generate output<br /> 
     922     *      <samp><select name="month">...</select></samp>.</li> 
     923     *    <li><samp>'discard_type' => ???</samp> FIXME</li> 
     924     *    <li><samp>'prefix' => ???</samp> FIXME</li> 
     925     *  </ul> 
     926     *  In all cases the value sent to the server is the two digit 
     927     *  month number in the range '01'..'12'. 
     928     * 
    417929     *  @return string  Generated HTML 
    418      *  @uses request_days 
     930     *  @uses attribute_name 
     931     *  @uses leading_zero_on_single_digits() 
    419932     *  @uses request_months 
    420933     *  @uses select_html 
    421934     */ 
    422935    function select_month($date = null, $options = array()) { 
    423         
    424936        $month_options = "";    // will accumulate <option>s 
    425937         
     
    437949        } 
    438950 
    439         //  First argument is missing or invalid, 
    440         //  initially select current month 
     951        //  Parse initially selected month from US English description 
     952        //  in first argument if present, otherwise select current month 
    441953        else { 
    442             $date_month = date("m",strtotime($date));     
     954            $date = $date ? $date : date("Y-m-d H:i:s");  
     955            $date_month = date("m",strtotime($date));   
    443956        } 
    444957    
     
    478991 
    479992    /** 
    480      * Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius 
    481      * can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year 
    482      * lists are supported by making <tt>:start_year</tt> less than or greater than <tt>:end_year</tt>. The <tt>date</tt> can also be 
    483      * substituted for a year given as a number. Example: 
    484      * 
    485      *   select_year(Date.today, :start_year => 1992, :end_year => 2007)  # ascending year values 
    486      *   select_year(Date.today, :start_year => 2005, :end_year => 1900)  # descending year values 
    487      * 
    488      * Override the field name using the <tt>:field_name</tt> option, 'year' by default. 
    489      *  @todo Document this method 
     993     *  Generate HTML/XML for year selector pull-down menu 
     994     * 
     995     *  Returns <samp><select>...</select></samp> HTML with options 
     996     *  for a number of years.  The first argument, if present, 
     997     *  specifies the initially selected year.  The second  
     998     *  argument controls the format of the generated HTML. 
     999     * 
     1000     *  Examples: 
     1001     *  <ul> 
     1002     *   <li><samp>select_year();</samp><br /> Generates a pulldown menu with 
     1003     *     with a range of +/- five years.  If a year is specified in 
     1004     *     {@link $request_years}[{@link $attribute_name}] then it is 
     1005     *     selected initially, otherwise the current calendar year is 
     1006     *     selected.</li>  
     1007     *   <li> 
     1008     *  <samp>select_year(null,array('start_year' => '1900));</samp><br /> 
     1009     *    Generates year options from 1900 to five years after the 
     1010     *    initially selected year, which is chosen as in the previous 
     1011     *    example.</li>  
     1012     *   <li><samp>select_year(null,array('start_year'=>date('Y')+5, 'end_year'=>date('Y')-5);</samp><br /> 
     1013     *    Generates year options starting five years after the current year, 
     1014     *    ending five years before the current year. 
     1015     *  </ul> 
     1016     * 
     1017     *  @param string   Year to display as initially selected if none 
     1018     *    was found in {@link $request_years}[{@link $attribute_name}]. 
     1019     *    Character string is either exactly four decimal 
     1020     *    digits or some English date representation.  If omitted, the 
     1021     *    current year is initially selected. 
     1022     * 
     1023     *  @param mixed[] Output format options: 
     1024     *  <ul> 
     1025     *    <li><samp>'start_year'=>'</samp><i>startyear</i><samp>'</samp> 
     1026     *      If specified, <i>startyear</i> will be the first year in 
     1027     *      the output menu, otherwise the first year in the menu will 
     1028     *      be five years before the initially selected year.</li> 
     1029     *    <li><samp>'end_year'=>'</samp><i>endyear</i><samp>'</samp> 
     1030     *      If specified, <i>endyear</i> will be the last year in 
     1031     *      the output menu, otherwise the last year in the menu will 
     1032     *      be five years after the initially selected year.</li> 
     1033     *    <li><samp>'field_name' => '</samp><i>somestring</i><samp>'</samp> 
     1034     *      Generate output<br /> 
     1035     *      <samp><select name="</samp><i>somestring</i><samp>">...</select></samp> . 
     1036     *      <br />If absent, generate output<br /> 
     1037     *      <samp><select name="year">...</select></samp>.</li> 
     1038     *    <li><samp>'discard_type' => ???</samp> FIXME</li> 
     1039     *    <li><samp>'prefix' => ???</samp> FIXME</li> 
     1040     *  </ul> 
     1041     *  To generate a list with most recent year first, define that 
     1042     *  year as the start year and the oldest year as the end year. 
     1043     *  @return string  Generated HTML 
     1044     *  @uses attribute_name 
     1045     *  @uses request_years 
    4901046     *  @uses select_html 
    491      */ 
    492     function select_year($date, $options = array()) { 
     1047     *  @uses year_option() 
     1048     */ 
     1049    function select_year($date=null, $options = array()) { 
     1050        //error_log("select_year('" . (is_null($date) ? 'null' : $date) 
     1051        //          ."', " . var_export($options,true)); 
     1052        //error_log('request_years=' 
     1053        //     .var_export($this->request_years[$this->attribute_name],true)); 
    4931054        $year_options = ""; 
    4941055 
     1056        //  Find the year to display. 
    4951057        if($this->request_years[$this->attribute_name]) { 
     1058 
     1059            //  There was a value for this attribute in $_REQUEST 
     1060            //  so display it as the initial choice 
    4961061            $date_year = $this->request_years[$this->attribute_name];     
    4971062        } elseif(strlen($date) == 4 && is_numeric($date)) { 
     1063 
     1064            //  The first argument is exactly four decimal digits 
     1065            //  so interpret that as a year 
    4981066            $date_year = $date;      
    4991067        } else { 
     1068 
     1069            //  If a first argument was specified, assume that it is 
     1070            //  some English date representation and convert it for 
     1071            //  use as the initial value. 
     1072            //  If first argument was null, use the current year for 
     1073            //  the initial value. 
    5001074            $date_year = $date ? date("Y",strtotime($date)) : date("Y"); 
    5011075        }  
    5021076 
    503         $start_year = ($options['start_year']) ? $options['start_year'] : $date_year - 5; 
    504         $end_year = ($options['end_year']) ? $options['end_year'] : $date_year + 5; 
    505  
    506         for($year = $start_year; $year <= $end_year; $year++) { 
    507             $year_options .= ($date && ($date_year == $year)) ? 
    508             "<option value=\"$year\" selected=\"selected\">$year</option>\n" : 
    509             "<option value=\"$year\">$year</option>\n"; 
    510         } 
    511  
    512         $field_name = ($options['field_name']) ? $options['field_name'] : 'year'; 
    513         return $this->select_html($field_name, $year_options, $options['prefix'], $options['include_blank'], $options['discard_type']); 
    514     } 
    515  
    516     /** 
    517      * 
    518      *  @todo Document this method 
     1077        //  Set first year to appear in the option list 
     1078        $start_year = array_key_exists('start_year',$options) 
     1079                       ? $options['start_year'] : $date_year - 5; 
     1080 
     1081        //  Set last year to appear in the option list 
     1082        $end_year = array_key_exists('end_year',$options) 
     1083                     ? $options['end_year'] : $date_year + 5; 
     1084 
     1085        if ($start_year < $end_year) { 
     1086            for($year = $start_year; $year <= $end_year; $year++) { 
     1087                $year_options .= $this->year_option($year, $date_year); 
     1088            } 
     1089        } else { 
     1090            for($year = $start_year; $year >= $end_year; $year--) { 
     1091                $year_options .= $this->year_option($year, $date_year); 
     1092            } 
     1093        } 
     1094 
     1095        $field_name = array_key_exists('field_name',$options) 
     1096                      ? $options['field_name'] : 'year'; 
     1097        return $this->select_html($field_name, $year_options, 
     1098                                  array_key_exists('prefix',$options) 
     1099                                  ? $options['prefix'] : null, 
     1100                                  array_key_exists('include_blank',$options) 
     1101                                  ? $options['include_blank'] : false, 
     1102                                  array_key_exists('discard_type',$options) 
     1103                                  ? $options['discard_type'] : false); 
     1104 
     1105    } 
     1106 
     1107    /** 
     1108     *  Return one HTML/XML year option, selected if so specified 
     1109     *  @param integer Year to put in the option 
     1110     *  @param integer Year that should be selected 
     1111     *  @return string HTML for one year option 
     1112     */ 
     1113    function year_option($year, $date_year) { 
     1114        return "<option value=\"$year\"" 
     1115            . (($date_year == $year) ? "  selected=\"selected\">" : ">") 
     1116            . "$year</option>\n"; 
     1117    } 
     1118 
     1119    /** 
     1120     *  Generate HTML/XML for day/month/year selector pull-down menus 
     1121     * 
     1122     *  When called, {@link $object_name} describes the 
     1123     *  {@link ActiveRecord} subclass and {@link $attribute_name} 
     1124     *  describes the attribute whose value will be set by the 
     1125     *  generated pull-down menus.  The value to be displayed 
     1126     *  initially in each menu is from $_REQUEST if present, otherwise 
     1127     *  from the database. 
     1128     * 
     1129     *  @param mixed[] Output format options 
     1130     *  <ul> 
     1131     *    <li><samp>'discard_day' => true</samp> Don't show a day of 
     1132     *      month menu. If absent or false, day menu will be output.</li> 
     1133     *    <li><samp>'discard_month' => true</samp> Don't show a month 
     1134     *      or day of the month menu.  If absent or false, month menu 
     1135     *      will be output.</li> 
     1136     *    <li><samp>'discard_type' => true</samp> (true is the  
     1137     *      default) Don't show name of individual field, for example 
     1138     *      <samp>[year]</samp>, as part of the <samp>name</samp> value 
     1139     *      of the generated <samp><select ...></samp>.  The 
     1140     *      information to identify the field is available as a suffix  
     1141     *      <samp>(</samp><i>n</i><samp>i)</samp> of the attribute 
     1142     *      name.</li>  
     1143     *    <li><samp>'discard_year' => true</samp> Don't show a year 
     1144     *      menu.  If absent or false, year menu will be output.</li> 
     1145     *    <li><samp>'field_seperator' => '</samp><i>string</i><samp>'</samp> 
     1146     *      String to insert between the submenus in the output.  If 
     1147     *      absent, one blank will be inserted.</li>  
     1148     *    <li><samp>'include_blank' => true</samp> Initially show a blank 
     1149     *      selection in the menu.  If absent or false, the current   
     1150     *      date will be shown as the initial selection.  If a value 
     1151     *      was parsed from $_REQUEST, it will be used for the initial 
     1152     *      selection regardless of this option.</li> 
     1153     *    <li><samp>'month_before_year' => true</samp>  Equivalent to 
     1154     *      <samp>'order' => array('month', 'day', 'year')</samp></li> 
     1155     *    <li><samp>'order' => array(</samp><i>elements</i><samp>)</samp> 
     1156     *      A list of the elements <samp>'month', 'day'</samp> and 
     1157     *      <samp>'year'</samp> in the order in which the menus should 
     1158     *      appear in the output. Default is 
     1159     *      <samp>'year', 'month', 'day'</samp></li> 
     1160     *    <li><b>Also:</b> options provided by {@link select_month()}, 
     1161     *      {@link select_day()} and {@link select_year()} 
     1162     *  </ul> 
     1163     *  @return string Generated HTML 
     1164     *  @uses select_day() 
     1165     *  @uses select_month() 
     1166     *  @uses select_year() 
     1167     *  @uses value() 
    5191168     */ 
    5201169    function to_date_select_tag($options = array()) { 
     1170//        error_log("to_date_select_tag() object='$this->object_name'" 
     1171//                  . " attribute='$this->attribute_name'"); 
     1172//        error_log("options=".var_export($options,true)); 
    5211173        $defaults = array('discard_type' => true); 
    5221174        $options  = array_merge($defaults, $options); 
    5231175        $options_with_prefix = array(); 
     1176 
     1177        //  Set the name of each submenu in the form 
    5241178        for($i=1 ; $i <= 3 ; $i++) { 
    525             $options_with_prefix[$i] = array_merge($options, array('prefix' => "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 
     1179            $options_with_prefix[$i] = array_merge($options, array('prefix' => 
     1180                  "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 
    5261181        }         
    5271182         
    528         if($options['include_blank']) { 
     1183        //  Test for output option 'include_blank' == true 
     1184        if(array_key_exists('include_blank', $options) 
     1185           && $options['include_blank']) { 
     1186 
     1187            //  'include_blank' is present so if no value for this 
     1188            //  attribute was parsed from $_REQUEST, show blank initially 
     1189            //  FIXME: this doesn't actually work 
    5291190            $value = $this->value(); 
    5301191            $date = $value ? $value : null; 
    5311192        } else { 
     1193 
     1194            //  'include_blank' is not present so if no value for this 
     1195            //  attribute was parsed from $_REQUEST, show today's date 
     1196            //  initially 
    5321197            $value = $this->value(); 
    5331198            $date = $value ? $value : date("Y-m-d"); 
    5341199        } 
    5351200 
     1201        //  Test for output option 'month_before_year' == true 
    5361202        $date_select = array(); 
    537         if($options['month_before_year']) { 
     1203        if(array_key_exists('month_before_year', $options) 
     1204           && $options['month_before_year']) { 
     1205 
     1206            //  'month_before_year' is present so set the default 
     1207            //  ordering of output menus accordingly 
    5381208            $options['order'] = array('month', 'year', 'day'); 
    539         } elseif(!$options['order']) { 
     1209        } elseif(!array_key_exists('order',$options) 
     1210                 ||!$options['order']) { 
     1211 
     1212            //  If 'order' option not present set order from default 
    5401213            $options['order'] = array('year', 'month', 'day'); 
    5411214        } 
     
    5431216        $position = array('year' => 1, 'month' => 2, 'day' => 3); 
    5441217 
     1218        //  Evaluate 'discard_field' options to see which fields 
     1219        //  should not be represented by menus in the output 
    5451220        $discard = array(); 
    546         if($options['discard_year']) $discard['year']  = true; 
    547         if($options['discard_month']) $discard['month'] = true; 
    548         if($options['discard_day'] || $options['discard_month']) $discard['day'] = true; 
    549  
     1221        if(array_key_exists('discard_year',$options) 
     1222           && $options['discard_year']) $discard['year']  = true; 
     1223        if(array_key_exists('discard_month',$options) 
     1224           && $options['discard_month']) $discard['month'] = true; 
     1225        if( (array_key_exists('discard_day',$options) 
     1226             &&$options['discard_day']) 
     1227            || (array_key_exists('discard_month',$options) 
     1228                && $options['discard_month'])) $discard['day'] = true; 
     1229 
     1230        //  Build HTML for menus in the order determined above, 
     1231        //  except for fields to be discarded. 
    5501232        foreach($options['order'] as $param) { 
    551             if(!$discard[$param]) { 
    552                 $date_select[] = call_user_func(array($this, "select_$param"),  $date, $options_with_prefix[$position[$param]]); 
     1233            if(!array_key_exists($param,$discard) || !$discard[$param]) { 
     1234                $date_select[] = call_user_func(array($this, "select_$param"), 
     1235                              $date, $options_with_prefix[$position[$param]]); 
    5531236            } 
    5541237        } 
    5551238         
     1239        //  HTML for each menu is in an element of $date_select[]. 
     1240        //  Join the pieces of HTML with an optional field separator 
     1241        //  (default blank) 
    5561242        if(count($date_select)) { 
    5571243            $seperator = array_key_exists('field_seperator',$options) 
     
    5641250 
    5651251    /** 
    566      * 
    567      *  @todo Document this method 
     1252     *  Generate HTML/XML for date/time pulldown menus 
     1253     * 
     1254     *  Returns <samp><select>...</select></samp> HTML with options 
     1255     *  for a number of years, months, days, hours and minutes.  The 
     1256     *  first argument, if present, specifies the initially selected 
     1257     *  date.  The second argument controls the format of the 
     1258     *  generated HTML. 
     1259     * 
     1260     *  Examples: 
     1261     *  <ul> 
     1262     *   <li><samp>to_datetime_select_tag();</samp><br /> Generates a 
     1263     *     group of five pulldown menus in the order year, month, day, 
     1264     *     hour and minute with the current date and time initially 
     1265     *     selected.</li>  
     1266     *   <li> 
     1267     *   <li><samp>to_datetime_select_tag(array('discard_second' => false);</samp><br /> 
     1268     *     Generates a group of six pulldown menus in the order year, 
     1269     *     month, day, hour, minute and second with the current date 
     1270     *     and time initially selected.</li>  
     1271     *   <li> 
     1272     *  <samp>to_datetime_select_tag('1998-04-08 13:21:17');</samp><br /> 
     1273     *    Generates a group of five pulldown menus in the order year, 
     1274     *    month, day, hour and minute with the date/time 
     1275     *    1998 August 4 13:21 initially selected.</li>  
     1276     *  </ul> 
     1277     * 
     1278     *  @param string   Date/time to display as initially selected. 
     1279     *    Character string is any US English date representation 
     1280     *    supported by {@link strtotime()}.  If omitted, the 
     1281     *    current date/time is initially selected. 
     1282     * 
     1283     *  @param mixed[] Output format options: 
     1284     *  <ul> 
     1285     *    <li><samp>'discard_month' => true</samp><br /> 
     1286     *      Output selector for only the year.</li> 
     1287     *    <li><samp>'discard_day' => true</samp><br /> 
     1288     *      Output selector for only the year and month.</li> 
     1289     *    <li><samp>'discard_hour' => true</samp><br /> 
     1290     *      Output selector for only the year, month and day.</li> 
     1291     *    <li><samp>'discard_minute' => true</samp><br /> 
     1292     *      Output selector for only the year, month, day and 
     1293     *      hour.</li>  
     1294     *    <li><samp>'discard_second' => false</samp><br /> 
     1295     *      Output selector for year, month, day, hour, minute and 
     1296     *      second.</li>  
     1297     *  </ul> 
     1298     *  @return string Generated HTML 
     1299     *  @uses request_days 
     1300     *  @uses request_hours 
     1301     *  @uses request_minutes 
     1302     *  @uses request_months 
     1303     *  @uses request_seconds 
     1304     *  @uses request_years 
     1305     *  @uses select_day() 
     1306     *  @uses select_hour() 
     1307     *  @uses select_minute() 
     1308     *  @uses select_month() 
     1309     *  @uses select_second() 
     1310     *  @uses select_year() 
     1311     *  @uses value() 
    5681312     */ 
    5691313    function to_datetime_select_tag($options = array()) { 
    570         $defaults = array('discard_type' => true); 
     1314        $defaults = array('discard_type'   => true, 
     1315                          'discard_second' => true); 
    5711316        $options = array_merge($defaults, $options); 
    5721317        $options_with_prefix = array(); 
    573         for($i=1 ; $i < 6 ; $i++) { 
    574             $options_with_prefix[$i] = array_merge($options, array('prefix' => "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 
    575         } 
    576  
    577         if($options['include_blank']) { 
     1318        for($i=1 ; $i <= 6 ; $i++) { 
     1319            $options_with_prefix[$i] = 
     1320                array_merge($options, array('prefix' => 
     1321                   "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 
     1322        } 
     1323 
     1324        //  FIXME: this doesn't work 
     1325        if(array_key_exists('include_blank', $options) 
     1326           && $options['include_blank']) { 
    5781327            $value = $this->value(); 
    5791328            $datetime = $value ? $value : null; 
     
    5831332        } 
    5841333     
    585         $datetime_select = $this->select_year($datetime, $options_with_prefix[1]); 
    586         if(!$options['discard_month']) 
    587             $datetime_select .= $this->select_month($datetime, $options_with_prefix[2]); 
    588         if(!($options['discard_day'] || $options['discard_month'])) 
    589             $datetime_select .= $this->select_day($datetime, $options_with_prefix[3]); 
    590         if(!$options['discard_hour']) 
    591             $datetime_select .= ' &mdash; ' . $this->select_hour($datetime, $options_with_prefix[4]); 
    592         if(!($options['discard_minute'] || $options['discard_hour'])) 
    593             $datetime_select .= ' : ' . $this->select_minute($datetime, $options_with_prefix[5]); 
    594  
     1334        //  Generate year pulldown 
     1335        $datetime_select = $this->select_year($datetime, 
     1336                                              $options_with_prefix[1]); 
     1337 
     1338        //  Generate month pulldown if not discarded 
     1339        if(!array_key_exists('discard_month', $options) 
     1340           || !$options['discard_month']) { 
     1341            $datetime_select .= $this->select_month($datetime, 
     1342                                                    $options_with_prefix[2]); 
     1343 
     1344            //  Generate day pulldown if not discarded 
     1345            if(!array_key_exists('discard_day', $options) 
     1346               || !($options['discard_day'] || $options['discard_month'])) { 
     1347                $datetime_select .= $this->select_day($datetime, 
     1348                                                      $options_with_prefix[3]); 
     1349 
     1350                //  Generate hour pulldown if not discarded 
     1351                if(!array_key_exists('discard_hour', $options) 
     1352                   || !$options['discard_hour']) { 
     1353                    $datetime_select .= ' &mdash; ' 
     1354                        . $this->select_hour($datetime, 
     1355                                         $options_with_prefix[4]); 
     1356 
     1357                    //  Generate minute pulldown if not discarded 
     1358                    if(!array_key_exists('discard_minute', $options) 
     1359                       || !$options['discard_minute']) { 
     1360                        $datetime_select .= ' : ' 
     1361                            . $this->select_minute($datetime, 
     1362                                                   $options_with_prefix[5]); 
     1363 
     1364                        //  Generate second pulldown if not discarded 
     1365                        if(!array_key_exists('discard_second', $options) 
     1366                           || !$options['discard_second']) { 
     1367                            $datetime_select .= ' : ' 
     1368                                . $this->select_second($datetime, 
     1369                                                    $options_with_prefix[6]); 
     1370                        }  // second 
     1371                    }      // minute 
     1372                }          // hour 
     1373            }              // day 
     1374        }                  // month 
    5951375        return $datetime_select; 
    5961376    } 
    5971377     
    5981378    /** 
    599      *  @todo Document this method 
     1379     *  Generate HTML/XML for expiration month and year pulldown. 
     1380     * 
     1381     *  Calls {@link to_date_select_tag()} with options for month with 
     1382     *  number, followed by year starting this year and going seven 
     1383     *  years in the future. 
     1384     *  @param mixed[] Output format options 
     1385     *  @return string Generated HTML 
     1386     *  @uses to_date_select_tag() 
    6001387     */ 
    6011388    function to_expiration_date_select_tag($options = array()) { 
     
    6091396    }   
    6101397 
     1398    /** 
     1399     *  Generate HTML/XML for time pulldown 
     1400     * 
     1401     *  When called, {@link $object_name} describes the 
     1402     *  {@link ActiveRecord} subclass and {@link $attribute_name} 
     1403     *  describes the attribute whose value will be set by the 
     1404     *  generated pull-down menu.  The value to be displayed initially 
     1405     *  is from $_REQUEST if present, otherwise from the database. 
     1406     * 
     1407     *  @param mixed[] Output format options 
     1408     *  @return string Generated HTML 
     1409     *  @uses request_hours 
     1410     *  @uses request_minutes 
     1411     *  @uses request_seconds 
     1412     *  @uses select_time() 
     1413     *  @uses value() 
     1414     */ 
     1415    function time_select($options=array()) { 
     1416        $defaults = array('discard_type' => true, 
     1417                          'discard_second' => true); 
     1418        $options = array_merge($defaults,$options); 
     1419        $options_with_prefix = array(); 
     1420        for($i=4 ; $i <= 6 ; $i++) { 
     1421            $options_with_prefix[$i] = 
     1422                array_merge($options, array('prefix' => 
     1423                 "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 
     1424        } 
     1425 
     1426        //  If no value for this attribute found in $_REQUEST 
     1427        //  or the model, show current time initially  
     1428        $time = $this->value(); 
     1429        $time = $time ? $time : date('H:i:s'); 
     1430 
     1431        //  Generate HTML for hour 
     1432        $time_select = $this->select_hour($time, $options_with_prefix[4]); 
     1433 
     1434        //  Generate HTML for minute if not discarded 
     1435        if (!(array_key_exists('discard_minute', $options) 
     1436              && $options['discard_minute'])) { 
     1437            $time_select .= ' : ' 
     1438                . $this->select_minute($time, $options_with_prefix[5]); 
     1439 
     1440            //  Generate HTML for second if not discarded 
     1441            if (!(array_key_exists('discard_second', $options) 
     1442                  && $options['discard_second'])) { 
     1443                $time_select .= ' : ' 
     1444                    . $this->select_second($time, $options_with_prefix[6]); 
     1445            } 
     1446        } 
     1447        return $time_select; 
     1448    } 
     1449 
     1450    /** 
     1451     *  Generate HTML/XML for year pulldown 
     1452     * 
     1453     *  When called, {@link $object_name} describes the 
     1454     *  {@link ActiveRecord} subclass and {@link $attribute_name} 
     1455     *  describes the attribute whose value will be set by the 
     1456     *  generated pull-down menu.  The value to be displayed initially 
     1457     *  is from $_REQUEST if present, otherwise from the database. 
     1458     * 
     1459     *  @param mixed[] Output format options 
     1460     *  @return string Generated HTML 
     1461     *  @uses select_year() 
     1462     *  @uses value() 
     1463     */ 
     1464    function year_select($options=array()) { 
     1465        $defaults = array('discard_type' => true, 
     1466             'prefix' => 
     1467                   "{$this->object_name}[{$this->attribute_name}(1i)]"); 
     1468        $options = array_merge($defaults,$options); 
     1469 
     1470        //  If no value for this attribute found in $_REQUEST 
     1471        //  or the model, show today's date initially  
     1472        $year = $this->value(); 
     1473        if (!$year) { 
     1474            $year = 
     1475            (is_array($this->request_years) 
     1476             && array_key_exists($this->attribute_name,$this->request_years)) 
     1477            ? $this->request_years[$this->attribute_name] 
     1478            : date("Y"); 
     1479        } 
     1480        return $this->select_year($year.'-01-01',$options); 
     1481    } 
    6111482} 
    6121483 
    6131484/** 
    614   *  Avialble functions for use in views 
    615   *  select_date($date = null, $options = array()) 
    616   *  @todo Document this function 
     1485 *  Make a new DateHelper object and call its select_date() method 
     1486 *  @uses DateHelper::select_date() 
    6171487  */ 
    6181488function select_date() { 
     
    6231493 
    6241494/** 
    625  *  Select_datetime($datetime = null, $options = array()) 
    626  *  @todo Document this function 
     1495 *  Make a new DateHelper object and call its select_datetime() method 
     1496 *  @uses DateHelper::select_datetime() 
    6271497 */ 
    6281498function select_datetime() { 
     
    6331503 
    6341504/** 
    635  * select_expiration_date($datetime = null, $options = array()) 
    636  *  @todo Document this function 
     1505 *  Make a new DateHelper object and call its select_expiration_date() method 
     1506 *  @uses DateHelper::select_expiration_date() 
    6371507 */ 
    6381508function select_expiration_date() { 
     
    6431513 
    6441514/** 
    645  * 
    646  *  @todo Document this function 
     1515 *  Make a new DateHelper object and call its datetime_select() method 
     1516 *  @param string Name of an ActiveRecord subclass 
     1517 *  @param string Name of an attribute of $object 
     1518 *  @param mixed[] Format options 
     1519 *  @uses DateHelper::datetime_select() 
     1520 *  @see ActiveRecordHelper::to_scaffold_tag() 
    6471521 */ 
    6481522function datetime_select($object, $attribute, $options = array()) { 
     
    6521526 
    6531527/** 
    654  * 
    655  *  @todo Document this function 
     1528 *  Make a new DateHelper object and call its date_select() method 
     1529 *  @param string Name of an ActiveRecord subclass 
     1530 *  @param string Name of an attribute of $object 
     1531 *  @param mixed[]  Output format options 
     1532 *  @return string Generated HTML 
     1533 *  @uses DateHelper::date_select() 
     1534 *  @see ActiveRecordHelper::to_scaffold_tag() 
    6561535 */ 
    6571536function date_select($object, $attribute, $options = array()) { 
     
    6611540 
    6621541/** 
    663  * 
    664  *  @todo Document this function 
     1542 *  Make a new DateHelper object and call its year_select() method 
     1543 *  @param string Name of an ActiveRecord subclass 
     1544 *  @param string Name of an attribute of $object 
     1545 *  @param mixed[] Format options 
     1546 *  @uses DateHelper::year_select() 
     1547 *  @see ActiveRecordHelper::to_scaffold_tag() 
     1548 */ 
     1549function year_select($object, $attribute, $options = array()) { 
     1550    $date_helper = new DateHelper($object, $attribute); 
     1551    return $date_helper->year_select($options);     
     1552} 
     1553 
     1554/** 
     1555 *  Make a new DateHelper object and call its select_time() method 
     1556 *  @param string Name of an ActiveRecord subclass 
     1557 *  @param string Name of an attribute of $object 
     1558 *  @param mixed[] Format options 
     1559 *  @uses DateHelper::select_time() 
     1560 *  @see ActiveRecordHelper::to_scaffold_tag() 
     1561 */ 
     1562function time_select($object, $attribute, $options = array()) { 
     1563    $date_helper = new DateHelper($object, $attribute); 
     1564    return $date_helper->time_select($options);     
     1565} 
     1566 
     1567/** 
     1568 *  Make a new DateHelper object and call its expiration_date_select() method 
     1569 *  @param string Name of an ActiveRecord subclass 
     1570 *  @param string Name of an attribute of $object 
     1571 *  @param mixed[] Format options 
     1572 *  @uses DateHelper::expiration_date_select() 
    6651573 */ 
    6661574function expiration_date_select($object, $attribute, $options = array()) { 
     
    6691577} 
    6701578 
    671  
    6721579/** 
     1580 *  Make a new DateHelper object and call its select_month() method 
    6731581 * 
    674  *  @todo Document this function 
    675  */ 
    676 function select_year() { 
    677     $date_helper = new DateHelper(); 
    678     $args = func_get_args(); 
    679     return call_user_func_array(array($date_helper, 'select_year'), $args);     
    680 } 
    681  
    682  
    683 /** 
    684  * 
    685  *  @todo Document this function 
     1582 *  Generate HTML/XML for month selector pull-down menu using only 
     1583 *  explicit month specification.<br /> 
     1584 *  <b>NB:</b>  An attempt to get value of an attribute will always 
     1585 *  fail because there is no way to set 
     1586 *  {@link DateHelper::object_name} and 
     1587 *  {@link DateHelper::attribute_name}. 
     1588 *  @uses DateHelper::select_month() 
    6861589 */ 
    6871590function select_month() { 
     
    6911594} 
    6921595 
    693  
    6941596/** 
    695  *  @todo Document this function 
     1597 *  Make a new DateHelper object and call its select_day() method 
     1598 *  @uses DateHelper::select_day() 
    6961599 */ 
    6971600function select_day() { 
  • trunk/trax/vendor/trax/action_view/helpers/form_options_helper.php

    r164 r198  
    8181 
    8282/** 
    83  * 
    84  *  @package PHPonTrax 
     83 *  @todo Document this class 
    8584 */ 
    8685class FormOptionsHelper extends FormHelper { 
    8786     
    8887    /** 
    89      *  Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container 
    90      *  where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and 
    91      *  the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values 
    92      *  become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag.  +Selected+ 
    93      *  may also be an array of values to be selected when using a multiple select. 
     88     *  Generate HTML option tags from a list of choices 
     89     * 
     90     *  Accepts an array of possible choices and returns a string of 
     91     *  option tags.  The value of each array element becomes the 
     92     *  visible text of an option, and the key of the element becomes 
     93     *  the value returned to the server.  For example:<br /> 
     94     *  <samp>options_for_select(array('foo','bar'));</samp><br /> 
     95     *  will return:<br /> 
     96     *  <samp><option value="0">foo</option>\n</samp><br /> 
     97     *  <samp><option value="1">bar</option></samp><br /> 
     98     * 
     99     *  The optional second argument specifies the array key of an 
     100     *  option to be initially selected. 
    94101     *  
    95      *  Examples (call, result): 
    96      *    options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) 
    97      *      <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> 
    98      *  
    99      *    options_for_select([ "VISA", "MasterCard" ], "MasterCard") 
    100      *      <option>VISA</option>\n<option selected="selected">MasterCard</option> 
    101      *  
    102      *    options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40") 
    103      *      <option value="$20">Basic</option>\n<option value="$40" selected="selected">Plus</option> 
    104      *  
    105      *    options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"]) 
    106      *      <option selected="selected">VISA</option>\n<option>MasterCard</option>\n<option selected="selected">Discover</option> 
    107      *  
    108      *  NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
     102     *  NOTE: Only the option tags are returned, you have to wrap this 
     103     *  call in a regular HTML select tag. 
     104     *  @param string[]  Choices 
     105     *  @param integer   Selected choice 
     106     *  @return string 
    109107     */ 
    110108    function options_for_select($choices, $selected = null) { 
     
    113111            foreach($choices as $choice_value => $choice_text) { 
    114112                if(!empty($choice_value)) { 
    115                     $is_selected = ($choice_value == $selected) ? true : false;    
     113                    $is_selected = ($choice_value == $selected) 
     114                        ? true : false;    
    116115                } else { 
    117                     $is_selected = ($choice_text == $selected) ? true : false;         
     116                    $is_selected = ($choice_text == $selected) 
     117                        ? true : false;         
    118118                } 
    119119                if($is_selected) { 
    120                     $options[] = "<option value=\"".htmlspecialchars($choice_value)."\" selected=\"selected\">".htmlspecialchars($choice_text)."</option>"; 
     120                    $options[] = "<option value=\"" 
     121              . htmlspecialchars($choice_value) 
     122              . "\" selected=\"selected\">" 
     123              . htmlspecialchars($choice_text)."</option>"; 
    121124                } else { 
    122                     $options[] = "<option value=\"".htmlspecialchars($choice_value)."\">".htmlspecialchars($choice_text)."</option>"; 
     125                    $options[] = "<option value=\"" 
     126              . htmlspecialchars($choice_value) 
     127              . "\">" 
     128              . htmlspecialchars($choice_text)."</option>"; 
    123129                }                         
    124130            }     
     
    128134     
    129135    /** 
    130      * Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the 
    131      * the result of a call to the +value_method+ as the option value and the +text_method+ as the option text. 
    132      * If +selected_value+ is specified, the element returning a match on +value_method+ will get the selected option tag. 
    133      * 
    134      * Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag: 
     136     *  Returns a string of option tags that have been compiled by 
     137     *  iterating over the +collection+ and assigning the result of a 
     138     *  call to the +value_method+ as the option value and the 
     139     *  +text_method+ as the option text. If +selected_value+ is 
     140     *  specified, the element returning a match on +value_method+ will 
     141     *  get the selected option tag.  
     142     * 
     143     *  Example (call, result). Imagine a loop iterating over each 
     144     *  +person+ in <tt>@project.people</tt> to generate an input tag:  
    135145     *   options_from_collection_for_select(@project.people, "id", "name") 
    136146     *     <option value="#{person.id}">#{person.name}</option> 
    137147     * 
    138      * NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
    139      */ 
    140     function options_from_collection_for_select($collection, $attribute_value, $attribute_text, $selected_value = null) { 
     148     *  NOTE: Only the option tags are returned, you have to wrap this call 
     149     *  in a regular HTML select tag.  
     150     *  @todo Document this method 
     151     */ 
     152    function options_from_collection_for_select($collection, $attribute_value, 
     153                                                $attribute_text, 
     154                                                $selected_value = null) { 
    141155        $options = array(); 
    142156        if(is_array($collection)) { 
    143157            foreach($collection as $object) { 
    144158                if(is_object($object)) { 
    145                     $options[$object->send($attribute_value)] = $object->send($attribute_text);             
     159                    $options[$object->send($attribute_value)] = 
     160                        $object->send($attribute_text);             
    146161                } 
    147162            }     
     
    151166     
    152167    /** 
    153      *  Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to 
    154      *  have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so 
    155      *  that they will be listed above the rest of the (long) list. 
    156      * 
    157      *  NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 
    158      */ 
    159     function country_options_for_select($selected = null, $priority_countries = array()) { 
     168     *  Generate HTML options for world countries 
     169     * 
     170     *  @param integer  Array key of country initially selected 
     171     *  NOTE: Only the option tags are returned, you have to wrap this 
     172     *  call in a regular HTML select tag. 
     173     *  @todo <b>FIXME:</b> Second argument doesn't work 
     174     */ 
     175    function country_options_for_select($selected = null, 
     176                    $priority_countries = array()) { 
    160177        $country_options = ""; 
    161178         
    162179        if(count($priority_countries)) { 
    163             $country_options .= $this->options_for_select($priority_countries, $selected); 
     180            $country_options .= $this->options_for_select($priority_countries, 
     181                              $selected); 
    164182            $country_options .= "<option value=\"\">-------------</option>\n"; 
    165183            foreach($priority_countries as $country) {  
    166                 unset($GLOBALS['COUNTRIES'][array_search($country, $GLOBALS['COUNTRIES'])]); 
     184                unset($GLOBALS['COUNTRIES'][array_search($country, 
     185                             $GLOBALS['COUNTRIES'])]); 
    167186            } 
    168187        } 
    169188         
    170         $country_options .= $this->options_for_select($GLOBALS['COUNTRIES'], $selected); 
     189        $country_options .= $this->options_for_select($GLOBALS['COUNTRIES'], 
     190                              $selected); 
    171191  
    172192        return $country_options; 
     
    174194     
    175195    /** 
    176      * 
     196     *  @todo Document this method 
     197     *  @uses add_default_name_and_id() 
     198     *  @uses add_options() 
     199     *  @uses content_tag() 
     200     *  @uses value() 
    177201     */ 
    178202    function to_select_tag($choices, $options, $html_options) { 
    179203        $html_options = $this->add_default_name_and_id($html_options); 
    180         return $this->content_tag("select", $this->add_options($this->options_for_select($choices, $this->value()), $options, $this->value()), $html_options); 
    181     } 
    182      
    183     /** 
    184      * 
    185      */ 
    186     function to_collection_select_tag($collection, $attribute_value, $attribute_text, $options, $html_options) { 
     204        return $this->content_tag( 
     205             "select", 
     206             $this->add_options( 
     207                       $this->options_for_select($choices, $this->value()), 
     208                       $options, 
     209                       $this->value()), 
     210             $html_options); 
     211    } 
     212     
     213    /** 
     214     *  @todo Document this method 
     215     * 
     216     *  @uses add_default_name_and_id() 
     217     *  @uses add_options() 
     218     *  @uses content_tag() 
     219     *  @uses options_from_collection_for_select() 
     220     *  @uses value() 
     221     */ 
     222    function to_collection_select_tag($collection, $attribute_value, 
     223                                      $attribute_text, $options, 
     224                                      $html_options) { 
    187225        $html_options = $this->add_default_name_and_id($html_options); 
    188         return $this->content_tag("select", $this->add_options($this->options_from_collection_for_select($collection, $attribute_value, $attribute_text, $this->value()), $options, $this->value()), $html_options); 
    189     } 
    190      
    191     /** 
    192      * 
    193      */ 
    194     function to_country_select_tag($priority_countries, $options, $html_options) { 
     226        return $this->content_tag( 
     227          "select", 
     228          $this->add_options( 
     229            $this->options_from_collection_for_select($collection, 
     230                                                      $attribute_value, 
     231                                                      $attribute_text, 
     232                                                      $this->value()), 
     233            $options, 
     234            $this->value()), 
     235         $html_options); 
     236    } 
     237     
     238    /** 
     239     *  @todo Document this method 
     240     * 
     241     *  @uses add_default_name_and_id() 
     242     *  @uses add_options() 
     243     *  @uses content_tag() 
     244     *  @uses value 
     245     */ 
     246    function to_country_select_tag($priority_countries, 
     247                                   $options, $html_options) { 
    195248        $html_options = $this->add_default_name_and_id($html_options); 
    196         return $this->content_tag("select", $this->add_options($this->country_options_for_select($this->value(), $priority_countries), $options, $this->value), $html_options); 
    197     } 
    198  
    199     /** 
    200      * 
     249        return $this->content_tag( 
     250                "select", 
     251                $this->add_options( 
     252                        $this->country_options_for_select($this->value(), 
     253                                                          $priority_countries), 
     254                        $options, 
     255                        $this->value), 
     256                $html_options); 
     257    } 
     258 
     259    /** 
     260     *  @todo Document this method 
     261     * 
     262     *  @param string 
     263     *  @param string[] 
     264     *  @param string 
     265     *  @todo <b>FIXME:</b> Why the third argument?  It's overwritten! 
     266     *  @uses value() 
    201267     */ 
    202268    private function add_options($option_tags, $options, $value = null) { 
    203         if($options["include_blank"] == true) { 
     269        if(array_key_exists("include_blank", $options) 
     270           && $options["include_blank"] == true) { 
    204271            $option_tags = "<option value=\"\"></option>\n" . $option_tags; 
    205272        }  
    206273        $value = $this->value(); 
    207         if(empty($value) && $options['prompt']) { 
     274        if(empty($value) && array_key_exists('prompt', $options)) { 
    208275            $text = $options['prompt'] ? $options['prompt'] : "Please select"; 
    209276            return ("<option value=\"\">$text</option>\n" . $option_tags); 
     
    215282 
    216283/** 
    217  * Avialble functions for use in views 
    218  * Create a select tag and a series of contained option tags for the provided object and method. 
    219  * The option currently held by the object will be selected, provided that the object is available. 
    220  * See options_for_select for the required format of the choices parameter. 
     284 *  Create a new FormOptionsHelper object and call its to_select_tag() method 
     285 * 
     286 *  Create a select tag and a series of contained option tags for the 
     287 *  provided object and method.  The option currently held by the 
     288 *  object will be selected, provided that the object is available.  
     289 *  See options_for_select for the required format of the choices parameter. 
    221290 * 
    222291 * Example with $post->person_id => 1: 
     
    237306 *   </select> 
    238307 * 
    239  * This can be used to provide a functionault set of options in the standard way: before r}ering the create form, a 
    240  * new model instance is assigned the functionault options and bound to @model_name. Usually this model is not saved 
    241  * to the database. Instead, a second model object is created when the create request is received. 
    242  * This allows the user to submit a form page more than once with the expected results of creating multiple records. 
    243  * In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. 
    244  */ 
    245 function select($object_name, $attribute_name, $choices, $options = array(), $html_options = array()) { 
     308 *  This can be used to provide a functionault set of options in the 
     309 *  standard way: before r}ering the create form, a new model instance 
     310 *  is assigned the functional options and bound to 
     311 *  @model_name. Usually this model is not saved to the 
     312 *  database. Instead, a second model object is created when the 
     313 *  create request is received.  This allows the user to submit a form 
     314 *  page more than once with the expected results of creating multiple 
     315 *  records.  In addition, this allows a single partial to be used to 
     316 *  generate form inputs for both edit and create forms.  
     317 *  @todo Document this function 
     318 */ 
     319function select($object_name, $attribute_name, $choices, 
     320        $options = array(), $html_options = array()) { 
    246321    $form = new FormOptionsHelper($object_name, $attribute_name); 
    247322    return $form->to_select_tag($choices, $options, $html_options); 
     
    249324 
    250325/** 
     326 *  Create a new FormOptionsHelper object and call its to_collection_select_tag() method 
     327 * 
    251328 * Return select and option tags for the given object and method using  
    252329 * options_from_collection_for_select to generate the list of option tags. 
     
    266343 *   </select> 
    267344 * 
    268  */ 
    269 function collection_select($object_name, $attribute_name, $collection, $attribute_value, $attribute_text, $options = array(), $html_options = array()) { 
     345 *  @todo Document this function 
     346 *  @uses FormOptionsHelper::to_collection_select_tag() 
     347 */ 
     348function collection_select($object_name, $attribute_name, $collection, 
     349                           $attribute_value, $attribute_text, 
     350                           $options = array(), $html_options = array()) { 
    270351    $form = new FormOptionsHelper($object_name, $attribute_name); 
    271     return $form->to_collection_select_tag($collection, $attribute_value, $attribute_text, $options, $html_options); 
    272 } 
    273  
    274 /** 
     352    return $form->to_collection_select_tag($collection, $attribute_value, 
     353                                           $attribute_text, $options, 
     354                                           $html_options); 
     355} 
     356 
     357/** 
     358 *  Create a new FormOptionsHelper object and call its to_country_select_tag() method 
     359 * 
    275360 * Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. 
     361 *  @todo Document this function 
     362 *  @uses FormOptionsHelper::country_select() 
    276363 */ 
    277364function country_select($object_name, $attribute_name, $priority_countries = null, $options = array(), $html_options = array()) { 
     
    280367} 
    281368 
     369/** 
     370 *  Create a new FormOptionsHelper object and call its options_for_select() method 
     371 * 
     372 *  @param string[]  List of choices 
     373 *  @param integer   Index of the selected choice 
     374 *  @uses FormOptionsHelper::options_for_select() 
     375 */ 
    282376function options_for_select($choices, $selected = null) { 
    283377    $form = new FormOptionsHelper(); 
    284     return $form->options_for_select($choices, $selected = null);     
    285 } 
    286  
     378    return $form->options_for_select($choices, $selected);     
     379} 
     380 
     381// -- set Emacs parameters -- 
     382// Local variables: 
     383// tab-width: 4 
     384// c-basic-offset: 4 
     385// c-hanging-comment-ender-p: nil 
     386// indent-tabs-mode: nil 
     387// End: 
    287388?> 
  • trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php

    r196 r198  
    3030 
    3131/** 
    32  * 
    33  *  @package PHPonTrax 
     32 *  @todo Document this class 
    3433 */ 
    3534class FormTagHelper extends Helpers { 
     
    4140        $html_options = array_merge(array("method" => "post"), $options); 
    4241 
    43         if($html_options['multipart']) { 
     42        if(array_key_exists('multipart',$html_options) 
     43       && $html_options['multipart']) { 
    4444            $html_options['enctype'] = "multipart/form-data"; 
    4545            unset($html_options['multipart']);