Show
Ignore:
Timestamp:
02/23/06 20:09:13 (6 years ago)
Author:
john
Message:

added in phpDoc commenting tests docs - Walt

Files:
1 modified

Legend:

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

    r132 r138  
    11<?php 
    2 # $Id$ 
    3 # 
    4 # Copyright (c) 2005 John Peterson 
    5 # 
    6 # Permission is hereby granted, free of charge, to any person obtaining 
    7 # a copy of this software and associated documentation files (the 
    8 # "Software"), to deal in the Software without restriction, including 
    9 # without limitation the rights to use, copy, modify, merge, publish, 
    10 # distribute, sublicense, and/or sell copies of the Software, and to 
    11 # permit persons to whom the Software is furnished to do so, subject to 
    12 # the following conditions: 
    13 # 
    14 # The above copyright notice and this permission notice shall be 
    15 # included in all copies or substantial portions of the Software. 
    16 # 
    17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
    22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    24  
     2/** 
     3 *  File containing the FormHelper class 
     4 * 
     5 *  (PHP 5) 
     6 * 
     7 *  @package PHPonTrax 
     8 *  @version $Id$ 
     9 *  @copyright (c) 2005 John Peterson 
     10 * 
     11 *  Permission is hereby granted, free of charge, to any person obtaining 
     12 *  a copy of this software and associated documentation files (the 
     13 *  "Software"), to deal in the Software without restriction, including 
     14 *  without limitation the rights to use, copy, modify, merge, publish, 
     15 *  distribute, sublicense, and/or sell copies of the Software, and to 
     16 *  permit persons to whom the Software is furnished to do so, subject to 
     17 *  the following conditions: 
     18 * 
     19 *  The above copyright notice and this permission notice shall be 
     20 *  included in all copies or substantial portions of the Software. 
     21 * 
     22 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     23 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
     24 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     25 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
     26 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
     27 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
     28 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
     29 */ 
     30 
     31/** 
     32 * 
     33 *  @package PHPonTrax 
     34 */ 
    2535class FormHelper extends Helpers { 
    2636 
     37    /** 
     38     * 
     39     */ 
    2740    function __construct($object_name, $attribute_name) { 
    2841        parent::__construct(); 
     
    3548    } 
    3649 
     50    /** 
     51     * 
     52     */ 
    3753    function value() { 
    3854        if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 
     
    4561    } 
    4662 
     63    /** 
     64     * 
     65     */ 
    4766    function object($object_name = null) { 
    4867        $object_name = $object_name ? $object_name : $this->object_name; 
     
    5069    } 
    5170 
     71    /** 
     72     * 
     73     */ 
    5274    function tag_name() { 
    5375        return "{$this->object_name}[{$this->attribute_name}]"; 
    5476    } 
    5577 
     78    /** 
     79     * 
     80     */ 
    5681    function tag_name_with_index($index) { 
    5782        return "{$this->object_name}[{$index}][{$this->attribute_name}]"; 
    5883    } 
    5984 
     85    /** 
     86     * 
     87     */ 
    6088    function tag_id() { 
    6189        return "{$this->object_name}_{$this->attribute_name}"; 
    6290    } 
    6391 
     92    /** 
     93     * 
     94     */ 
    6495    function tag_id_with_index($index) { 
    6596        return "{$this->object_name}_{$index}_{$this->attribute_name}"; 
    6697    } 
    6798 
     99    /** 
     100     * 
     101     */ 
    68102    function add_default_name_and_id($options) { 
    69103        if(array_key_exists("index", $options)) { 
     
    81115    } 
    82116 
     117    /** 
     118     * 
     119     */ 
    83120    function to_input_field_tag($field_type, $options = array()) { 
    84121        $default_size = $options["maxlength"] ? $options["maxlength"] : $this->default_field_options['size']; 
     
    96133    } 
    97134 
     135    /** 
     136     * 
     137     */ 
    98138    function to_radio_button_tag($tag_value, $options = array()) { 
    99139        $options = array_merge($this->default_radio_options, $options); 
     
    111151    } 
    112152 
     153    /** 
     154     * 
     155     */ 
    113156    function to_text_area_tag($options = array()) { 
    114157        if ($options["size"]) { 
     
    123166    } 
    124167 
     168    /** 
     169     * 
     170     */ 
    125171    function to_check_box_tag($options = array(), $checked_value = "1", $unchecked_value = "0") { 
    126172        $options["type"] = "checkbox"; 
     
    153199    } 
    154200 
     201    /** 
     202     * 
     203     */ 
    155204    function to_boolean_select_tag($options = array()) { 
    156205        $options = $this->add_default_name_and_id($options); 
     
    179228 
    180229 
    181 ################################################################################################ 
    182 ## Avialble functions for use in views 
    183 ################################################################################################ 
    184 # Example: text_field("post", "title"); 
    185 # Result: <input type="text" id="post_title" name="post[title]" value="$post->title" /> 
     230/** 
     231 * Avialble functions for use in views 
     232 *  Example: text_field("post", "title"); 
     233 *  Result: <input type="text" id="post_title" name="post[title]" value="$post->title" /> 
     234 */ 
    186235function text_field($object, $field, $options = array()) { 
    187236    $form = new FormHelper($object, $field); 
     
    189238} 
    190239 
    191 # Works just like text_field, but returns a input tag of the "password" type instead. 
    192 # Example: password_field("user", "password"); 
    193 # Result: <input type="password" id="user_password" name="user[password]" value="$user->password" /> 
     240/** 
     241 *  Works just like text_field, but returns a input tag of the "password" type instead. 
     242 * Example: password_field("user", "password"); 
     243 *  Result: <input type="password" id="user_password" name="user[password]" value="$user->password" /> 
     244 */ 
    194245function password_field($object, $field, $options = array()) { 
    195246    $form = new FormHelper($object, $field); 
     
    197248} 
    198249 
    199 # Works just like text_field, but returns a input tag of the "hidden" type instead. 
    200 # Example: hidden_field("post", "title"); 
    201 # Result: <input type="hidden" id="post_title" name="post[title]" value="$post->title" /> 
     250/** 
     251 *  Works just like text_field, but returns a input tag of the "hidden" type instead. 
     252 *  Example: hidden_field("post", "title"); 
     253 *  Result: <input type="hidden" id="post_title" name="post[title]" value="$post->title" /> 
     254 */ 
    202255function hidden_field($object, $field, $options = array()) { 
    203256    $form = new FormHelper($object, $field); 
     
    205258} 
    206259 
    207 # Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value. 
     260/** 
     261 * Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value. 
     262 */ 
    208263function file_field($object, $field, $options = array()) { 
    209264    $form = new FormHelper($object, $field); 
     
    211266} 
    212267 
    213 # Example: text_area("post", "body", array("cols" => 20, "rows" => 40)); 
    214 # Result: <textarea cols="20" rows="40" id="post_body" name="post[body]">$post->body</textarea> 
     268/** 
     269 *  Example: text_area("post", "body", array("cols" => 20, "rows" => 40)); 
     270 *  Result: <textarea cols="20" rows="40" id="post_body" name="post[body]">$post->body</textarea> 
     271 */ 
    215272function text_area($object, $field, $options = array()) { 
    216273    $form = new FormHelper($object, $field); 
     
    218275} 
    219276 
    220 # Returns a checkbox tag tailored for accessing a specified attribute (identified by $field) on an object 
    221 # assigned to the template (identified by $object). It's intended that $field returns an integer and if that 
    222 # integer is above zero, then the checkbox is checked. Additional $options on the input tag can be passed as an 
    223 # array with $options. The $checked_value defaults to 1 while the default $unchecked_value 
    224 # is set to 0 which is convenient for boolean values. Usually unchecked checkboxes don't post anything. 
    225 # We work around this problem by adding a hidden value with the same name as the checkbox. 
     277/** 
     278 * Returns a checkbox tag tailored for accessing a specified attribute (identified by $field) on an object 
     279 * assigned to the template (identified by $object). It's intended that $field returns an integer and if that 
     280 * integer is above zero, then the checkbox is checked. Additional $options on the input tag can be passed as an 
     281 * array with $options. The $checked_value defaults to 1 while the default $unchecked_value 
     282 * is set to 0 which is convenient for boolean values. Usually unchecked checkboxes don't post anything. 
     283 * We work around this problem by adding a hidden value with the same name as the checkbox. 
    226284# 
    227 # Example: Imagine that $post->validated is 1: 
    228 #   check_box("post", "validated"); 
    229 # Result: 
    230 #   <input type="checkbox" id="post_validate" name="post[validated] value="1" checked="checked" /> 
    231 #   <input name="post[validated]" type="hidden" value="0" /> 
     285 * Example: Imagine that $post->validated is 1: 
     286 *   check_box("post", "validated"); 
     287 * Result: 
     288 *   <input type="checkbox" id="post_validate" name="post[validated] value="1" checked="checked" /> 
     289 *   <input name="post[validated]" type="hidden" value="0" /> 
    232290# 
    233 # Example: Imagine that $puppy->gooddog is no: 
    234 #   check_box("puppy", "gooddog", array(), "yes", "no"); 
    235 # Result: 
    236 #     <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /> 
    237 #     <input name="puppy[gooddog]" type="hidden" value="no" /> 
     291 * Example: Imagine that $puppy->gooddog is no: 
     292 *   check_box("puppy", "gooddog", array(), "yes", "no"); 
     293 * Result: 
     294 *     <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /> 
     295 *     <input name="puppy[gooddog]" type="hidden" value="no" /> 
     296*/ 
    238297function check_box($object, $field, $options = array(), $checked_value = "1", $unchecked_value = "0") { 
    239298    $form = new FormHelper($object, $field); 
     
    241300} 
    242301 
    243 # Returns a radio button tag for accessing a specified attribute (identified by $field) on an object 
    244 # assigned to the template (identified by $object). If the current value of $field is $tag_value the 
    245 # radio button will be checked. Additional $options on the input tag can be passed as a 
    246 # hash with $options. 
    247 # Example: Imagine that $post->category is "trax": 
    248 #   radio_button("post", "category", "trax"); 
    249 #   radio_button("post", "category", "java"); 
    250 # Result: 
    251 #     <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 
    252 #     <input type="radio" id="post_category" name="post[category] value="java" /> 
     302/** 
     303 * Returns a radio button tag for accessing a specified attribute (identified by $field) on an object 
     304 * assigned to the template (identified by $object). If the current value of $field is $tag_value the 
     305 * radio button will be checked. Additional $options on the input tag can be passed as a 
     306 * hash with $options. 
     307 * Example: Imagine that $post->category is "trax": 
     308 *   radio_button("post", "category", "trax"); 
     309 *   radio_button("post", "category", "java"); 
     310 * Result: 
     311 *     <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 
     312 *     <input type="radio" id="post_category" name="post[category] value="java" /> 
     313*/ 
    253314function radio_button($object, $field, $tag_value, $options = array()) { 
    254315    $form = new FormHelper($object, $field); 
     
    256317} 
    257318 
     319/** 
     320 * 
     321 */ 
    258322function boolean_select($object, $field, $options = array()) { 
    259323    $form = new FormHelper($object, $field);