Changeset 1142
- Timestamp:
- 04/07/06 11:22:55 (3 years ago)
- Files:
-
- trunk/lib/helper/FormHelper.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/helper/FormHelper.php
r1096 r1142 516 516 function select_day_tag($name, $value, $options = array(), $html_options = array()) 517 517 { 518 $options = _parse_attributes($options); 519 518 520 $select_options = array(); 519 520 521 if (_get_option($options, 'include_blank')) 521 522 { … … 532 533 } 533 534 534 $option_tags = options_for_select($select_options, $value); 535 536 return select_tag($name, $option_tags, $html_options); 535 return select_tag($name, options_for_select($select_options, $value), $html_options); 537 536 } 538 537 539 538 function select_month_tag($name, $value, $options = array(), $html_options = array()) 540 539 { 540 $options = _parse_attributes($options); 541 541 542 542 $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); 543 544 543 $I18n_arr = _get_I18n_date_locales($culture); 545 544 546 545 $select_options = array(); 547 548 546 if (_get_option($options, 'include_blank')) 549 547 { … … 580 578 } 581 579 582 $option_tags = options_for_select($select_options, $value); 583 584 return select_tag($name, $option_tags, $html_options); 580 return select_tag($name, options_for_select($select_options, $value), $html_options); 585 581 } 586 582 587 583 function select_year_tag($name, $value, $options = array(), $html_options = array()) 588 584 { 585 $options = _parse_attributes($options); 586 589 587 $select_options = array(); 590 591 588 if (_get_option($options, 'include_blank')) 592 589 { … … 618 615 } 619 616 620 $option_tags = options_for_select($select_options, $value); 621 622 return select_tag($name, $option_tags, $html_options); 617 return select_tag($name, options_for_select($select_options, $value), $html_options); 623 618 } 624 619 … … 629 624 * @param string $value (proper date format: array('year'=>2005, 'month'=>1, 'day'=1) or timestamp or english date text) 630 625 * @param array $options 626 * @param array $html_options 631 627 * @return string 632 628 */ 633 629 function select_date_tag($name, $value, $options = array(), $html_options = array()) 634 630 { 635 $html_options = _parse_attributes($html_options);636 631 $options = _parse_attributes($options); 637 632 … … 649 644 650 645 //discarding month automatically discards day 651 if ($discard_month) 646 if ($discard_month) 647 { 652 648 $discard_day = true; 649 } 653 650 654 651 $order = _get_option($options, 'order'); 655 656 652 $tags = array(); 657 653 658 654 if (is_array($order) && count($order) == 3) 659 655 { 660 foreach ($order as $ k => $v)661 { 662 $tags[] = $v[0]; //'day' => 'd' | 'month' => 'm'656 foreach ($order as $v) 657 { 658 $tags[] = $v[0]; 663 659 } 664 660 } … … 690 686 691 687 $html_options['id'] = $name . '_month'; 692 $m = ( $discard_month != true) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : '';688 $m = (!$discard_month) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 693 689 694 690 $html_options['id'] = $name . '_day'; 695 $d = ( $discard_day != true) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : '';691 $d = (!$discard_day) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 696 692 697 693 $html_options['id'] = $name . '_year'; 698 $y = ( $discard_year != true) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : '';699 700 // we have $tags = array ('m','d','y')694 $y = (!$discard_year) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 695 696 // we have $tags = array ('m','d','y') 701 697 foreach ($tags as $k => $v) 702 698 { 699 // $tags['m|d|y'] = $m|$d|$y 703 700 $tags[$k] = $$v; 704 701 } … … 709 706 function select_second_tag($name, $value, $options = array(), $html_options = array()) 710 707 { 708 $options = _parse_attributes($options); 711 709 $select_options = array(); 712 710 … … 726 724 } 727 725 728 $option_tags = options_for_select($select_options, $value); 729 730 return select_tag($name, $option_tags, $html_options); 726 return select_tag($name, options_for_select($select_options, $value), $html_options); 731 727 } 732 728 733 729 function select_minute_tag($name, $value, $options = array(), $html_options = array()) 734 730 { 731 $options = _parse_attributes($options); 735 732 $select_options = array(); 736 733 … … 750 747 } 751 748 752 $option_tags = options_for_select($select_options, $value); 753 754 return select_tag($name, $option_tags, $html_options); 749 return select_tag($name, options_for_select($select_options, $value), $html_options); 755 750 } 756 751 757 752 function select_hour_tag($name, $value, $options = array(), $html_options = array()) 758 753 { 754 $options = _parse_attributes($options); 759 755 $select_options = array(); 760 756 … … 778 774 } 779 775 780 $option_tags = options_for_select($select_options, $value); 781 782 return select_tag($name, $option_tags, $html_options); 776 return select_tag($name, options_for_select($select_options, $value), $html_options); 783 777 } 784 778 785 779 function select_ampm_tag($name, $value, $options = array(), $html_options = array()) 786 780 { 781 $options = _parse_attributes($options); 787 782 $select_options = array(); 788 783 … … 799 794 $select_options['PM'] = 'PM'; 800 795 801 $option_tags = options_for_select($select_options, $value); 802 803 return select_tag($name, $option_tags, $html_options); 796 return select_tag($name, options_for_select($select_options, $value), $html_options); 804 797 } 805 798 … … 810 803 * @param string $value (proper time format: array('hour'=>0, 'minute'=>0, 'second'=0) or timestamp or english date text) 811 804 * @param array $options 805 * @param array $html_options 812 806 * @return string 813 807 */ 814 808 function select_time_tag($name, $value, $options = array(), $html_options = array()) 815 809 { 816 $html_options = _parse_attributes($html_options);817 810 $options = _parse_attributes($options); 818 811 … … 907 900 } 908 901 909 function _get_I18n_date_locales($culture = '')910 { 911 if ( empty($culture))902 function _get_I18n_date_locales($culture = null) 903 { 904 if (!$culture) 912 905 { 913 906 $culture = sfContext::getInstance()->getUser()->getCulture(); 914 907 } 915 908 916 $ret_val = array(); 917 $ret_val['culture'] = $culture; 909 $retval = array('culture'=>$culture); 918 910 919 911 $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture); 920 912 $date_format = strtolower($dateFormatInfo->getShortDatePattern()); 921 913 922 $ret _val['dateFormatInfo'] = $dateFormatInfo;914 $retval['dateFormatInfo'] = $dateFormatInfo; 923 915 924 916 $match_pattern = "/([dmy]+)(.*?)([dmy]+)(.*?)([dmy]+)/"; … … 929 921 } 930 922 931 $ret _val['date_seperator'] = $match_arr[2];923 $retval['date_seperator'] = $match_arr[2]; 932 924 933 925 //unset all but [dmy]+ 934 926 unset($match_arr[0], $match_arr[2], $match_arr[4]); 935 927 936 $cnt = 0; 937 foreach ($match_arr as $k => $v) 938 { 939 $ret_val['date_order'][$cnt++] = $v[0]; //$arr[date_order][0] = 'm'; [1] = 'd'; [2] = 'y'; 928 $retval['date_order'] = array(); 929 foreach ($match_arr as $v) 930 { 931 // 'm/d/yy' => $retval[date_order] = array ('m', 'd', 'y'); 932 $retval['date_order'][] = $v[0]; 940 933 } 941 934 942 return $ret _val;943 } 944 945 /* *946 * _parse_value_for_date functioncan parse any date field from $value given as:947 * - an array('year'=>2000, 'month'=> 1, .. 948 * - a timestamp 949 * -english text presentation of date (i.e '14:23', '03:30 AM', '2005-12-25' Refer to strtotime function in PHP manual)935 return $retval; 936 } 937 938 /* 939 # _parse_value_for_date can parse any date field from $value given as: 940 # 1. $value = array('year'=>2000, 'month'=>1, 'day'=>1) and $key = 'year|month|day' 941 # 2. $value = timestamp and $format_char = 'h|H|i|s|A|d|m|Y' 942 # 3. english text presentation of date (i.e '14:23', '03:30 AM', '2005-12-25' Refer to strtotime function in PHP manual) 950 943 */ 951 function _parse_value_for_date($value, $ name, $format_char)944 function _parse_value_for_date($value, $key, $format_char) 952 945 { 953 946 if (is_array($value)) 954 947 { 955 return (isset($value[$ name])) ? $value[$name] : '';948 return (isset($value[$key])) ? $value[$key] : ''; 956 949 } 957 950 else if (is_numeric($value)) … … 964 957 } 965 958 959 // english text presentation 966 960 return date($format_char, strtotime($value)); 967 961 }