Changeset 131 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 02/13/06 12:15:03 (6 years ago)
- Location:
- trunk/trax/vendor/trax/action_view/helpers
- Files:
-
- 3 modified
-
date_helper.php (modified) (19 diffs)
-
form_helper.php (modified) (2 diffs)
-
form_tag_helper.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers/date_helper.php
r128 r131 24 24 25 25 class DateHelper extends Helpers { 26 26 public $selected_years = array(); 27 27 function __construct($object_name = null, $attribute_name = null) { 28 28 parent::__construct(); … … 32 32 33 33 private function value() { 34 if(!$value = $ _REQUEST[$this->object_name][$this->attribute_name]) {34 if(!$value = $this->check_request_for_value()) { 35 35 $object = $this->object(); 36 36 if(is_object($object) && $this->attribute_name) { … … 40 40 return $value; 41 41 } 42 43 private function check_request_for_value() { 44 if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 45 # check if this a date / datetime 46 if($year_value = $_REQUEST[$this->object_name][$this->attribute_name."(1i)"]) { 47 $this->request_years[$this->attribute_name] = $year_value; 48 } 49 if($month_value = $_REQUEST[$this->object_name][$this->attribute_name."(2i)"]) { 50 $this->request_months[$this->attribute_name] = $month_value; 51 } 52 if($day_value = $_REQUEST[$this->object_name][$this->attribute_name."(3i)"]) { 53 $this->request_days[$this->attribute_name] = $day_value; 54 } 55 if($minute_value = $_REQUEST[$this->object_name][$this->attribute_name."(4i)"]) { 56 $this->request_minutes[$this->attribute_name] = $minute_value; 57 } 58 if($hour_value = $_REQUEST[$this->object_name][$this->attribute_name."(5i)"]) { 59 $this->request_hours[$this->attribute_name] = $hour_value; 60 } 61 if($second_value = $_REQUEST[$this->object_name][$this->attribute_name."(6i)"]) { 62 $this->request_seconds[$this->attribute_name] = $second_value; 63 } 64 } 65 return $value; 66 } 42 67 43 68 private function object($object_name = null) { … … 47 72 48 73 private function select_html($type, $options, $prefix = null, $include_blank = false, $discard_type = false) { 49 $select_html = "<select name=\"$prefix"; 50 if(!$discard_type) $select_html .= "[$type]"; 74 $select_html = "<select name=\"$prefix"; 75 if(!$discard_type) { 76 if($prefix) $select_html .= "["; 77 $select_html .= $type; 78 if($prefix) $select_html .= "]"; 79 } 51 80 $select_html .= "\">\n"; 52 81 if($include_blank) $select_html .= "<option value=\"\"></option>\n"; … … 58 87 private function leading_zero_on_single_digits($number) { 59 88 return $number > 9 ? $number : "0$number"; 89 } 90 91 function expiration_date_select($options = array()) { 92 return $this->to_expiration_date_select_tag($options); 60 93 } 61 94 … … 68 101 # datetime_select("post", "written_on") 69 102 # datetime_select("post", "written_on", array("start_year" => 1995)) 70 function date_select($options = array()) { 103 function date_select($options = array()) { 71 104 return $this->to_date_select_tag($options); 72 } 105 } 106 107 function select_expiration_date($date = null, $options = array()) { 108 $options['month_before_year'] = true; 109 $options['use_month_numbers'] = true; 110 $options['start_year'] = date("Y"); 111 $options['end_year'] = date("Y") + 7; 112 $options['field_seperator'] = " / "; 113 $options['field_name'] = $options['year_name'] ? $options['year_name'] : "expiration_year"; 114 $date = ($_REQUEST[$options['field_name']]) ? date("Y-m-d", strtotime($_REQUEST[$options['field_name']]."-01-01")) : date("Y-m-d"); 115 $year_select = $this->select_year($date, $options); 116 $options['field_name'] = $options['month_name'] ? $options['month_name'] : "expiration_month"; 117 $date = ($_REQUEST[$options['field_name']]) ? date("Y-m-d", strtotime("2006-".$_REQUEST[$options['field_name']]."-01")) : date("Y-m-d"); 118 $month_select = $this->select_month($date, $options); 119 if($options['month_before_year']) { 120 $select_html = $month_select . $options['field_seperator'] . $year_select; 121 } else { 122 $select_html = $year_select . $options['field_seperator'] . $month_select; 123 } 124 return $select_html; 125 } 73 126 74 127 # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. … … 103 156 function select_second($datetime, $options = array()) { 104 157 $second_options = ""; 105 106 for($second = 0; $second <= 59; $second++) { 158 159 if($this->request_seconds[$this->attribute_name]) { 160 $datetime_sec = $this->request_seconds[$this->attribute_name]; 161 } elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 162 $datetime_sec = $datetime; 163 } else { 164 $datetime = $datetime ? $datetime : date("Y-m-d H:i:s"); 107 165 $datetime_sec = date("s",strtotime($datetime)); 166 } 167 168 for($second = 0; $second <= 59; $second++) { 108 169 $second_options .= ($datetime && ($datetime_sec == $second)) ? 109 170 "<option value=\"".$this->leading_zero_on_single_digits($second)."\" selected=\"selected\">".$this->leading_zero_on_single_digits($second)."</option>\n" : … … 120 181 function select_minute($datetime, $options = array()) { 121 182 $minute_options = ""; 122 123 for($minute = 0; $minute <= 59; $minute++) { 183 184 if($this->request_minutes[$this->attribute_name]) { 185 $datetime_min = $this->request_minutes[$this->attribute_name]; 186 } elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 187 $datetime_min = $datetime; 188 } else { 189 $datetime = $datetime ? $datetime : date("Y-m-d H:i:s"); 124 190 $datetime_min = date("i",strtotime($datetime)); 191 } 192 193 for($minute = 0; $minute <= 59; $minute++) { 125 194 $minute_options .= ($datetime && ($datetime_min == $minute)) ? 126 195 "<option value=\"".$this->leading_zero_on_single_digits($minute)."\" selected=\"selected\">".$this->leading_zero_on_single_digits($minute)."</option>\n" : … … 136 205 function select_hour($datetime, $options = array()) { 137 206 $hour_options = ""; 207 208 if($this->request_hours[$this->attribute_name]) { 209 $datetime_hour = $this->request_hours[$this->attribute_name]; 210 } elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 211 $datetime_hour = $datetime; 212 } else { 213 $datetime = $datetime ? $datetime : date("Y-m-d H:i:s"); 214 $datetime_hour = date("H",strtotime($datetime)); 215 } 138 216 139 217 for($hour = 0; $hour <= 23; $hour++) { 140 $datetime_hour = date("H",strtotime($datetime));218 141 219 $hour_options .= ($datetime && ($datetime_hour == $hour)) ? 142 220 "<option value=\"".$this->leading_zero_on_single_digits($hour)."\" selected=\"selected\">".$this->leading_zero_on_single_digits($hour)."</option>\n" : … … 152 230 function select_day($datetime, $options = array()) { 153 231 $day_options = ""; 154 155 for($day = 1; $day <= 31; $day++) { 156 $datetime_day = date("d",strtotime($datetime)); 232 233 if($this->request_days[$this->attribute_name]) { 234 $datetime_day = $this->request_days[$this->attribute_name]; 235 } elseif(strlen($datetime) == 2 && is_numeric($datetime)) { 236 $datetime_day = $datetime; 237 } else { 238 $datetime = $datetime ? $datetime : date("Y-m-d H:i:s"); 239 $datetime_day = date("d",strtotime($datetime)); 240 } 241 242 for($day = 1; $day <= 31; $day++) { 157 243 $day_options .= ($datetime && ($datetime_day == $day)) ? 158 244 "<option value=\"".$this->leading_zero_on_single_digits($day)."\" selected=\"selected\">".$this->leading_zero_on_single_digits($day)."</option>\n" : … … 176 262 function select_month($date, $options = array()) { 177 263 $month_options = ""; 178 $date_month = date("m",strtotime($date)); 264 265 if($this->request_months[$this->attribute_name]) { 266 $date_month = $this->request_months[$this->attribute_name]; 267 } elseif(strlen($date) != 2 && !is_numeric($date)) { 268 $date = $date ? $date : date("Y-m-d"); 269 $date_month = date("m",strtotime($date)); 270 } 271 179 272 for($month_number = 1; $month_number <= 12; $month_number++) { 180 273 if($options['use_month_numbers']) { … … 205 298 function select_year($date, $options = array()) { 206 299 $year_options = ""; 207 $y = $date ? date("Y",strtotime($date)) : date("Y"); 300 301 if($this->request_years[$this->attribute_name]) { 302 $date_year = $this->request_years[$this->attribute_name]; 303 } elseif(strlen($date) == 4 && is_numeric($date)) { 304 $date_year = $date; 305 } else { 306 $date_year = $date ? date("Y",strtotime($date)) : date("Y"); 307 } 208 308 209 309 $start_year = ($options['start_year']) ? $options['start_year'] : $y - 5; … … 211 311 212 312 for($year = $start_year; $year <= $end_year; $year++) { 213 $date_year = date("Y",strtotime($date));214 313 $year_options .= ($date && ($date_year == $year)) ? 215 314 "<option value=\"$year\" selected=\"selected\">$year</option>\n" : … … 225 324 $options = array_merge($defaults, $options); 226 325 $options_with_prefix = array(); 227 for($i=1 ; $i < 4; $i++) {326 for($i=1 ; $i <= 3 ; $i++) { 228 327 $options_with_prefix[$i] = array_merge($options, array('prefix' => "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 229 328 } … … 237 336 } 238 337 239 $date_select = '';338 $date_select = array(); 240 339 if($options['month_before_year']) { 241 340 $options['order'] = array('month', 'year', 'day'); … … 253 352 foreach($options['order'] as $param) { 254 353 if(!$discard[$param]) { 255 $date_select .= call_user_func(array($this, "select_$param"), $date, $options_with_prefix[$position[$param]]); 256 } 354 $date_select[] = call_user_func(array($this, "select_$param"), $date, $options_with_prefix[$position[$param]]); 355 } 356 } 357 358 if(count($date_select)) { 359 $seperator = $options['field_seperator'] ? $options['field_seperator'] : " "; 360 $date_select = implode($seperator, $date_select); 257 361 } 258 362 … … 264 368 $options = array_merge($defaults, $options); 265 369 $options_with_prefix = array(); 266 for($i=1 ; $i < 6 ; $i++) {370 for($i=1 ; $i < 6 ; $i++) { 267 371 $options_with_prefix[$i] = array_merge($options, array('prefix' => "{$this->object_name}[{$this->attribute_name}({$i}i)]")); 268 372 } … … 288 392 return $datetime_select; 289 393 } 394 395 function to_expiration_date_select_tag($options = array()) { 396 $options['discard_day'] = true; 397 $options['month_before_year'] = true; 398 $options['use_month_numbers'] = true; 399 $options['start_year'] = date("Y"); 400 $options['end_year'] = date("Y") + 7; 401 $options['field_seperator'] = " / "; 402 return $this->to_date_select_tag($options); 403 } 290 404 291 405 } … … 308 422 } 309 423 424 # select_expiration_date($datetime = null, $options = array()) 425 function select_expiration_date() { 426 $date_helper = new DateHelper(); 427 $args = func_get_args(); 428 return call_user_func_array(array($date_helper, 'select_expiration_date'), $args); 429 } 430 310 431 function datetime_select($object, $attribute, $options = array()) { 311 432 $date_helper = new DateHelper($object, $attribute); 312 $args = func_get_args(); 313 return call_user_func_array(array($date_helper, 'datetime_select'), $options); 433 return $date_helper->datetime_select($options); 314 434 } 315 435 316 436 function date_select($object, $attribute, $options = array()) { 317 437 $date_helper = new DateHelper($object, $attribute); 318 $args = func_get_args(); 319 return call_user_func_array(array($date_helper, 'date_select'), $options); 438 return $date_helper->date_select($options); 439 } 440 441 function expiration_date_select($object, $attribute, $options = array()) { 442 $date_helper = new DateHelper($object, $attribute); 443 return $date_helper->expiration_date_select($options); 444 } 445 446 function select_year() { 447 $date_helper = new DateHelper(); 448 $args = func_get_args(); 449 return call_user_func_array(array($date_helper, 'select_year'), $args); 450 } 451 452 function select_month() { 453 $date_helper = new DateHelper(); 454 $args = func_get_args(); 455 return call_user_func_array(array($date_helper, 'select_month'), $args); 456 } 457 458 function select_day() { 459 $date_helper = new DateHelper(); 460 $args = func_get_args(); 461 return call_user_func_array(array($date_helper, 'select_day'), $args); 320 462 } 321 463 -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
r130 r131 39 39 $object = $this->object(); 40 40 if(is_object($object) && $this->attribute_name) { 41 $attribute = $this->attribute_name; 42 if(!$value = $object->$attribute) { 43 $value = $object->send($attribute); 44 } 41 $value = $object->send($this->attribute_name); 45 42 } 46 43 } … … 115 112 116 113 function to_text_area_tag($options = array()) { 117 if (isset($options["size"])) {118 $options["cols"] = reset(explode('x', $options["size"]));119 $options["rows"] = end(explode('x', $options["size"]));120 unset($options["size"]);121 }122 114 $options = array_merge($this->default_text_area_options, $options); 123 $options = $this->add_default_name_and_id($options); 115 $options = $this->add_default_name_and_id($options); 124 116 return $this->error_wrapping($this->content_tag("textarea", htmlspecialchars($this->value()), $options),$this->object()->errors[$this->attribute_name]); 125 117 } -
trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php
r128 r131 26 26 27 27 28 private function convert_options($options ) {28 private function convert_options($options = array()) { 29 29 $arr = array('disabled', 'readonly', 'multiple'); 30 30 foreach($arr as $a) { 31 $this->boolean_attribute( $options, $a);31 $this->boolean_attribute(&$options, $a); 32 32 } 33 33 return $options; 34 34 } 35 35 36 private function boolean_attribute( $options, $attribute) {37 if( isset($options[$attribute])) {36 private function boolean_attribute(&$options, $attribute) { 37 if($options[$attribute]) { 38 38 $options[$attribute] = $attribute; 39 39 } else { … … 80 80 81 81 function text_area_tag($name, $content = null, $options = array()) { 82 if ( isset($options["size"])) {82 if ($options["size"]) { 83 83 $options["cols"] = reset(explode('x', $options["size"])); 84 84 $options["rows"] = end(explode('x', $options["size"]));
