Changeset 196 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 04/06/06 11:30:43 (6 years ago)
- Location:
- trunk/trax/vendor/trax/action_view
- Files:
-
- 7 modified
-
helpers.php (modified) (10 diffs)
-
helpers/active_record_helper.php (modified) (21 diffs)
-
helpers/asset_tag_helper.php (modified) (12 diffs)
-
helpers/date_helper.php (modified) (12 diffs)
-
helpers/form_helper.php (modified) (20 diffs)
-
helpers/form_tag_helper.php (modified) (1 diff)
-
helpers/url_helper.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers.php
r165 r196 31 31 /** 32 32 * Basic helper functions 33 * 34 * A collection of methods used to generate basic HTML/XML. 33 35 */ 34 36 class Helpers { 35 37 36 38 /** 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 38 92 */ 39 93 function __construct($object_name = null, $attribute_name = null) { … … 46 100 $this->object_name = str_replace("[]", "", $object_name); 47 101 $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; 51 113 if($auto_index) { 52 114 $object = $this->object(); … … 59 121 60 122 /** 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() 62 131 */ 63 132 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])) { 65 136 $object = $this->object(); 66 137 if(is_object($object) && $this->attribute_name) { … … 72 143 73 144 /** 74 * 145 * @todo Document this method 146 * @param string object_name 147 * @uses controller_object 75 148 */ 76 149 protected function object($object_name = null) { … … 125 198 */ 126 199 protected function boolean_attribute(&$options, $attribute) { 127 if($options[$attribute]) { 200 if(array_key_exists($attribute,$options) 201 && $options[$attribute]) { 128 202 $options[$attribute] = $attribute; 129 203 } else { … … 135 209 * Wrap CDATA begin and end tags around argument 136 210 * 137 * Returns a CDATA section for the given +content+. CDATA sections211 * Returns a CDATA section for the given content. CDATA sections 138 212 * are used to escape blocks of text containing characters which would 139 213 * otherwise be recognized as markup. CDATA sections begin with the string 140 * < tt><![CDATA[</tt> and end with (and may not contain) the string141 * < tt>]]></tt>.214 * <samp><![CDATA[</samp> and end with (and may not contain) the string 215 * <samp>]]></samp>. 142 216 * @param string $content Content to wrap 143 217 * @return string Wrapped argument … … 148 222 149 223 /** 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']...) 159 235 * @param boolean $open 160 236 * <ul> … … 162 238 * <li>false => make self-terminating tag (end with ' \>')</li> 163 239 * </ul> 164 * @return string The tag, followed by "\n" 240 * @return string The generated tag, followed by "\n" 241 * @uses tag_options() 165 242 */ 166 243 function tag($name, $options = array(), $open = false) { … … 172 249 173 250 /** 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> 181 263 * @uses tag_options() 182 264 * @param string $name Tag to wrap around $content 183 265 * @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']...) 185 268 * @return string Text wrapped with tag and attributes, 186 269 * followed by "\n" … … 195 278 /** 196 279 * 280 * @uses content_tag() 281 * @uses value() 197 282 */ 198 283 function to_content_tag($tag_name, $options = array()) { -
trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php
r195 r196 37 37 38 38 /** 39 * 39 * @todo Document this variable 40 40 */ 41 41 public $scaffolding = 0; … … 98 98 * @uses all_input_tags() 99 99 * @uses content_tag() 100 * @uses Helpers::object() 100 101 */ 101 102 function form($record_name, $options = array()) { … … 146 147 * <tt>id</tt> - The id of the error div (default: errorExplanation) 147 148 * <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() 148 155 */ 149 156 function error_messages_for($object_name, $options = array()) { … … 171 178 /** 172 179 * @todo Document this method 180 * @uses default_input_block() 173 181 */ 174 182 function all_input_tags($record, $record_name, $options) { … … 203 211 /** 204 212 * @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() 205 227 */ 206 228 function to_tag($object_name, $attribute_name, $options = array()) { … … 245 267 /** 246 268 * @todo Document this method 269 * 270 * @uses attribute_name 271 * @uses column_type() 272 * @uses object() 273 * @uses object_name 247 274 */ 248 275 function to_scaffold_tag($object_name, $attribute_name, $options = array()) { … … 277 304 break; 278 305 default: 279 echo "default case from ".$this->column_type()."\n";280 306 } 281 307 if(count($this->object()->errors)) { … … 287 313 /** 288 314 * @todo Document this method 315 * 316 * @uses tag() 289 317 */ 290 318 function tag_without_error_wrapping() { … … 295 323 /** 296 324 * @todo Document this method 325 * 326 * @uses error_wrapping() 327 * @uses object() 328 * @uses tag_without_error_wrapping() 297 329 */ 298 330 function tag($name, $options = array()) { … … 306 338 /** 307 339 * @todo Document this method 340 * 341 * @uses content_tag() 308 342 */ 309 343 function content_tag_without_error_wrapping() { … … 314 348 /** 315 349 * @todo Document this method 350 * 351 * @uses object() 352 * @uses error_wrapping() 353 * @uses content_tag_without_error_wrapping() 316 354 */ 317 355 function content_tag($name, $value, $options = array()) { … … 325 363 /** 326 364 * @todo Document this method 365 * 366 * @uses object_name 367 * @uses attribute_name 368 * @uses DateHelper::to_date_select_tag() 327 369 */ 328 370 function to_date_select_tag_without_error_wrapping() { … … 345 387 /** 346 388 * @todo Document this method 389 * 390 * @uses attribute_name 391 * @uses object_name 392 * @uses DateHelper::to_datetime_select_tag() 347 393 */ 348 394 function to_datetime_select_tag_without_error_wrapping() { 349 395 $form = new DateHelper($this->object_name, $this->attribute_name); 350 396 $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 356 408 */ 357 409 function to_datetime_select_tag($options = array()) { … … 365 417 /** 366 418 * @todo Document this method 419 * 420 * @param string $html_tag 421 * @param boolean $has_error 367 422 */ 368 423 function error_wrapping($html_tag, $has_error) { … … 372 427 /** 373 428 * @todo Document this method 429 * 430 * @uses attribute_name 431 * @uses object() 374 432 */ 375 433 function error_message() { … … 379 437 /** 380 438 * @todo Document this method 439 * 440 * @uses attribute_name 441 * @uses object() 442 * @uses ActiveRecord::column_for_attribute() 381 443 */ 382 444 function column_type() { … … 390 452 * Avialble functions for use in views 391 453 * error_message_on($object, $attribute_name, $prepend_text = "", $append_text = "", $css_class = "formError") 454 * @uses ActiveRecordHelper::error_message_on() 392 455 */ 393 456 function error_message_on() { … … 398 461 399 462 /** 400 * error_messages_for($object_name, $options = array()) 463 * error_messages_for($object_name, $options = array()) 464 * @uses ActiveRecordHelper::error_messages_for() 401 465 */ 402 466 function error_messages_for() { … … 408 472 /** 409 473 * form($record_name, $options = array()) 474 * @uses ActiveRecordHelper::form() 410 475 */ 411 476 function form() { … … 420 485 * input("post", "title") => 421 486 * <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /> 487 * @uses ActiveRecordHelper::input() 422 488 */ 423 489 function input() { … … 429 495 /** 430 496 * 497 * @uses ActiveRecordHelper::input_scaffolding() 431 498 */ 432 499 function input_scaffolding() { -
trunk/trax/vendor/trax/action_view/helpers/asset_tag_helper.php
r148 r196 31 31 /** 32 32 * @todo Document this class 33 * @package PHPonTrax34 33 */ 35 34 class AssetTagHelper extends Helpers { 36 35 37 36 /** 38 * 37 * @todo Document this method 39 38 * 40 39 */ … … 45 44 46 45 /** 47 * 46 * @todo Document this method 48 47 * 49 48 */ … … 119 118 * 120 119 * stylesheet_path("style") # => /stylesheets/style.css 120 * @uses compute_public_path() 121 121 */ 122 122 function stylesheet_path($source) { … … 138 138 * <link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" /> 139 139 * <link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" /> 140 * @uses stylesheet_path() 141 * @uses tag() 140 142 */ 141 143 function stylesheet_link_tag() { … … 159 161 * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" 160 162 * * file name without extension, like "logo", that gets expanded to "/images/logo.png" 163 * @uses compute_public_path 161 164 */ 162 165 function image_path($source) { … … 174 177 * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" 175 178 * * file name without extension, like "logo", that gets expanded to "/images/logo.png" 179 * @uses Inflector::capitalize() 180 * @uses image_path() 181 * @uses tag() 176 182 */ 177 183 function image_tag($source, $options = array()) { … … 202 208 * auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"}) # => 203 209 * <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.curenthost.com/controller/feed" /> 210 * @uses tag() 204 211 */ 205 212 function auto_discovery_link_tag($type = 'rss', $options = array(), $tag_options = array()) { … … 216 223 217 224 /** 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 */ 221 230 function auto_discovery_link_tag() { 222 231 $asset_helper = new AssetTagHelper(); … … 226 235 227 236 /** 228 * image_tag($source, $options = array()) 229 */ 237 * @todo Document this method 238 * image_tag($source, $options = array()) 239 * @uses AssetTagHelper::image_tag() 240 */ 230 241 function image_tag() { 231 242 $asset_helper = new AssetTagHelper(); … … 235 246 236 247 /** 237 * stylesheet_link_tag($sources) 238 */ 248 * @todo Document this method 249 * stylesheet_link_tag($sources) 250 * @uses AssetTagHelper::stylesheet_link_tag() 251 */ 239 252 function stylesheet_link_tag() { 240 253 $asset_helper = new AssetTagHelper(); … … 244 257 245 258 /** 246 * javascript_include_tag($sources) 247 */ 259 * @todo Document this method 260 * javascript_include_tag($sources) 261 * @uses AssetTagHelper::javascript_include_tag() 262 */ 248 263 function javascript_include_tag() { 249 264 $asset_helper = new AssetTagHelper(); … … 252 267 } 253 268 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: 254 276 ?> -
trunk/trax/vendor/trax/action_view/helpers/date_helper.php
r177 r196 34 34 */ 35 35 class 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 */ 36 70 public $selected_years = array(); 71 37 72 /** 38 73 * @todo Document this method … … 44 79 /** 45 80 * @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 46 89 */ 47 90 private function check_request_for_value() { … … 71 114 72 115 /** 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) { 77 127 $select_html = "<select name=\"$prefix"; 78 128 if(!$discard_type) { … … 89 139 90 140 /** 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 93 144 */ 94 145 private function leading_zero_on_single_digits($number) { … … 137 188 /** 138 189 * @todo Document this method 190 * @uses select_html 139 191 */ 140 192 function select_expiration_date($date = null, $options = array()) { … … 198 250 * Override the field name using the <tt>:field_name</tt> option, 'second' by default. 199 251 * @todo Document this method 252 * @uses select_html 200 253 */ 201 254 function select_second($datetime, $options = array()) { … … 226 279 * Override the field name using the <tt>:field_name</tt> option, 'minute' by default. 227 280 * @todo Document this method 281 * @uses select_html 228 282 */ 229 283 function select_minute($datetime, $options = array()) { … … 253 307 * Override the field name using the <tt>:field_name</tt> option, 'hour' by default. 254 308 * @todo Document this method 309 * @uses select_html 255 310 */ 256 311 function select_hour($datetime, $options = array()) { … … 281 336 * Override the field name using the <tt>:field_name</tt> option, 'day' by default. 282 337 * @todo Document this method 338 * @uses leading_zero_on_single_digits 339 * @uses request_days 340 * @uses select_html 283 341 */ 284 342 function select_day($datetime, $options = array()) { … … 299 357 "<option value=\"".$this->leading_zero_on_single_digits($day)."\">".$this->leading_zero_on_single_digits($day)."</option>\n"; 300 358 } 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)) { 323 429 $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 { 326 442 $date_month = date("m",strtotime($date)); 327 443 } 328 444 445 // Generate <option>...</option> HTML for each month 329 446 for($month_number = 1; $month_number <= 12; $month_number++) { 330 if( $options['use_month_numbers']) {447 if(array_key_exists('use_month_numbers',$options)) { 331 448 $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")); 334 453 } 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")); 336 456 } 337 457 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); 344 477 } 345 478 … … 355 488 * Override the field name using the <tt>:field_name</tt> option, 'year' by default. 356 489 * @todo Document this method 357 */ 490 * @uses select_html 491 */ 358 492 function select_year($date, $options = array()) { 359 493 $year_options = ""; … … 421 555 422 556 if(count($date_select)) { 423 $seperator = $options['field_seperator'] ? $options['field_seperator'] : " "; 557 $seperator = array_key_exists('field_seperator',$options) 558 ? $options['field_seperator'] : " "; 424 559 $date_select = implode($seperator, $date_select); 425 560 } -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
r160 r196 30 30 31 31 /** 32 * 33 * @package PHPonTrax 32 * @todo Document this class 34 33 */ 35 34 class FormHelper extends Helpers { 36 35 37 36 /** 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 39 66 */ 40 67 function __construct($object_name, $attribute_name) { 41 68 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 50 97 */ 51 98 function tag_name() { … … 54 101 55 102 /** 56 * 103 * @todo Document this method 57 104 */ 58 105 function tag_name_with_index($index) { … … 61 108 62 109 /** 63 * 110 * @todo Document this method 64 111 */ 65 112 function tag_id() { … … 68 115 69 116 /** 70 * 117 * @todo Document this method 71 118 */ 72 119 function tag_id_with_index($index) { … … 75 122 76 123 /** 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() 78 131 */ 79 132 function add_default_name_and_id($options) { 80 133 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"]); 83 140 unset($options["index"]); 84 141 } 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); 87 148 } 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(); 90 155 } 91 156 return $options; … … 93 158 94 159 /** 160 * Generate an HTML or XML input tag with optional attributes 95 161 * 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() 96 177 */ 97 178 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; 100 183 $options = array_merge($this->default_field_options, $options); 101 184 if($field_type == "hidden") { … … 104 187 $options["type"] = $field_type; 105 188 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(); 107 191 } 108 192 $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() 114 203 */ 115 204 function to_radio_button_tag($tag_value, $options = array()) { … … 129 218 130 219 /** 131 * 220 * @todo Document this method 221 * @uses add_default_name_and_id() 132 222 */ 133 223 function to_text_area_tag($options = array()) { 134 if ( $options["size"]) {224 if (array_key_exists("size", $options)) { 135 225 $size = explode('x', $options["size"]); 136 226 $options["cols"] = reset($size); … … 140 230 $options = array_merge($this->default_text_area_options, $options); 141 231 $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() 147 243 */ 148 244 function to_check_box_tag($options = array(), $checked_value = "1", $unchecked_value = "0") { … … 177 273 178 274 /** 179 * 275 * @todo Document this method 276 * @uses add_default_name_and_id() 180 277 */ 181 278 function to_boolean_select_tag($options = array()) { … … 198 295 } 199 296 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 */ 200 304 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); 202 308 } 203 309 … … 206 312 207 313 /** 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() 211 324 */ 212 325 function text_field($object, $field, $options = array()) { … … 219 332 * Example: password_field("user", "password"); 220 333 * Result: <input type="password" id="user_password" name="user[password]" value="$user->password" /> 334 * @uses FormHelper::to_input_field_tag() 221 335 */ 222 336 function password_field($object, $field, $options = array()) { … … 229 343 * Example: hidden_field("post", "title"); 230 344 * Result: <input type="hidden" id="post_title" name="post[title]" value="$post->title" /> 345 * @uses FormHelper::to_input_field_tag() 231 346 */ 232 347 function hidden_field($object, $field, $options = array()) { … … 237 352 /** 238 353 * 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() 239 355 */ 240 356 function file_field($object, $field, $options = array()) { … … 246 362 * Example: text_area("post", "body", array("cols" => 20, "rows" => 40)); 247 363 * Result: <textarea cols="20" rows="40" id="post_body" name="post[body]">$post->body</textarea> 364 * @uses FormHelper::to_text_area_tag() 248 365 */ 249 366 function text_area($object, $field, $options = array()) { … … 271 388 * <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /> 272 389 * <input name="puppy[gooddog]" type="hidden" value="no" /> 273 */ 390 * @uses FormHelper::to_check_box_tag() 391 */ 274 392 function check_box($object, $field, $options = array(), $checked_value = "1", $unchecked_value = "0") { 275 393 $form = new FormHelper($object, $field); … … 288 406 * <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 289 407 * <input type="radio" id="post_category" name="post[category] value="java" /> 290 */ 408 * @uses FormHelper::to_radio_button_tag() 409 */ 291 410 function radio_button($object, $field, $tag_value, $options = array()) { 292 411 $form = new FormHelper($object, $field); … … 295 414 296 415 /** 297 * 416 * Make a new FormHelper object and call its to_boolean_select_tag method 417 * @uses FormHelper::to_boolean_select_tag() 298 418 */ 299 419 function boolean_select($object, $field, $options = array()) { … … 302 422 } 303 423 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: 304 431 ?> -
trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php
r155 r196 145 145 * 146 146 * @todo Document this method 147 * @uses tag() 147 148 */ 148 149 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))); 150 154 } 151 155 -
trunk/trax/vendor/trax/action_view/helpers/url_helper.php
r150 r196 76 76 /** 77 77 * @todo Document this method 78 * @param string[] Options 79 * @return string 78 80 */ 79 81 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'])."');"; 82 85 unset($html_options['confirm']); 83 86 } … … 252 255 } 253 256 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: 254 264 ?>
