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

enhance tests, docs

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

Legend:

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

    r165 r196  
    3131/** 
    3232 *  Basic helper functions 
     33 * 
     34 *  A collection of methods used to generate basic HTML/XML. 
    3335 */ 
    3436class Helpers { 
    3537 
    3638    /** 
    37      * 
     39     *  @todo Document this variable 
     40     *  @var boolean 
     41     */ 
     42    public $auto_index; 
     43 
     44    /** 
     45     *  @todo Document this variable 
     46     *  Name of a PHP class(?) 
     47     *  @var string 
     48     */ 
     49    public $object_name; 
     50 
     51    /** 
     52     *  @todo Document this variable 
     53     */ 
     54    public $attribute_name; 
     55 
     56    /** 
     57     *  Current controller object 
     58     * 
     59     *  Local copy of $GLOBALS['current_controller_object'] 
     60     *  @var ActionController 
     61     */ 
     62    public $controller_object; 
     63 
     64    /** 
     65     *  Current controller name 
     66     * 
     67     *  Local copy of $GLOBALS['current_controller_name'] 
     68     *  @var string 
     69     */ 
     70    public $controller_name; 
     71 
     72    /** 
     73     *  Current controller path 
     74     * 
     75     *  Local copy of $GLOBALS['current_controller_path'] 
     76     *  @var string 
     77     */ 
     78    public $controller_path; 
     79 
     80 
     81    /** 
     82     *  Construct a Helpers object 
     83     * 
     84     *  @param string Name of ActiveRecord subclass 
     85     *  @param string Attribute of ActiveRecord subclass 
     86     *  @uses auto_index 
     87     *  @uses object_name 
     88     *  @uses attribute_name 
     89     *  @uses controller_name 
     90     *  @uses controller_path 
     91     *  @uses controller_object 
    3892     */ 
    3993    function __construct($object_name = null, $attribute_name = null) { 
     
    46100        $this->object_name = str_replace("[]", "", $object_name);      
    47101        $this->attribute_name = $attribute_name;         
    48         $this->controller_name = $GLOBALS['current_controller_name']; 
    49         $this->controller_path = $GLOBALS['current_controller_path']; 
    50         $this->controller_object = $GLOBALS['current_controller_object']; 
     102 
     103        //  Copy controller information from $GLOBALS 
     104        $this->controller_name = 
     105            array_key_exists('current_controller_name',$GLOBALS) 
     106            ? $GLOBALS['current_controller_name'] : null; 
     107        $this->controller_path = 
     108            array_key_exists('current_controller_path', $GLOBALS) 
     109            ? $GLOBALS['current_controller_path'] : null; 
     110        $this->controller_object = 
     111            array_key_exists('current_controller_object', $GLOBALS) 
     112            ? $GLOBALS['current_controller_object'] : null; 
    51113        if($auto_index) { 
    52114            $object = $this->object(); 
     
    59121 
    60122    /** 
    61      * 
     123     *  Get value of current attribute in the current ActiveRecord object 
     124     * 
     125     *  If there is a value in $_REQUEST[][], return it. 
     126     *  Otherwise fetch the value from the database. 
     127     *  @uses attribute_name 
     128     *  @uses object() 
     129     *  @uses object_name 
     130     *  @uses ActiveRecord::send() 
    62131     */ 
    63132    protected function value() { 
    64         if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 
     133        if (!array_key_exists($this->object_name, $_REQUEST) 
     134            || !array_key_exists($this->attribute_name, 
     135                                 $_REQUEST[$this->object_name])) { 
    65136            $object = $this->object(); 
    66137            if(is_object($object) && $this->attribute_name) { 
     
    72143 
    73144    /** 
    74      * 
     145     *  @todo Document this method 
     146     *  @param string object_name 
     147     *  @uses controller_object 
    75148     */ 
    76149    protected function object($object_name = null) { 
     
    125198     */ 
    126199    protected function boolean_attribute(&$options, $attribute) { 
    127         if($options[$attribute]) { 
     200        if(array_key_exists($attribute,$options) 
     201           && $options[$attribute]) { 
    128202            $options[$attribute] = $attribute; 
    129203        } else { 
     
    135209     *  Wrap CDATA begin and end tags around argument 
    136210     * 
    137      *  Returns a CDATA section for the given +content+.  CDATA sections 
     211     *  Returns a CDATA section for the given content.  CDATA sections 
    138212     *  are used to escape blocks of text containing characters which would 
    139213     *  otherwise be recognized as markup. CDATA sections begin with the string 
    140      *  <tt>&lt;![CDATA[</tt> and end with (and may not contain) the string  
    141      *  <tt>]]></tt>.  
     214     *  <samp><![CDATA[</samp> and end with (and may not contain) the string  
     215     *  <samp>]]></samp>.  
    142216     *  @param string $content  Content to wrap 
    143217     *  @return string          Wrapped argument 
     
    148222 
    149223    /** 
    150      *  Generate an HTML or XML tag with optional attributes 
    151      * 
    152      *  Example: tag("br"); 
    153      *   Results: <br /> 
    154      *  Example: tag("input", array("type" => "text")); 
    155      * <input type="text" /> 
    156      *  @uses tag_options() 
    157      *  @param string $name    Tag name 
    158      *  @param string[] $options Tag attributes to apply 
     224     *  Generate an HTML or XML tag with optional attributes and self-ending 
     225     * 
     226     *  <ul> 
     227     *   <li>Example: <samp>tag("br");</samp><br> 
     228     *       Returns: <samp><br  />\n</samp></li> 
     229     *   <li> Example: <samp>tag("div", array("class" => "warning"), true);</samp><br> 
     230     *       Returns: <samp><div class="warning">\n</samp></li> 
     231     *  </ul> 
     232     *  @param string $name      Tag name 
     233     *  @param string[] $options Tag attributes to apply, specified as 
     234     *                  array('attr1' => 'value1'[, 'attr2' => 'value2']...)  
    159235     *  @param boolean $open 
    160236     *  <ul> 
     
    162238     *    <li>false => make self-terminating tag (end with ' \>')</li> 
    163239     *  </ul> 
    164      *  @return string The tag, followed by "\n" 
     240     *  @return string The generated tag, followed by "\n" 
     241     *  @uses tag_options() 
    165242     */ 
    166243    function tag($name, $options = array(), $open = false) { 
     
    172249 
    173250    /** 
    174      *  Generate an open/close pair of tags with content between 
    175      * 
    176      *  Example: content_tag("p", "Hello world!"); 
    177      *  Result: <p>Hello world!</p> 
    178      *  Example: content_tag("div", content_tag("p", "Hello world!"), 
    179      *           array("class" => "strong")) => 
    180      *  Result:<div class="strong"><p>Hello world!</p></div> 
     251     *  Generate an open/close pair of tags with optional attributes and content between 
     252     * 
     253     *  <ul> 
     254     *   <li>Example: <samp>content_tag("p", "Hello world!");</samp><br /> 
     255     *       Returns: <samp><p>Hello world!</p>\n</samp><li> 
     256     *   <li>Example: 
     257     *     <samp>content_tag("div", 
     258     *                       content_tag("p", "Hello world!"), 
     259     *                       array("class" => "strong"));</samp><br /> 
     260     *     Returns: 
     261     *     <samp><div class="strong"><p>Hello world!</p></div>\n</samp></li> 
     262     *  </ul> 
    181263     *  @uses tag_options() 
    182264     *  @param string $name    Tag to wrap around $content 
    183265     *  @param string $content Text to put between tags 
    184      *  @param string[] $options Tag attributes to apply 
     266     *  @param string[] $options Tag attributes to apply, specified as 
     267     *                  array('attr1' => 'value1'[, 'attr2' => 'value2']...)  
    185268     *  @return string Text wrapped with tag and attributes, 
    186269     *                 followed by "\n" 
     
    195278    /** 
    196279     * 
     280     *  @uses content_tag() 
     281     *  @uses value() 
    197282     */     
    198283    function to_content_tag($tag_name, $options = array()) { 
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r195 r196  
    3737     
    3838    /** 
    39      * 
     39     *  @todo Document this variable 
    4040     */ 
    4141    public $scaffolding = 0; 
     
    9898     *  @uses all_input_tags() 
    9999     *  @uses content_tag() 
     100     *  @uses Helpers::object() 
    100101     */ 
    101102    function form($record_name, $options = array()) { 
     
    146147     * <tt>id</tt> - The id of the error div (default: errorExplanation) 
    147148     * <tt>class</tt> - The class of the error div (default: errorExplanation) 
     149     *  @param mixed object_name  The name of a PHP class, or 
     150     *                            an object instance of that class 
     151     *  @param string[] options Set of options: 'header_tag', 'id', 'class' 
     152     *  @uses content_tag() 
     153     *  @uses object_name 
     154     *  @uses Inflector::humanize() 
    148155     */ 
    149156    function error_messages_for($object_name, $options = array()) { 
     
    171178    /** 
    172179     *  @todo Document this method 
     180     *  @uses default_input_block() 
    173181     */ 
    174182    function all_input_tags($record, $record_name, $options) { 
     
    203211    /** 
    204212     *  @todo Document this method 
     213     * 
     214     *  @param string object_name    Name of an ActiveRecord subclass 
     215     *  @param string attribute_name Name of an attribute of $object_name 
     216     *  @param string[] options 
     217     *  @uses attribute_name 
     218     *  @uses column_type() 
     219     *  @uses error_wrapping() 
     220     *  @uses object_name 
     221     *  @uses DateHelper::to_date_select_tag() 
     222     *  @uses FormHelper::to_boolean_select_tag() 
     223     *  @uses FormHelper::to_input_field_tag() 
     224     *  @uses FormHelper::to_text_area_tag() 
     225     *  @uses to_datetime_select_tag() 
     226     *  @uses object() 
    205227     */ 
    206228    function to_tag($object_name, $attribute_name, $options = array()) { 
     
    245267    /** 
    246268     *  @todo Document this method 
     269     * 
     270     *  @uses attribute_name 
     271     *  @uses column_type() 
     272     *  @uses object() 
     273     *  @uses object_name 
    247274     */ 
    248275    function to_scaffold_tag($object_name, $attribute_name, $options = array()) { 
     
    277304                break; 
    278305    default: 
    279       echo "default case from ".$this->column_type()."\n"; 
    280306        } 
    281307        if(count($this->object()->errors)) { 
     
    287313    /** 
    288314     *  @todo Document this method 
     315     * 
     316     *  @uses tag() 
    289317     */ 
    290318    function tag_without_error_wrapping() { 
     
    295323    /** 
    296324     *  @todo Document this method 
     325     * 
     326     *  @uses error_wrapping() 
     327     *  @uses object() 
     328     *  @uses tag_without_error_wrapping() 
    297329     */ 
    298330    function tag($name, $options = array()) { 
     
    306338    /** 
    307339     *  @todo Document this method 
     340     * 
     341     *  @uses content_tag() 
    308342     */ 
    309343    function content_tag_without_error_wrapping() { 
     
    314348    /** 
    315349     *  @todo Document this method 
     350     * 
     351     *  @uses object() 
     352     *  @uses error_wrapping() 
     353     *  @uses content_tag_without_error_wrapping() 
    316354     */ 
    317355    function content_tag($name, $value, $options = array()) { 
     
    325363    /** 
    326364     *  @todo Document this method 
     365     * 
     366     *  @uses object_name 
     367     *  @uses attribute_name 
     368     *  @uses DateHelper::to_date_select_tag() 
    327369     */ 
    328370    function to_date_select_tag_without_error_wrapping() { 
     
    345387    /** 
    346388     *  @todo Document this method 
     389     * 
     390     *  @uses attribute_name 
     391     *  @uses object_name 
     392     *  @uses DateHelper::to_datetime_select_tag() 
    347393     */ 
    348394    function to_datetime_select_tag_without_error_wrapping() { 
    349395        $form = new DateHelper($this->object_name, $this->attribute_name); 
    350396        $args = func_get_args(); 
    351         return call_user_func_array(array($form, 'to_datetime_select_tag'), $args); 
    352     } 
    353  
    354     /** 
    355      *  @todo Document this method 
     397        return call_user_func_array(array($form, 'to_datetime_select_tag'), 
     398                                    $args); 
     399    } 
     400 
     401    /** 
     402     *  @todo Document this method 
     403     * 
     404     *  @uses attribute_name 
     405     *  @uses error_wrapping() 
     406     *  @uses object() 
     407     *  @uses to_datetime_select_tag_without_error_wrapping 
    356408     */ 
    357409    function to_datetime_select_tag($options = array()) { 
     
    365417    /** 
    366418     *  @todo Document this method 
     419     * 
     420     *  @param string  $html_tag 
     421     *  @param boolean $has_error 
    367422     */ 
    368423    function error_wrapping($html_tag, $has_error) { 
     
    372427    /** 
    373428     *  @todo Document this method 
     429     * 
     430     *  @uses attribute_name 
     431     *  @uses object() 
    374432     */ 
    375433    function error_message() { 
     
    379437    /** 
    380438     *  @todo Document this method 
     439     * 
     440     *  @uses attribute_name 
     441     *  @uses object() 
     442     *  @uses ActiveRecord::column_for_attribute() 
    381443     */ 
    382444    function column_type() { 
     
    390452 *  Avialble functions for use in views 
    391453 * error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") 
     454 *  @uses ActiveRecordHelper::error_message_on() 
    392455 */ 
    393456function error_message_on() { 
     
    398461 
    399462/** 
    400  * error_messages_for($object_name, $options = array()) 
     463 *  error_messages_for($object_name, $options = array()) 
     464 *  @uses ActiveRecordHelper::error_messages_for() 
    401465 */ 
    402466function error_messages_for() { 
     
    408472/** 
    409473 *  form($record_name, $options = array()) 
     474 *  @uses ActiveRecordHelper::form() 
    410475 */ 
    411476function form() { 
     
    420485 *   input("post", "title") => 
    421486 *    <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 
     487 *  @uses ActiveRecordHelper::input() 
    422488 */ 
    423489function input() { 
     
    429495/** 
    430496 * 
     497 *  @uses ActiveRecordHelper::input_scaffolding() 
    431498 */ 
    432499function input_scaffolding() { 
  • trunk/trax/vendor/trax/action_view/helpers/asset_tag_helper.php

    r148 r196  
    3131/** 
    3232 *  @todo Document this class 
    33  *  @package PHPonTrax 
    3433 */ 
    3534class AssetTagHelper extends Helpers { 
    3635 
    3736    /** 
    38      *  
     37     *  @todo Document this method 
    3938     * 
    4039     */ 
     
    4544     
    4645    /** 
    47      *  
     46     *   @todo Document this method 
    4847     * 
    4948     */ 
     
    119118     * 
    120119     *  stylesheet_path("style") # => /stylesheets/style.css 
     120     *  @uses compute_public_path() 
    121121     */ 
    122122    function stylesheet_path($source) { 
     
    138138     *   <link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" /> 
    139139     *   <link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" /> 
     140     *  @uses stylesheet_path() 
     141     *  @uses tag() 
    140142     */ 
    141143    function stylesheet_link_tag() { 
     
    159161     * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" 
    160162     * * file name without extension, like "logo", that gets expanded to "/images/logo.png" 
     163     *  @uses compute_public_path 
    161164     */ 
    162165    function image_path($source) { 
     
    174177     * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" 
    175178     * * file name without extension, like "logo", that gets expanded to "/images/logo.png" 
     179     *  @uses Inflector::capitalize() 
     180     *  @uses image_path() 
     181     *  @uses tag() 
    176182     */ 
    177183    function image_tag($source, $options = array()) { 
     
    202208     *  auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"}) # => 
    203209     *   <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.curenthost.com/controller/feed" /> 
     210        *  @uses tag() 
    204211     */ 
    205212    function auto_discovery_link_tag($type = 'rss', $options = array(), $tag_options = array()) { 
     
    216223 
    217224/** 
    218   *  Avialble functions for use in views 
    219   *  auto_discovery_link_tag($type = 'rss', $options = array(), $tag_options = array()) 
    220   */ 
     225 *  @todo Document this method   
     226 *  Avialble functions for use in views 
     227 *  auto_discovery_link_tag($type = 'rss', $options = array(), $tag_options = array()) 
     228 *  @uses AssetTagHelper::auto_discovery_link_tag() 
     229 */ 
    221230function auto_discovery_link_tag() { 
    222231    $asset_helper = new AssetTagHelper(); 
     
    226235 
    227236/** 
    228   *  image_tag($source, $options = array()) 
    229   */ 
     237 *  @todo Document this method   
     238 *  image_tag($source, $options = array()) 
     239 *  @uses AssetTagHelper::image_tag() 
     240 */ 
    230241function image_tag() { 
    231242    $asset_helper = new AssetTagHelper(); 
     
    235246 
    236247/** 
    237   *  stylesheet_link_tag($sources) 
    238   */ 
     248 *  @todo Document this method   
     249 *  stylesheet_link_tag($sources) 
     250 *  @uses AssetTagHelper::stylesheet_link_tag() 
     251 */ 
    239252function stylesheet_link_tag() { 
    240253    $asset_helper = new AssetTagHelper(); 
     
    244257 
    245258/** 
    246   *  javascript_include_tag($sources) 
    247   */ 
     259 *  @todo Document this method 
     260 *  javascript_include_tag($sources) 
     261 *  @uses AssetTagHelper::javascript_include_tag() 
     262 */ 
    248263function javascript_include_tag() { 
    249264    $asset_helper = new AssetTagHelper(); 
     
    252267} 
    253268 
     269// -- set Emacs parameters -- 
     270// Local variables: 
     271// tab-width: 4 
     272// c-basic-offset: 4 
     273// c-hanging-comment-ender-p: nil 
     274// indent-tabs-mode: nil 
     275// End: 
    254276?> 
  • trunk/trax/vendor/trax/action_view/helpers/date_helper.php

    r177 r196  
    3434 */ 
    3535class DateHelper extends Helpers { 
     36 
     37    /** 
     38     *  @todo Document this variable 
     39     */ 
     40    public $request_years; 
     41 
     42    /** 
     43     *  Month value parsed from $_REQUEST 
     44     */ 
     45    public $request_months = array(); 
     46 
     47    /** 
     48     *  @todo Document this variable 
     49     */ 
     50    public $request_days; 
     51 
     52    /** 
     53     *  @todo Document this variable 
     54     */ 
     55    public $request_hours; 
     56 
     57    /** 
     58     *  @todo Document this variable 
     59     */ 
     60    public $request_minutes; 
     61 
     62    /** 
     63     *  @todo Document this variable 
     64     */ 
     65    public $request_seconds; 
     66 
     67    /** 
     68     *  @todo Document this variable 
     69     */ 
    3670    public $selected_years = array(); 
     71 
    3772    /** 
    3873     *  @todo Document this method 
     
    4479    /** 
    4580     *  @todo Document this method 
     81     *  @uses attribute_name 
     82     *  @uses object_name 
     83     *  @uses request_years 
     84     *  @uses request_months 
     85     *  @uses request_days 
     86     *  @uses request_hours 
     87     *  @uses request_minutes 
     88     *  @uses request_seconds 
    4689     */ 
    4790    private function check_request_for_value() { 
     
    71114 
    72115    /** 
    73      * 
    74      *  @todo Document this method 
    75      */ 
    76     private function select_html($type, $options, $prefix = null, $include_blank = false, $discard_type = false) { 
     116     *  @todo Document this method 
     117     *  @param string   Type of select 
     118     *  @param string[] Options to appear in the select 
     119     *  @param string    
     120     *  @param boolean  Whether to include a blank in the list of 
     121     *                  select options   
     122     *  @param boolean  Whether to ignore type 
     123     */ 
     124    private function select_html($type, $options, $prefix = null, 
     125                                 $include_blank = false, 
     126                                 $discard_type = false) { 
    77127        $select_html  = "<select name=\"$prefix";        
    78128        if(!$discard_type) { 
     
    89139 
    90140    /** 
    91      * 
    92      *  @todo Document this method 
     141     *  Prefix a leading zero to single digit numbers 
     142     *  @param string   A number 
     143     *  @return string  Number with zero prefix if value <= 9 
    93144     */ 
    94145    private function leading_zero_on_single_digits($number) { 
     
    137188    /** 
    138189     *  @todo Document this method 
     190     *  @uses select_html 
    139191     */ 
    140192    function select_expiration_date($date = null, $options = array()) { 
     
    198250     *  Override the field name using the <tt>:field_name</tt> option, 'second' by default. 
    199251     *  @todo Document this method 
     252     *  @uses select_html 
    200253     */ 
    201254    function select_second($datetime, $options = array()) { 
     
    226279     *  Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 
    227280     *  @todo Document this method 
     281     *  @uses select_html 
    228282     */ 
    229283    function select_minute($datetime, $options = array()) { 
     
    253307     *  Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 
    254308     *  @todo Document this method 
     309     *  @uses select_html 
    255310     */ 
    256311    function select_hour($datetime, $options = array()) { 
     
    281336     *  Override the field name using the <tt>:field_name</tt> option, 'day' by default. 
    282337     *  @todo Document this method 
     338     *  @uses leading_zero_on_single_digits 
     339     *  @uses request_days 
     340     *  @uses select_html 
    283341     */ 
    284342    function select_day($datetime, $options = array()) { 
     
    299357            "<option value=\"".$this->leading_zero_on_single_digits($day)."\">".$this->leading_zero_on_single_digits($day)."</option>\n"; 
    300358        } 
    301         $field_name = ($options['field_name']) ? $options['field_name'] : 'day'; 
    302         return $this->select_html($field_name, $day_options, $options['prefix'], $options['include_blank'], $options['discard_type']); 
    303     } 
    304  
    305     /** 
    306      *  Returns a select tag with options for each of the months January through December with the current month selected. 
    307      *  The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values 
    308      *  (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names -- 
    309      *  set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names, 
    310      *  set the <tt>:add_month_numbers</tt> key in +options+ to true. Examples: 
    311      * 
    312      *   select_month(Date.today)                             # Will use keys like "January", "March" 
    313      *   select_month(Date.today, :use_month_numbers => true) # Will use keys like "1", "3" 
    314      *   select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March" 
    315      * 
    316      *  Override the field name using the <tt>:field_name</tt> option, 'month' by default. 
    317      *  @todo Document this method 
    318    */ 
    319     function select_month($date, $options = array()) { 
    320         $month_options = ""; 
    321          
    322         if($this->request_months[$this->attribute_name]) { 
     359        $field_name = array_key_exists('field_name', $options) 
     360            ? $options['field_name'] : 'day'; 
     361        return $this->select_html($field_name, $day_options, 
     362                                  $options['prefix'], 
     363                                  array_key_exists('include_blank', $options) 
     364                                  ? $options['include_blank'] : false, 
     365                                  $options['discard_type']); 
     366    } 
     367 
     368    /** 
     369     *  Generate HTML/XML for month selector pull-down menu 
     370     * 
     371     *  Returns <samp><select>...</select></samp> HTML with an option 
     372     *  for each of the twelve months.  The first argument, if 
     373     *  present, specifies the initially selected month.  The second 
     374     *  argument controls the format of the generated HTML. 
     375     * 
     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. 
     382     *  Otherwise, if the first argument is present and is a character 
     383     *  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 
     417     *  @return string  Generated HTML 
     418     *  @uses request_days 
     419     *  @uses request_months 
     420     *  @uses select_html 
     421     */ 
     422    function select_month($date = null, $options = array()) { 
     423        
     424        $month_options = "";    // will accumulate <option>s 
     425         
     426        //  If a value for this attribute was parsed from $_REQUEST, 
     427        //  use it as initially selected and ignore first argument 
     428        if(array_key_exists($this->attribute_name,$this->request_months)) { 
    323429            $date_month = $this->request_months[$this->attribute_name];     
    324         } elseif(strlen($date) != 2 && !is_numeric($date)) { 
    325             $date = $date ? $date : date("Y-m-d");  
     430        } 
     431 
     432        //  No value in $_REQUEST so look at the first argument. 
     433        //  If it is valid use it as initially selected 
     434        elseif(strlen($date) == 2 && is_numeric($date) 
     435               && $date >=1 && $date <= 12 ) { 
     436            $date_month = $date; 
     437        } 
     438 
     439        //  First argument is missing or invalid, 
     440        //  initially select current month 
     441        else { 
    326442            $date_month = date("m",strtotime($date));     
    327443        } 
    328444    
     445        //  Generate <option>...</option> HTML for each month 
    329446        for($month_number = 1; $month_number <= 12; $month_number++) { 
    330             if($options['use_month_numbers']) { 
     447            if(array_key_exists('use_month_numbers',$options)) { 
    331448                $month_name = $month_number; 
    332             } elseif($options['add_month_numbers']) { 
    333                 $month_number .= ' - ' + date("F",strtotime("01-".$month_number."-2005")); 
     449            } elseif(array_key_exists('add_month_numbers',$options)) { 
     450                $month_name = $month_number. ' - ' 
     451                    . date("F",strtotime("2005-" . $month_number 
     452                                       . "-01")); 
    334453            } else { 
    335                 $month_name = date("F",strtotime("2005-".$this->leading_zero_on_single_digits($month_number)."-01")); 
     454                $month_name = date("F",strtotime("2005-" . $month_number 
     455                                                 ."-01")); 
    336456            } 
    337457 
    338             $month_options .= ($date && ($date_month == $month_number)) ? 
    339             "<option value=\"".$this->leading_zero_on_single_digits($month_number)."\" selected=\"selected\">$month_name</option>\n" : 
    340             "<option value=\"".$this->leading_zero_on_single_digits($month_number)."\">$month_name</option>\n"; 
    341         } 
    342         $field_name = ($options['field_name']) ? $options['field_name'] : 'month'; 
    343         return $this->select_html($field_name, $month_options, $options['prefix'], $options['include_blank'], $options['discard_type']); 
     458            $month_options .= ($date_month == $month_number ? 
     459                               "<option value=\"" 
     460                          .$this->leading_zero_on_single_digits($month_number) 
     461                       ."\" selected=\"selected\">$month_name</option>\n" : 
     462                               "<option value=\"" 
     463                          .$this->leading_zero_on_single_digits($month_number) 
     464                               ."\">$month_name</option>\n"); 
     465        } 
     466 
     467        //  Return finished HTML 
     468        $field_name = array_key_exists('field_name', $options) 
     469                       ? $options['field_name'] : 'month'; 
     470        return $this->select_html($field_name, $month_options, 
     471                                  array_key_exists('prefix', $options) 
     472                                  ? $options['prefix'] : null, 
     473                                  array_key_exists('include_blank', $options) 
     474                                  ? $options['include_blank'] : false, 
     475                                  array_key_exists('discard_type', $options) 
     476                                  ? $options['discard_type'] : false); 
    344477    } 
    345478 
     
    355488     * Override the field name using the <tt>:field_name</tt> option, 'year' by default. 
    356489     *  @todo Document this method 
    357     */ 
     490     *  @uses select_html 
     491     */ 
    358492    function select_year($date, $options = array()) { 
    359493        $year_options = ""; 
     
    421555         
    422556        if(count($date_select)) { 
    423             $seperator = $options['field_seperator'] ? $options['field_seperator'] : " "; 
     557            $seperator = array_key_exists('field_seperator',$options) 
     558                ? $options['field_seperator'] : " "; 
    424559            $date_select = implode($seperator, $date_select);             
    425560        } 
  • trunk/trax/vendor/trax/action_view/helpers/form_helper.php

    r160 r196  
    3030 
    3131/** 
    32  * 
    33  *  @package PHPonTrax 
     32 *  @todo Document this class 
    3433 */ 
    3534class FormHelper extends Helpers { 
    3635 
    3736    /** 
    38      * 
     37     *  Default attributes for input fields 
     38     *  @var string[] 
     39     */ 
     40    private $default_field_options = array(); 
     41 
     42    /** 
     43     *  Default attributes for radio buttons 
     44     *  @var string[] 
     45     */ 
     46    private $default_radio_options = array(); 
     47 
     48    /** 
     49     *  Default attributes for text areas 
     50     *  @var string[] 
     51     */ 
     52    private $default_text_area_options = array(); 
     53 
     54    /** 
     55     *  Default attributes for dates 
     56     *  @var string[] 
     57     */ 
     58    private $default_date_options = array(); 
     59 
     60    /** 
     61     *  @todo Document this method 
     62     *  @uses default_date_options 
     63     *  @uses default_field_options 
     64     *  @uses default_radio_options 
     65     *  @uses default_text_area_options 
    3966     */ 
    4067    function __construct($object_name, $attribute_name) { 
    4168        parent::__construct($object_name, $attribute_name); 
    42         $this->default_field_options = $GLOBALS['DEFAULT_FIELD_OPTIONS'] ? $GLOBALS['DEFAULT_FIELD_OPTIONS'] : array("size" => 30); 
    43         $this->default_radio_options = $GLOBALS['DEFAULT_RADIO_OPTIONS'] ? $GLOBALS['DEFAULT_RADIO_OPTIONS'] : array(); 
    44         $this->default_text_area_options = $GLOBALS['DEFAULT_TEXT_AREA_OPTIONS'] ? $GLOBALS['DEFAULT_TEXT_AREA_OPTIONS'] : array("cols" => 40, "rows" => 20); 
    45         $this->default_date_options = $GLOBALS['DEFAULT_DATE_OPTIONS'] ? $GLOBALS['DEFAULT_DATE_OPTIONS'] : array(":discard_type" => true); 
    46     } 
    47  
    48     /** 
    49      * 
     69 
     70        //  Set default attributes for input fields 
     71        $this->default_field_options =  
     72            array_key_exists('DEFAULT_FIELD_OPTIONS',$GLOBALS) 
     73            ? $GLOBALS['DEFAULT_FIELD_OPTIONS'] 
     74            : array("size" => 30); 
     75 
     76        //  Set default attributes for radio buttons 
     77        $this->default_radio_options = 
     78            array_key_exists('DEFAULT_RADIO_OPTIONS',$GLOBALS) 
     79            ? $GLOBALS['DEFAULT_RADIO_OPTIONS'] 
     80            : array(); 
     81 
     82        //  Set default attributes for text areas 
     83        $this->default_text_area_options = 
     84            array_key_exists('DEFAULT_TEXT_AREA_OPTIONS',$GLOBALS) 
     85            ? $GLOBALS['DEFAULT_TEXT_AREA_OPTIONS'] 
     86            : array("cols" => 40, "rows" => 20); 
     87 
     88        //  Set default attributes for dates 
     89        $this->default_date_options = 
     90            array_key_exists('DEFAULT_Date_OPTIONS',$GLOBALS) 
     91            ? $GLOBALS['DEFAULT_DATE_OPTIONS'] 
     92            : array(":discard_type" => true); 
     93    } 
     94 
     95    /** 
     96     *  @todo Document this method 
    5097     */ 
    5198    function tag_name() { 
     
    54101 
    55102    /** 
    56      * 
     103     *  @todo Document this method 
    57104     */ 
    58105    function tag_name_with_index($index) { 
     
    61108 
    62109    /** 
    63      * 
     110     *  @todo Document this method 
    64111     */ 
    65112    function tag_id() { 
     
    68115 
    69116    /** 
    70      * 
     117     *  @todo Document this method 
    71118     */ 
    72119    function tag_id_with_index($index) { 
     
    75122 
    76123    /** 
    77      * 
     124     *  @todo Document this method 
     125     *  @param string[] 
     126     *  @uses auto_index 
     127     *  @uses tag_id 
     128     *  @uses tag_name 
     129     *  @uses tag_id_with_index() 
     130     *  @uses tag_name_with_index() 
    78131     */ 
    79132    function add_default_name_and_id($options) {     
    80133        if(array_key_exists("index", $options)) { 
    81             $options["name"] = $options["name"] ? $options["name"] : $this->tag_name_with_index($options["index"]); 
    82             $options["id"] = $options["id"] ? $options["id"] : $this->tag_id_with_index($options["index"]); 
     134            $options["name"] = array_key_exists("name", $options) 
     135                ? $options["name"] 
     136                : $this->tag_name_with_index($options["index"]); 
     137            $options["id"] = array_key_exists("id", $options) 
     138                ? $options["id"] 
     139                : $this->tag_id_with_index($options["index"]); 
    83140            unset($options["index"]); 
    84141        } elseif($this->auto_index) { 
    85             $options["name"] = $options["name"] ? $options["name"] : $this->tag_name_with_index($this->auto_index); 
    86             $options["id"] = $options["id"] ? $options["id"] : $this->tag_id_with_index($this->auto_index); 
     142            $options["name"] = array_key_exists("name", $options) 
     143                ? $options["name"] 
     144                : $this->tag_name_with_index($this->auto_index); 
     145            $options["id"] = array_key_exists("id", $options) 
     146                ? $options["id"] 
     147                : $this->tag_id_with_index($this->auto_index); 
    87148        } else { 
    88             $options["name"] = $options["name"] ? $options["name"] : $this->tag_name(); 
    89             $options["id"] = $options["id"] ? $options["id"] : $this->tag_id(); 
     149            $options["name"] = array_key_exists("name", $options) 
     150                ? $options["name"] 
     151                : $this->tag_name(); 
     152            $options["id"] = array_key_exists("id", $options) 
     153                ? $options["id"] 
     154                : $this->tag_id(); 
    90155        } 
    91156        return $options; 
     
    93158 
    94159    /** 
     160     *  Generate an HTML or XML input tag with optional attributes 
    95161     * 
     162     *  @param string  Type of input field (<samp>'text'</samp>, 
     163     *                 <samp>'password'</samp>, <samp>'hidden'</samp> 
     164     *                 <i>etc.</i>) 
     165     *  @param string[] Attributes to apply to the input tag:<br> 
     166     *    <samp>array('attr1' => 'value1'[, 'attr2' => 'value2']...)</samp> 
     167     *  @return string 
     168     *   <samp><input type="</samp><i>type</i> 
     169     *   <samp>" maxlength="</samp><i>maxlength</i><samp>" .../>\n</samp> 
     170     *  @uses add_default_name_and_id() 
     171     *  @uses attribute_name 
     172     *  @uses error_wrapping 
     173     *  @uses default_field_options 
     174     *  @uses object() 
     175     *  @uses tag() 
     176     *  @uses value() 
    96177     */ 
    97178    function to_input_field_tag($field_type, $options = array()) { 
    98         $default_size = $options["maxlength"] ? $options["maxlength"] : $this->default_field_options['size']; 
    99         $options["size"] = $options["size"] ? $options["size"] : $default_size; 
     179        $default_size = array_key_exists("maxlength", $options) 
     180            ? $options["maxlength"] : $this->default_field_options['size']; 
     181        $options["size"] = array_key_exists("size", $options) 
     182            ? $options["size"]: $default_size; 
    100183        $options = array_merge($this->default_field_options, $options); 
    101184        if($field_type == "hidden") { 
     
    104187        $options["type"] = $field_type; 
    105188        if($field_type != "file") { 
    106             $options["value"] = $options["value"] ? $options["value"] : $this->value(); 
     189            $options["value"] = array_key_exists("value", $options) 
     190                ? $options["value"] : $this->value(); 
    107191        } 
    108192        $options = $this->add_default_name_and_id($options); 
    109         return $this->error_wrapping($this->tag("input", $options),$this->object()->errors[$this->attribute_name]); 
    110     } 
    111  
    112     /** 
    113      * 
     193        return $this->error_wrapping( 
     194                     $this->tag("input", $options), 
     195                     array_key_exists($this->attribute_name, 
     196                                      $this->object()->errors) 
     197                     ? true : false); 
     198    } 
     199 
     200    /** 
     201     *  @todo Document this method 
     202     *  @uses add_default_name_and_id() 
    114203     */ 
    115204    function to_radio_button_tag($tag_value, $options = array()) { 
     
    129218 
    130219    /** 
    131      * 
     220     *  @todo Document this method 
     221     *  @uses add_default_name_and_id() 
    132222     */ 
    133223    function to_text_area_tag($options = array()) { 
    134         if ($options["size"]) { 
     224        if (array_key_exists("size", $options)) { 
    135225            $size = explode('x', $options["size"]); 
    136226            $options["cols"] = reset($size); 
     
    140230        $options = array_merge($this->default_text_area_options, $options); 
    141231        $options = $this->add_default_name_and_id($options); 
    142         return $this->error_wrapping($this->content_tag("textarea", htmlspecialchars($this->value()), $options),$this->object()->errors[$this->attribute_name]); 
    143     } 
    144  
    145     /** 
    146      * 
     232        return $this->error_wrapping( 
     233           $this->content_tag("textarea", 
     234                              htmlspecialchars($this->value()), 
     235                              $options), 
     236           array_key_exists($this->attribute_name,$this->object()->errors) 
     237           ? $this->object()->errors[$this->attribute_name] : false); 
     238    } 
     239 
     240    /** 
     241     *  @todo Document this method 
     242     *  @uses add_default_name_and_id() 
    147243     */ 
    148244    function to_check_box_tag($options = array(), $checked_value = "1", $unchecked_value = "0") { 
     
    177273 
    178274    /** 
    179      * 
     275     *  @todo Document this method 
     276     *  @uses add_default_name_and_id() 
    180277     */ 
    181278    function to_boolean_select_tag($options = array()) { 
     
    198295    } 
    199296     
     297    /** 
     298     *  If this tag has an error, wrap it with a visual indicator 
     299     * 
     300     *  @param string HTML to be wrapped 
     301     *  @param boolean  true=>error, false=>no error 
     302     *  @return string 
     303     */ 
    200304    function error_wrapping($html_tag, $has_error) { 
    201         return ($has_error ? '<span class="fieldWithErrors">' . $html_tag . '</span>' : $html_tag); 
     305        return ($has_error 
     306                ? '<span class="fieldWithErrors">' . $html_tag . '</span>' 
     307                : $html_tag); 
    202308    }     
    203309 
     
    206312 
    207313/** 
    208  *  Avialble functions for use in views 
    209  *  Example: text_field("post", "title"); 
    210  *  Result: <input type="text" id="post_title" name="post[title]" value="$post->title" /> 
     314 *  Generate HTML/XML for <input type="text" /> in a view file 
     315 * 
     316 *  Example: In the view file, code 
     317 *           <code><?= text_field("Person", "fname"); ?></code> 
     318 *  Result: <input id="Person_fname" name="Person[fname]" size="30" type="text" value="$Person->fname" /> 
     319 *  @param string  Class name of the object being processed 
     320 *  @param string  Name of attribute in the object being processed 
     321 *  @param string[]  Attributes to apply to the generated input tag as:<br> 
     322 *    <samp>array('attr1' => 'value1'[, 'attr2' => 'value2']...)</samp> 
     323 *  @uses FormHelper::to_input_field_tag() 
    211324 */ 
    212325function text_field($object, $field, $options = array()) { 
     
    219332 * Example: password_field("user", "password"); 
    220333 *  Result: <input type="password" id="user_password" name="user[password]" value="$user->password" /> 
     334 *  @uses FormHelper::to_input_field_tag() 
    221335 */ 
    222336function password_field($object, $field, $options = array()) { 
     
    229343 *  Example: hidden_field("post", "title"); 
    230344 *  Result: <input type="hidden" id="post_title" name="post[title]" value="$post->title" /> 
     345 *  @uses FormHelper::to_input_field_tag() 
    231346 */ 
    232347function hidden_field($object, $field, $options = array()) { 
     
    237352/** 
    238353 * Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value. 
     354 *  @uses FormHelper::to_input_field_tag() 
    239355 */ 
    240356function file_field($object, $field, $options = array()) { 
     
    246362 *  Example: text_area("post", "body", array("cols" => 20, "rows" => 40)); 
    247363 *  Result: <textarea cols="20" rows="40" id="post_body" name="post[body]">$post->body</textarea> 
     364 *  @uses FormHelper::to_text_area_tag() 
    248365 */ 
    249366function text_area($object, $field, $options = array()) { 
     
    271388 *     <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /> 
    272389 *     <input name="puppy[gooddog]" type="hidden" value="no" /> 
    273 */ 
     390   *  @uses FormHelper::to_check_box_tag() 
     391 */ 
    274392function check_box($object, $field, $options = array(), $checked_value = "1", $unchecked_value = "0") { 
    275393    $form = new FormHelper($object, $field); 
     
    288406 *     <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 
    289407 *     <input type="radio" id="post_category" name="post[category] value="java" /> 
    290 */ 
     408 *  @uses FormHelper::to_radio_button_tag() 
     409 */ 
    291410function radio_button($object, $field, $tag_value, $options = array()) { 
    292411    $form = new FormHelper($object, $field); 
     
    295414 
    296415/** 
    297  * 
     416 *  Make a new FormHelper object and call its to_boolean_select_tag method 
     417 *  @uses FormHelper::to_boolean_select_tag() 
    298418 */ 
    299419function boolean_select($object, $field, $options = array()) { 
     
    302422} 
    303423 
     424// -- set Emacs parameters -- 
     425// Local variables: 
     426// tab-width: 4 
     427// c-basic-offset: 4 
     428// c-hanging-comment-ender-p: nil 
     429// indent-tabs-mode: nil 
     430// End: 
    304431?> 
  • trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php

    r155 r196  
    145145     * 
    146146     *  @todo Document this method 
     147     *  @uses tag() 
    147148     */ 
    148149    function image_submit_tag($source, $options = array()) { 
    149         return $this->tag("input", array_merge(array("type" => "image", "src" => image_path($source)), $this->convert_options($options))); 
     150        return $this->tag("input", 
     151              array_merge(array("type" => "image", 
     152                        "src" => image_path($source)), 
     153                      $this->convert_options($options))); 
    150154    } 
    151155 
  • trunk/trax/vendor/trax/action_view/helpers/url_helper.php

    r150 r196  
    7676    /** 
    7777     *  @todo Document this method 
     78     *  @param string[] Options 
     79     *  @return string 
    7880     */ 
    7981    function convert_confirm_option_to_javascript($html_options) { 
    80         if($html_options['confirm']) { 
    81             $html_options['onclick'] = "return confirm('".addslashes($html_options['confirm'])."');"; 
     82        if(array_key_exists('confirm', $html_options)) { 
     83            $html_options['onclick'] = 
     84                "return confirm('".addslashes($html_options['confirm'])."');"; 
    8285            unset($html_options['confirm']); 
    8386        } 
     
    252255} 
    253256 
     257// -- set Emacs parameters -- 
     258// Local variables: 
     259// tab-width: 4 
     260// c-basic-offset: 4 
     261// c-hanging-comment-ender-p: nil 
     262// indent-tabs-mode: nil 
     263// End: 
    254264?>