Index: trunk/extensions/SemanticFormsInputs/SFI_Inputs.php |
— | — | @@ -343,24 +343,23 @@ |
344 | 344 | * @return array of arrays of DateTimes |
345 | 345 | */ |
346 | 346 | static private function createRangesArray ( $rangesAsStrings ) { |
347 | | - |
348 | 347 | // transform array of strings into array of array of dates |
349 | 348 | return array_map( |
350 | | - function( $range ) { |
351 | | - |
352 | | - if ( strpos ( $range, '-' ) === FALSE ) { // single date |
353 | | - $date = date_create( $range ); |
354 | | - return ( $date ) ? array( $date, clone $date ):null; |
355 | | - } else { // date range |
356 | | - $dates = array_map( "date_create", explode( '-', $range ) ); |
357 | | - return ( $dates[0] && $dates[1] ) ? $dates:null; |
358 | | - } |
359 | | - |
360 | | - } , |
361 | | - $rangesAsStrings |
| 349 | + self::createRange(), |
| 350 | + $rangesAsStrings |
362 | 351 | ); |
363 | 352 | |
364 | 353 | } |
| 354 | + |
| 355 | + private static function createRange( $range ) { |
| 356 | + if ( strpos ( $range, '-' ) === FALSE ) { // single date |
| 357 | + $date = date_create( $range ); |
| 358 | + return ( $date ) ? array( $date, clone $date ):null; |
| 359 | + } else { // date range |
| 360 | + $dates = array_map( "date_create", explode( '-', $range ) ); |
| 361 | + return ( $dates[0] && $dates[1] ) ? $dates:null; |
| 362 | + } |
| 363 | + } |
365 | 364 | |
366 | 365 | /** |
367 | 366 | * Takes an array of date ranges and returns an array containing the gaps |
— | — | @@ -767,19 +766,8 @@ |
768 | 767 | // register disabled dates with datepicker |
769 | 768 | if ( count( $disabledDates ) ) { |
770 | 769 | |
771 | | - $disabledDatesString = '[' . implode( ',', array_map( function ( $range ) { |
| 770 | + $disabledDatesString = '[' . implode( ',', array_map( self::createDateString(), $disabledDates ) ) . ']'; |
772 | 771 | |
773 | | - $y0 = $range[0]->format( "Y" ); |
774 | | - $m0 = $range[0]->format( "m" ) - 1; |
775 | | - $d0 = $range[0]->format( "d" ); |
776 | | - |
777 | | - $y1 = $range[1]->format( "Y" ); |
778 | | - $m1 = $range[1]->format( "m" ) - 1; |
779 | | - $d1 = $range[1]->format( "d" ); |
780 | | - |
781 | | - return "[new Date({$y0}, {$m0}, {$d0}), new Date({$y1}, {$m1}, {$d1})]"; |
782 | | - } , $disabledDates ) ) . ']'; |
783 | | - |
784 | 772 | $jstext .= " jQuery(\"#input_{$sfgFieldNum}_show\").datepicker(\"option\", \"disabledDates\", $disabledDatesString);\n"; |
785 | 773 | |
786 | 774 | } |
— | — | @@ -787,19 +775,8 @@ |
788 | 776 | // register highlighted dates with datepicker |
789 | 777 | if ( count( $highlightedDates ) ) { |
790 | 778 | |
791 | | - $highlightedDatesString = '[' . implode( ',', array_map( function ( $range ) { |
| 779 | + $highlightedDatesString = '[' . implode( ',', array_map( self::createDateString(), $highlightedDates ) ) . ']'; |
792 | 780 | |
793 | | - $y0 = $range[0]->format( "Y" ); |
794 | | - $m0 = $range[0]->format( "m" ) - 1; |
795 | | - $d0 = $range[0]->format( "d" ); |
796 | | - |
797 | | - $y1 = $range[1]->format( "Y" ); |
798 | | - $m1 = $range[1]->format( "m" ) - 1; |
799 | | - $d1 = $range[1]->format( "d" ); |
800 | | - |
801 | | - return "[new Date({$y0}, {$m0}, {$d0}), new Date({$y1}, {$m1}, {$d1})]"; |
802 | | - } , $highlightedDates ) ) . ']'; |
803 | | - |
804 | 781 | $jstext .= " jQuery(\"#input_{$sfgFieldNum}_show\").datepicker(\"option\", \"highlightedDates\", $highlightedDatesString);\n"; |
805 | 782 | |
806 | 783 | } |
— | — | @@ -832,13 +809,25 @@ |
833 | 810 | |
834 | 811 | |
835 | 812 | } |
836 | | - |
| 813 | + |
837 | 814 | // add span for error messages (e.g. used for mandatory inputs) |
838 | 815 | $html .= Html::element( "span", array( "id" => "info_$sfgFieldNum", "class" => "errorMessage" ) ); |
839 | 816 | |
840 | 817 | $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
841 | 818 | |
842 | 819 | return array( $html, "" ); |
| 820 | + } |
| 821 | + |
| 822 | + private static function createDateString( $range ) { |
| 823 | + $y0 = $range[0]->format( "Y" ); |
| 824 | + $m0 = $range[0]->format( "m" ) - 1; |
| 825 | + $d0 = $range[0]->format( "d" ); |
843 | 826 | |
| 827 | + $y1 = $range[1]->format( "Y" ); |
| 828 | + $m1 = $range[1]->format( "m" ) - 1; |
| 829 | + $d1 = $range[1]->format( "d" ); |
| 830 | + |
| 831 | + return "[new Date({$y0}, {$m0}, {$d0}), new Date({$y1}, {$m1}, {$d1})]"; |
844 | 832 | } |
| 833 | + |
845 | 834 | } |