Changeset 138 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 02/23/06 20:09:13 (6 years ago)
- Location:
- trunk/trax/vendor/trax/action_view
- Files:
-
- 7 modified
-
helpers.php (modified) (7 diffs)
-
helpers/active_record_helper.php (modified) (22 diffs)
-
helpers/date_helper.php (modified) (22 diffs)
-
helpers/form_helper.php (modified) (17 diffs)
-
helpers/form_options_helper.php (modified) (11 diffs)
-
helpers/form_tag_helper.php (modified) (20 diffs)
-
helpers/url_helper.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers.php
r128 r138 1 1 <?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. 2 /** 3 * File containing the Helpers class and associated functions 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 */ 24 30 31 /** 32 * 33 * @package PHPonTrax 34 */ 25 35 class Helpers { 26 36 37 /** 38 * 39 */ 27 40 function __construct() { 28 41 $this->controller_name = $GLOBALS['current_controller_name']; … … 31 44 } 32 45 46 /** 47 * 48 */ 33 49 function tag_options($options) { 34 50 if(count($options)) { … … 43 59 } 44 60 45 # Example: tag("br"); 46 # Results: <br /> 47 # Example: tag("input", array("type" => "text")); 48 # <input type="text" /> 61 /** 62 * Generate an HTML or XML tag with optional attributes 63 * 64 * Example: tag("br"); 65 * Results: <br /> 66 * Example: tag("input", array("type" => "text")); 67 * <input type="text" /> 68 */ 49 69 function tag($name, $options = array(), $open = false) { 50 70 $html = "<$name "; … … 54 74 } 55 75 56 # Example: content_tag("p", "Hello world!"); 57 # Result: <p>Hello world!</p> 58 # Example: content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => 59 # Result:<div class="strong"><p>Hello world!</p></div> 76 /** 77 * Generate an open/close pair of tags with content between 78 * 79 * Example: content_tag("p", "Hello world!"); 80 * Result: <p>Hello world!</p> 81 * Example: content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => 82 * Result:<div class="strong"><p>Hello world!</p></div> 83 */ 60 84 function content_tag($name, $content, $options = array()) { 61 85 $html .= "<$name "; … … 65 89 } 66 90 67 # Returns the URL for the set of $options provided. 91 /** 92 * Return the URL for the set of $options provided. 93 */ 68 94 function url_for($options = array()) { 69 95 $url_base = null; … … 132 158 } 133 159 134 135 ################################################################################################ 136 ## Avialble functions for use in views 137 ################################################################################################ 160 /** 161 * Avialble functions for use in views 162 */ 138 163 function content_tag() { 139 164 $helper = new Helpers(); … … 142 167 } 143 168 169 /** 170 * 171 */ 144 172 function url_for($options = array()) { 145 173 $helper = new Helpers(); -
trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php
r128 r138 1 1 <?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 ActiveRecordHelper class and support functions 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 */ 25 35 class ActiveRecordHelper extends Helpers { 26 36 27 37 public $scaffolding = 0; 28 38 29 # Returns a default input tag for the type of object returned by the method. Example 30 # (title is a VARCHAR column and holds "Hello World"): 31 # input("post", "title") => 32 # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 39 /** 40 * Returns a default input tag for the type of object returned by the method. Example 41 * (title is a VARCHAR column and holds "Hello World"): 42 * input("post", "title") => 43 * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 44 */ 33 45 function input($object_name, $attribute_name, $options = array()) { 34 46 return $this->to_tag($object_name, $attribute_name, $options); 35 47 } 36 48 49 /** 50 * 51 */ 37 52 function input_scaffolding($object_name, $attribute_name, $options = array()) { 38 53 return $this->to_scaffold_tag($object_name, $attribute_name, $options); 39 54 } 40 55 41 # Returns an entire form with input tags and everything for a specified Active Record object. Example 42 # (post is a new record that has a title using VARCHAR and a body using TEXT): 43 # form("post") => 44 # <form action='/post/create' method='post'> 45 # <p> 46 # <label for="post_title">Title</label><br /> 47 # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 48 # </p> 49 # <p> 50 # <label for="post_body">Body</label><br /> 51 # <textarea cols="40" id="post_body" name="post[body]" rows="20"> 52 # Back to the hill and over it again! 53 # </textarea> 54 # </p> 55 # <input type='submit' value='Create' /> 56 # </form> 57 # 58 # It's possible to specialize the form builder by using a different action name and by supplying another 59 # block renderer. Example (entry is a new record that has a message attribute using VARCHAR): 60 # 61 # form("entry", array('action' => "sign", 'input_block' => 62 # 'foreach($record->content_columns() as $column_name => $column) $contents .= Inflector::humanize($column_name) . ": " . input($record, $column) . "<br />"')) => 63 # 64 # <form action='/post/sign' method='post'> 65 # Message: 66 # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br /> 67 # <input type='submit' value='Sign' /> 68 # </form> 69 # 70 # It's also possible to add additional content to the form by giving it a block, such as: 71 # 72 # form("entry", array('action' => "sign", 'block' => 73 # content_tag("b", "Department") . 74 # collection_select("department", "id", $departments, "id", "name")) 75 # ) 56 /** 57 * Returns an entire form with input tags and everything for a specified Active Record object. Example 58 * (post is a new record that has a title using VARCHAR and a body using TEXT): 59 * form("post") => 60 * <form action='/post/create' method='post'> 61 * <p> 62 * <label for="post_title">Title</label><br /> 63 * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 64 * </p> 65 * <p> 66 * <label for="post_body">Body</label><br /> 67 * <textarea cols="40" id="post_body" name="post[body]" rows="20"> 68 * Back to the hill and over it again! 69 * </textarea> 70 * </p> 71 * <input type='submit' value='Create' /> 72 * </form> 73 * 74 * It's possible to specialize the form builder by using a different action name and by supplying another 75 * block renderer. Example (entry is a new record that has a message attribute using VARCHAR): 76 * 77 * form("entry", array('action' => "sign", 'input_block' => 78 * 'foreach($record->content_columns() as $column_name => $column) $contents .= Inflector::humanize($column_name) . ": " . input($record, $column) . "<br />"')) => 79 * 80 * <form action='/post/sign' method='post'> 81 * Message: 82 * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br /> 83 * <input type='submit' value='Sign' /> 84 * </form> 85 * 86 * It's also possible to add additional content to the form by giving it a block, such as: 87 * 88 * form("entry", array('action' => "sign", 'block' => 89 * content_tag("b", "Department") . 90 * collection_select("department", "id", $departments, "id", "name")) 91 * ) 92 */ 76 93 function form($record_name, $options = array()) { 77 94 $record = $this->object($record_name); … … 89 106 } 90 107 91 /* # Returns a string containing the error message attached to the +method+ on the +object+, if one exists. 92 # This error message is wrapped in a DIV tag, which can be specialized to include both a +prepend_text+ and +append_text+ 93 # to properly introduce the error and a +css_class+ to style it accordingly. Examples (post has an error message 94 # "can't be empty" on the title attribute): 95 # 96 # <?= error_message_on("post", "title") ?> => 97 # <div class="formError">can't be empty</div> 98 # 99 # <?= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" ?> => 100 # <div class="inputError">Title simply can't be empty (or it won't work)</div> */ 108 /** 109 * Returns a string containing the error message attached to the +method+ on the +object+, if one exists. 110 * This error message is wrapped in a DIV tag, which can be specialized to include both a +prepend_text+ and +append_text+ 111 * to properly introduce the error and a +css_class+ to style it accordingly. Examples (post has an error message 112 * "can't be empty" on the title attribute): 113 * 114 * <?= error_message_on("post", "title") ?> => 115 * <div class="formError">can't be empty</div> 116 * 117 * <?= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" ?> => 118 * <div class="inputError">Title simply can't be empty (or it won't work)</div> 119 */ 101 120 function error_message_on($object_name, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") { 102 121 $this->object_name = $object_name; … … 108 127 } 109 128 110 # Returns a string with a div containing all the error messages for the object located as an instance variable by the name 111 # of <tt>object_name</tt>. This div can be tailored by the following options: 112 # 113 # * <tt>header_tag</tt> - Used for the header of the error div (default: h2) 114 # * <tt>id</tt> - The id of the error div (default: errorExplanation) 115 # * <tt>class</tt> - The class of the error div (default: errorExplanation) 129 /** 130 * Returns a string with a div containing all the error messages for the object located as an instance variable by the name 131 * of <tt>object_name</tt>. This div can be tailored by the following options: 132 * 133 * <tt>header_tag</tt> - Used for the header of the error div (default: h2) 134 * <tt>id</tt> - The id of the error div (default: errorExplanation) 135 * <tt>class</tt> - The class of the error div (default: errorExplanation) 136 */ 116 137 function error_messages_for($object_name, $options = array()) { 117 138 if(is_object($object_name)) { … … 136 157 } 137 158 159 /** 160 * 161 */ 138 162 function all_input_tags($record, $record_name, $options) { 139 163 //if($record_name) $this->object_name = $record_name; … … 153 177 } 154 178 179 /** 180 * 181 */ 155 182 function default_input_block() { 156 183 if($this->scaffolding) { … … 161 188 } 162 189 190 /** 191 * 192 */ 163 193 function to_tag($object_name, $attribute_name, $options = array()) { 164 194 $this->object_name = $object_name; … … 200 230 } 201 231 232 /** 233 * 234 */ 202 235 function to_scaffold_tag($object_name, $attribute_name, $options = array()) { 203 236 $this->object_name = $object_name; … … 237 270 } 238 271 272 /** 273 * 274 */ 239 275 function object($object_name = null) { 240 276 $object_name = $object_name ? $object_name : $this->object_name; … … 244 280 } 245 281 282 /** 283 * 284 */ 246 285 function tag_without_error_wrapping() { 247 286 $args = func_get_args(); … … 249 288 } 250 289 290 /** 291 * 292 */ 251 293 function tag($name, $options = array()) { 252 294 if(count($this->object()->errors)) { … … 257 299 } 258 300 301 /** 302 * 303 */ 259 304 function content_tag_without_error_wrapping() { 260 305 $args = func_get_args(); … … 262 307 } 263 308 309 /** 310 * 311 */ 264 312 function content_tag($name, $value, $options = array()) { 265 313 if (count($this->object()->errors)) { … … 270 318 } 271 319 320 /** 321 * 322 */ 272 323 function to_date_select_tag_without_error_wrapping() { 273 324 $form = new DateHelper($this->object_name, $this->attribute_name); … … 276 327 } 277 328 329 /** 330 * 331 */ 278 332 function to_date_select_tag($options = array()) { 279 333 if (count($this->object()->errors)) { … … 284 338 } 285 339 340 /** 341 * 342 */ 286 343 function to_datetime_select_tag_without_error_wrapping() { 287 344 $form = new DateHelper($this->object_name, $this->attribute_name); … … 290 347 } 291 348 349 /** 350 * 351 */ 292 352 function to_datetime_select_tag($options = array()) { 293 353 if (count($this->object()->errors)) { … … 298 358 } 299 359 360 /** 361 * 362 */ 300 363 function error_wrapping($html_tag, $has_error) { 301 364 return ($has_error ? '<span class="fieldWithErrors">' . $html_tag . '</span>' : $html_tag); 302 365 } 303 366 367 /** 368 * 369 */ 304 370 function error_message() { 305 371 return $this->object()->errors[$this->attribute_name]; 306 372 } 307 373 374 /** 375 * 376 */ 308 377 function column_type() { 309 378 $column = $this->object()->column_for_attribute($this->attribute_name); … … 313 382 } 314 383 315 ################################################################################################ 316 ##Avialble functions for use in views317 ################################################################################################ 318 # error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") 384 /** 385 * Avialble functions for use in views 386 * error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") 387 */ 319 388 function error_message_on() { 320 389 $ar_helper = new ActiveRecordHelper(); … … 323 392 } 324 393 325 # error_messages_for($object_name, $options = array()) 394 /** 395 * error_messages_for($object_name, $options = array()) 396 */ 326 397 function error_messages_for() { 327 398 $ar_helper = new ActiveRecordHelper(); … … 330 401 } 331 402 332 # form($record_name, $options = array()) 403 /** 404 * form($record_name, $options = array()) 405 */ 333 406 function form() { 334 407 $ar_helper = new ActiveRecordHelper(); … … 337 410 } 338 411 339 # Returns a default input tag for the type of object returned by the method. Example 340 # (title is a VARCHAR column and holds "Hello World"): 341 # input("post", "title") => 342 # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 412 /** 413 * Returns a default input tag for the type of object returned by the method. Example 414 * (title is a VARCHAR column and holds "Hello World"): 415 * input("post", "title") => 416 * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 417 */ 343 418 function input() { 344 419 $ar_helper = new ActiveRecordHelper(); … … 347 422 } 348 423 424 /** 425 * 426 */ 349 427 function input_scaffolding() { 350 428 $ar_helper = new ActiveRecordHelper(); -
trunk/trax/vendor/trax/action_view/helpers/date_helper.php
r131 r138 1 1 <?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 DateHelper class and support functions 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 */ 25 35 class DateHelper extends Helpers { 26 36 public $selected_years = array(); 37 /** 38 * 39 */ 27 40 function __construct($object_name = null, $attribute_name = null) { 28 41 parent::__construct(); … … 31 44 } 32 45 46 /** 47 * 48 */ 33 49 private function value() { 34 50 if(!$value = $this->check_request_for_value()) { … … 66 82 } 67 83 84 /** 85 * 86 */ 68 87 private function object($object_name = null) { 69 88 $object_name = $object_name ? $object_name : $this->object_name; … … 71 90 } 72 91 92 /** 93 * 94 */ 73 95 private function select_html($type, $options, $prefix = null, $include_blank = false, $discard_type = false) { 74 96 $select_html = "<select name=\"$prefix"; … … 85 107 } 86 108 109 /** 110 * 111 */ 87 112 private function leading_zero_on_single_digits($number) { 88 113 return $number > 9 ? $number : "0$number"; … … 93 118 } 94 119 95 # datetime_select("post", "written_on") 96 # datetime_select("post", "written_on", array("start_year" => 1995)) 120 /** 121 * datetime_select("post", "written_on") 122 * datetime_select("post", "written_on", array("start_year" => 1995)) 123 */ 97 124 function datetime_select($options = array()) { 98 125 return $this->to_datetime_select_tag($options); 99 126 } 100 127 101 # datetime_select("post", "written_on") 102 # datetime_select("post", "written_on", array("start_year" => 1995)) 128 /** 129 * datetime_select("post", "written_on") 130 * datetime_select("post", "written_on", array("start_year" => 1995)) 131 */ 103 132 function date_select($options = array()) { 104 133 return $this->to_date_select_tag($options); … … 125 154 } 126 155 127 # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. 156 /** 157 * Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. 158 */ 128 159 function select_date($date = null, $options = array()) { 129 160 $date = is_null($date) ? date("Y-m-d") : $date; … … 133 164 } 134 165 135 # Returns a set of html select-tags (one for year, month, day, hour, and minute) preselected the +datetime+. 166 /** 167 * Returns a set of html select-tags (one for year, month, day, hour, and minute) preselected the +datetime+. 168 */ 136 169 function select_datetime($datetime = null, $options = array()) { 137 170 $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; … … 143 176 } 144 177 145 # Returns a set of html select-tags (one for hour and minute) 178 /** 179 * Returns a set of html select-tags (one for hour and minute) 180 */ 146 181 function select_time($datetime = null, $options = array()) { 147 182 $datetime = is_null($datetime) ? date("Y-m-d H:i:s") : $datetime; … … 151 186 } 152 187 153 # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. 154 # The <tt>second</tt> can also be substituted for a second number. 155 # Override the field name using the <tt>:field_name</tt> option, 'second' by default. 188 /** 189 * Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. 190 * The <tt>second</tt> can also be substituted for a second number. 191 * Override the field name using the <tt>:field_name</tt> option, 'second' by default. 192 */ 156 193 function select_second($datetime, $options = array()) { 157 194 $second_options = ""; … … 175 212 } 176 213 177 # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. 178 # Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected 179 # The <tt>minute</tt> can also be substituted for a minute number. 180 # Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 214 /** 215 * Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. 216 * Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected 217 * The <tt>minute</tt> can also be substituted for a minute number. 218 * Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 219 */ 181 220 function select_minute($datetime, $options = array()) { 182 221 $minute_options = ""; … … 200 239 } 201 240 202 # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. 203 # The <tt>hour</tt> can also be substituted for a hour number. 204 # Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 241 /** 242 * Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. 243 * The <tt>hour</tt> can also be substituted for a hour number. 244 * Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 245 */ 205 246 function select_hour($datetime, $options = array()) { 206 247 $hour_options = ""; … … 225 266 } 226 267 227 # Returns a select tag with options for each of the days 1 through 31 with the current day selected. 228 # The <tt>date</tt> can also be substituted for a hour number. 229 # Override the field name using the <tt>:field_name</tt> option, 'day' by default. 268 /** 269 * Returns a select tag with options for each of the days 1 through 31 with the current day selected. 270 * The <tt>date</tt> can also be substituted for a hour number. 271 * Override the field name using the <tt>:field_name</tt> option, 'day' by default. 272 */ 230 273 function select_day($datetime, $options = array()) { 231 274 $day_options = ""; … … 249 292 } 250 293 251 # Returns a select tag with options for each of the months January through December with the current month selected. 252 # The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values 253 # (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names -- 254 # set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names, 255 # set the <tt>:add_month_numbers</tt> key in +options+ to true. Examples: 256 # 257 # select_month(Date.today) # Will use keys like "January", "March" 258 # select_month(Date.today, :use_month_numbers => true) # Will use keys like "1", "3" 259 # select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March" 260 # 261 # Override the field name using the <tt>:field_name</tt> option, 'month' by default. 294 /** 295 * Returns a select tag with options for each of the months January through December with the current month selected. 296 * The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values 297 * (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names -- 298 * set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names, 299 * set the <tt>:add_month_numbers</tt> key in +options+ to true. Examples: 300 * 301 * select_month(Date.today) # Will use keys like "January", "March" 302 * select_month(Date.today, :use_month_numbers => true) # Will use keys like "1", "3" 303 * select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March" 304 * 305 * Override the field name using the <tt>:field_name</tt> option, 'month' by default. 306 */ 262 307 function select_month($date, $options = array()) { 263 308 $month_options = ""; … … 287 332 } 288 333 289 # 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 290 # can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year 291 # 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 292 # substituted for a year given as a number. Example: 293 # 294 # select_year(Date.today, :start_year => 1992, :end_year => 2007) # ascending year values 295 # select_year(Date.today, :start_year => 2005, :end_year => 1900) # descending year values 296 # 297 # Override the field name using the <tt>:field_name</tt> option, 'year' by default. 334 /** 335 * 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 336 * can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year 337 * 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 338 * substituted for a year given as a number. Example: 339 * 340 * select_year(Date.today, :start_year => 1992, :end_year => 2007) # ascending year values 341 * select_year(Date.today, :start_year => 2005, :end_year => 1900) # descending year values 342 * 343 * Override the field name using the <tt>:field_name</tt> option, 'year' by default. 344 */ 298 345 function select_year($date, $options = array()) { 299 346 $year_options = ""; … … 320 367 } 321 368 369 /** 370 * 371 */ 322 372 function to_date_select_tag($options = array()) { 323 373 $defaults = array('discard_type' => true); … … 364 414 } 365 415 416 /** 417 * 418 */ 366 419 function to_datetime_select_tag($options = array()) { 367 420 $defaults = array('discard_type' => true); … … 405 458 } 406 459 407 ################################################################################################ 408 ##Avialble functions for use in views409 ################################################################################################ 410 # select_date($date = null, $options = array()) 460 /** 461 * Avialble functions for use in views 462 * select_date($date = null, $options = array()) 463 */ 411 464 function select_date() { 412 465 $date_helper = new DateHelper(); … … 415 468 } 416 469 417 # select_datetime($datetime = null, $options = array()) 470 /** 471 * Select_datetime($datetime = null, $options = array()) 472 */ 418 473 function select_datetime() { 419 474 $date_helper = new DateHelper(); … … 422 477 } 423 478 424 # select_expiration_date($datetime = null, $options = array()) 479 /** 480 * select_expiration_date($datetime = null, $options = array()) 481 */ 425 482 function select_expiration_date() { 426 483 $date_helper = new DateHelper(); … … 429 486 } 430 487 488 /** 489 * 490 */ 431 491 function datetime_select($object, $attribute, $options = array()) { 432 492 $date_helper = new DateHelper($object, $attribute); … … 434 494 } 435 495 496 /** 497 * 498 */ 436 499 function date_select($object, $attribute, $options = array()) { 437 500 $date_helper = new DateHelper($object, $attribute); -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
r132 r138 1 1 <?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 */ 25 35 class FormHelper extends Helpers { 26 36 37 /** 38 * 39 */ 27 40 function __construct($object_name, $attribute_name) { 28 41 parent::__construct(); … … 35 48 } 36 49 50 /** 51 * 52 */ 37 53 function value() { 38 54 if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { … … 45 61 } 46 62 63 /** 64 * 65 */ 47 66 function object($object_name = null) { 48 67 $object_name = $object_name ? $object_name : $this->object_name; … … 50 69 } 51 70 71 /** 72 * 73 */ 52 74 function tag_name() { 53 75 return "{$this->object_name}[{$this->attribute_name}]"; 54 76 } 55 77 78 /** 79 * 80 */ 56 81 function tag_name_with_index($index) { 57 82 return "{$this->object_name}[{$index}][{$this->attribute_name}]"; 58 83 } 59 84 85 /** 86 * 87 */ 60 88 function tag_id() { 61 89 return "{$this->object_name}_{$this->attribute_name}"; 62 90 } 63 91 92 /** 93 * 94 */ 64 95 function tag_id_with_index($index) { 65 96 return "{$this->object_name}_{$index}_{$this->attribute_name}"; 66 97 } 67 98 99 /** 100 * 101 */ 68 102 function add_default_name_and_id($options) { 69 103 if(array_key_exists("index", $options)) { … … 81 115 } 82 116 117 /** 118 * 119 */ 83 120 function to_input_field_tag($field_type, $options = array()) { 84 121 $default_size = $options["maxlength"] ? $options["maxlength"] : $this->default_field_options['size']; … … 96 133 } 97 134 135 /** 136 * 137 */ 98 138 function to_radio_button_tag($tag_value, $options = array()) { 99 139 $options = array_merge($this->default_radio_options, $options); … … 111 151 } 112 152 153 /** 154 * 155 */ 113 156 function to_text_area_tag($options = array()) { 114 157 if ($options["size"]) { … … 123 166 } 124 167 168 /** 169 * 170 */ 125 171 function to_check_box_tag($options = array(), $checked_value = "1", $unchecked_value = "0") { 126 172 $options["type"] = "checkbox"; … … 153 199 } 154 200 201 /** 202 * 203 */ 155 204 function to_boolean_select_tag($options = array()) { 156 205 $options = $this->add_default_name_and_id($options); … … 179 228 180 229 181 ################################################################################################ 182 ##Avialble functions for use in views183 ################################################################################################ 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 */ 186 235 function text_field($object, $field, $options = array()) { 187 236 $form = new FormHelper($object, $field); … … 189 238 } 190 239 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 */ 194 245 function password_field($object, $field, $options = array()) { 195 246 $form = new FormHelper($object, $field); … … 197 248 } 198 249 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 */ 202 255 function hidden_field($object, $field, $options = array()) { 203 256 $form = new FormHelper($object, $field); … … 205 258 } 206 259 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 */ 208 263 function file_field($object, $field, $options = array()) { 209 264 $form = new FormHelper($object, $field); … … 211 266 } 212 267 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 */ 215 272 function text_area($object, $field, $options = array()) { 216 273 $form = new FormHelper($object, $field); … … 218 275 } 219 276 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. 226 284 # 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" /> 232 290 # 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 */ 238 297 function check_box($object, $field, $options = array(), $checked_value = "1", $unchecked_value = "0") { 239 298 $form = new FormHelper($object, $field); … … 241 300 } 242 301 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 */ 253 314 function radio_button($object, $field, $tag_value, $options = array()) { 254 315 $form = new FormHelper($object, $field); … … 256 317 } 257 318 319 /** 320 * 321 */ 258 322 function boolean_select($object, $field, $options = array()) { 259 323 $form = new FormHelper($object, $field); -
trunk/trax/vendor/trax/action_view/helpers/form_options_helper.php
r117 r138 1 1 <?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 25 # All the countries included in the country_options output. 2 /** 3 * File containing the FormOptionsHelper class and support functions 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 * All the countries included in the country_options output. 33 */ 26 34 if(!$GLOBALS['COUNTRIES']) { 27 35 $GLOBALS['COUNTRIES'] = … … 72 80 } 73 81 82 /** 83 * 84 * @package PHPonTrax 85 */ 74 86 class FormOptionsHelper extends FormHelper { 75 87 76 # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container 77 # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and 78 # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values 79 # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. +Selected+ 80 # may also be an array of values to be selected when using a multiple select. 81 # 82 # Examples (call, result): 83 # options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) 84 # <option value="$">Dollar</option>\n<option value="DKK">Kroner</option> 85 # 86 # options_for_select([ "VISA", "MasterCard" ], "MasterCard") 87 # <option>VISA</option>\n<option selected="selected">MasterCard</option> 88 # 89 # options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40") 90 # <option value="$20">Basic</option>\n<option value="$40" selected="selected">Plus</option> 91 # 92 # options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"]) 93 # <option selected="selected">VISA</option>\n<option>MasterCard</option>\n<option selected="selected">Discover</option> 94 # 95 # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 88 /** 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. 94 * 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. 109 */ 96 110 function options_for_select($choices, $selected = null) { 97 111 $options = array(); … … 113 127 } 114 128 115 # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the 116 # the result of a call to the +value_method+ as the option value and the +text_method+ as the option text. 117 # If +selected_value+ is specified, the element returning a match on +value_method+ will get the selected option tag. 118 # 119 # Example (call, result). Imagine a loop iterating over each +person+ in <tt>@project.people</tt> to generate an input tag: 120 # options_from_collection_for_select(@project.people, "id", "name") 121 # <option value="#{person.id}">#{person.name}</option> 122 # 123 # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 129 /** 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: 135 * options_from_collection_for_select(@project.people, "id", "name") 136 * <option value="#{person.id}">#{person.name}</option> 137 * 138 * NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 139 */ 124 140 function options_from_collection_for_select($collection, $attribute_value, $attribute_text, $selected_value = null) { 125 141 $options = array(); … … 134 150 } 135 151 136 # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to 137 # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so 138 # that they will be listed above the rest of the (long) list. 139 # 140 # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. 152 /** 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 */ 141 159 function country_options_for_select($selected = null, $priority_countries = array()) { 142 160 $country_options = ""; … … 155 173 } 156 174 175 /** 176 * 177 */ 157 178 function to_select_tag($choices, $options, $html_options) { 158 179 $html_options = $this->add_default_name_and_id($html_options); … … 160 181 } 161 182 183 /** 184 * 185 */ 162 186 function to_collection_select_tag($collection, $attribute_value, $attribute_text, $options, $html_options) { 163 187 $html_options = $this->add_default_name_and_id($html_options); … … 165 189 } 166 190 191 /** 192 * 193 */ 167 194 function to_country_select_tag($priority_countries, $options, $html_options) { 168 195 $html_options = $this->add_default_name_and_id($html_options); … … 170 197 } 171 198 199 /** 200 * 201 */ 172 202 private function add_options($option_tags, $options, $value = null) { 173 203 if($options["include_blank"] == true) { … … 184 214 } 185 215 186 ################################################################################################ 187 ##Avialble functions for use in views188 ################################################################################################ 189 # Create a select tag and a series of contained option tags for the provided object and method.190 # The option currently held by the object will be selected, provided that the object is available.191 # See options_for_select for the required format of the choices parameter.192 # 193 # Example with @post.person_id => 1: 194 # select("post", "person_id", Person.find_all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })195 # 196 # could become:197 # 198 # <select name="post[person_id">199 # <option></option>200 # <option value="1" selected="selected">David</option>201 # <option value="2">Sam</option>202 # <option value="3">Tobias</option>203 # </select>204 # 205 # This can be used to provide a functionault set of options in the standard way: before r}ering the create form, a 206 # new model instance is assigned the functionault options and bound to @model_name. Usually this model is not saved 207 # to the database. Instead, a second model object is created when the create request is received.208 # This allows the user to submit a form page more than once with the expected results of creating multiple records.209 # In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. 216 /** 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. 221 # 222 * Example with @post.person_id => 1: 223 * select("post", "person_id", Person.find_all.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) 224 # 225 * could become: 226 # 227 * <select name="post[person_id"> 228 * <option></option> 229 * <option value="1" selected="selected">David</option> 230 * <option value="2">Sam</option> 231 * <option value="3">Tobias</option> 232 * </select> 233 # 234 * This can be used to provide a functionault set of options in the standard way: before r}ering the create form, a 235 * new model instance is assigned the functionault options and bound to @model_name. Usually this model is not saved 236 * to the database. Instead, a second model object is created when the create request is received. 237 * This allows the user to submit a form page more than once with the expected results of creating multiple records. 238 * In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. 239 */ 210 240 function select($object_name, $attribute_name, $choices, $options = array(), $html_options = array()) { 211 241 $form = new FormOptionsHelper($object_name, $attribute_name); … … 213 243 } 214 244 215 # Return select and option tags for the given object and method using 216 # options_from_collection_for_select to generate the list of option tags. 245 /** 246 * Return select and option tags for the given object and method using 247 * options_from_collection_for_select to generate the list of option tags. 248 */ 217 249 function collection_select($object_name, $attribute_name, $collection, $attribute_value, $attribute_text, $options = array(), $html_options = array()) { 218 250 $form = new FormOptionsHelper($object_name, $attribute_name); … … 220 252 } 221 253 222 # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. 254 /** 255 * Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. 256 */ 223 257 function country_select($object_name, $attribute_name, $priority_countries = null, $options = array(), $html_options = array()) { 224 258 $form = new FormOptionsHelper($object_name, $attribute_name); -
trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php
r132 r138 1 1 <?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 FormTagHelper class and support functions 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 */ 25 35 class FormTagHelper extends Helpers { 26 36 27 37 /** 38 * 39 */ 28 40 private function convert_options($options = array()) { 29 41 $arr = array('disabled', 'readonly', 'multiple'); … … 34 46 } 35 47 48 /** 49 * 50 */ 36 51 private function boolean_attribute(&$options, $attribute) { 37 52 if($options[$attribute]) { … … 42 57 } 43 58 59 /** 60 * 61 */ 44 62 function form_tag($url_for_options = array(), $options = array(), $parameters_for_url = array()) { 45 63 $html_options = array_merge(array("method" => "post"), $options); … … 54 72 } 55 73 74 /** 75 * 76 */ 56 77 function start_form_tag() { 57 78 $args = func_get_args(); … … 59 80 } 60 81 82 /** 83 * 84 */ 61 85 function select_tag($name, $option_tags = null, $options = array()) { 62 86 return $this->content_tag("select", $option_tags, array_merge(array("name" => $name, "id" => $name), $this->convert_options($options))); 63 87 } 64 88 89 /** 90 * 91 */ 65 92 function text_field_tag($name, $value = null, $options = array()) { 66 93 return $this->tag("input", array_merge(array("type" => "text", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options))); 67 94 } 68 95 96 /** 97 * 98 */ 69 99 function hidden_field_tag($name, $value = null, $options = array()) { 70 100 return $this->text_field_tag($name, $value, array_merge($options, array("type" => "hidden"))); 71 101 } 72 102 103 /** 104 * 105 */ 73 106 function file_field_tag($name, $options = array()) { 74 107 return $this->text_field_tag($name, null, array_merge($this->convert_options($options), array("type" => "file"))); 75 108 } 76 109 110 /** 111 * 112 */ 77 113 function password_field_tag($name = "password", $value = null, $options = array()) { 78 114 return $this->text_field_tag($name, $value, array_merge($this->convert_options($options), array("type" => "password"))); 79 115 } 80 116 117 /** 118 * 119 */ 81 120 function text_area_tag($name, $content = null, $options = array()) { 82 121 if ($options["size"]) { … … 90 129 } 91 130 131 /** 132 * 133 */ 92 134 function check_box_tag($name, $value = "1", $checked = false, $options = array()) { 93 135 $html_options = array_merge(array("type" => "checkbox", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options)); … … 96 138 } 97 139 140 /** 141 * 142 */ 98 143 function radio_button_tag($name, $value, $checked = false, $options = array()) { 99 144 $html_options = array_merge(array("type" => "radio", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options)); … … 102 147 } 103 148 149 /** 150 * 151 */ 104 152 function submit_tag($value = "Save changes", $options = array()) { 105 153 return $this->tag("input", array_merge(array("type" => "submit", "name" => "commit", "value" => $value), $this->convert_options($options))); 106 154 } 107 155 156 /** 157 * 158 */ 108 159 function image_submit_tag($source, $options = array()) { 109 160 return $this->tag("input", array_merge(array("type" => "image", "src" => image_path($source)), $this->convert_options($options))); … … 112 163 } 113 164 114 ################################################################################################ 115 ##Avialble functions for use in views116 ################################################################################################ 165 /** 166 * Avialble functions for use in views 167 */ 117 168 function form_tag() { 118 169 $form_tag_helper = new FormTagHelper(); … … 121 172 } 122 173 174 /** 175 * 176 */ 123 177 function start_form_tag() { 124 178 $args = func_get_args(); … … 126 180 } 127 181 182 /** 183 * 184 */ 128 185 function end_form_tag() { 129 186 return "</form>"; 130 187 } 131 188 189 /** 190 * 191 */ 132 192 function select_tag() { 133 193 $form_tag_helper = new FormTagHelper(); … … 136 196 } 137 197 198 /** 199 * 200 */ 138 201 function text_field_tag() { 139 202 $form_tag_helper = new FormTagHelper(); … … 142 205 } 143 206 207 /** 208 * 209 */ 144 210 function hidden_field_tag() { 145 211 $form_tag_helper = new FormTagHelper(); … … 148 214 } 149 215 216 /** 217 * 218 */ 150 219 function file_field_tag() { 151 220 $form_tag_helper = new FormTagHelper(); … … 154 223 } 155 224 225 /** 226 * 227 */ 156 228 function password_field_tag() { 157 229 $form_tag_helper = new FormTagHelper(); … … 160 232 } 161 233 234 /** 235 * 236 */ 162 237 function text_area_tag() { 163 238 $form_tag_helper = new FormTagHelper(); … … 166 241 } 167 242 243 /** 244 * 245 */ 168 246 function check_box_tag() { 169 247 $form_tag_helper = new FormTagHelper(); … … 172 250 } 173 251 252 /** 253 * 254 */ 174 255 function radio_button_tag() { 175 256 $form_tag_helper = new FormTagHelper(); … … 178 259 } 179 260 261 /** 262 * 263 */ 180 264 function submit_tag() { 181 265 $form_tag_helper = new FormTagHelper(); … … 184 268 } 185 269 270 /** 271 * 272 */ 186 273 function image_submit_tag() { 187 274 $form_tag_helper = new FormTagHelper(); -
trunk/trax/vendor/trax/action_view/helpers/url_helper.php
r117 r138 1 1 <?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. 2 /** 3 * File containing the UrlHelper class and support functions 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 */ 24 30 31 /** 32 * @todo Document this class 33 * @package PHPonTrax 34 */ 25 35 class UrlHelper extends Helpers { 26 36 27 # Creates a link tag of the given +name+ using an URL created by the set of +options+. 28 # It's also possible to pass a string instead of an options hash to 29 # get a link tag that just points without consideration. If null is passed as a name, the link itself will become the name. 30 # The $html_options have a special feature for creating javascript confirm alerts where if you pass ":confirm" => 'Are you sure?', 31 # the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not. 32 # 33 # Example: 34 # link_to("Delete this page", array(":action" => "delete", ":id" => $page->id), array(":confirm" => "Are you sure?")) 37 /** 38 * Creates a link tag of the given +name+ using an URL created by the set of +options+. 39 * It's also possible to pass a string instead of an options hash to 40 * get a link tag that just points without consideration. If null is passed as a name, the link itself will become the name. 41 * The $html_options have a special feature for creating javascript confirm alerts where if you pass ":confirm" => 'Are you sure?', 42 * the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not. 43 * 44 * Example: 45 * link_to("Delete this page", array(":action" => "delete", ":id" => $page->id), array(":confirm" => "Are you sure?")) 46 */ 35 47 function link_to($name, $options = array(), $html_options = array()) { 36 48 $html_options = $this->convert_confirm_option_to_javascript($html_options); … … 62 74 } 63 75 76 /** 77 * @todo Document this method 78 */ 64 79 function convert_confirm_option_to_javascript($html_options) { 65 80 if($html_options['confirm']) { … … 70 85 } 71 86 87 /** 88 * @todo Document this method 89 */ 72 90 function convert_boolean_attributes(&$html_options, $bool_attrs) { 73 91 foreach($bool_attrs as $x) { … … 80 98 } 81 99 100 /** 101 * @todo Document this method 102 */ 82 103 function button_to($name, $options = array(), $html_options = null) { 83 104 $html_options = (!is_null($html_options) ? $html_options : array()); … … 97 118 } 98 119 99 # This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like: 100 # link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com") 120 /** 121 * This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like: 122 * link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com") 123 */ 101 124 function link_image_to($src, $options = array(), $html_options = array(), $parameters_for_method_reference = array()) { 102 125 $image_options = array("src" => (ereg("/", $src) ? $src : "/images/$src")); … … 131 154 } 132 155 133 ################################################################################################ 134 ## Avialble functions for use in views 135 ################################################################################################ 156 /** 157 * Avialble functions for use in views 158 * @todo Document this function 159 */ 136 160 function link_to($name, $options = array(), $html_options = array()) { 137 161 $url_helper = new UrlHelper();
