From 04fea245d8254c7dec8e63bb5288af39ef276f6d Mon Sep 17 00:00:00 2001 From: Romain Louis Date: Sun, 4 Nov 2007 23:01:55 +0000 Subject: [PATCH] PopupDateTimeField adding git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@44226 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/PopupDateTimeField.php | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 forms/PopupDateTimeField.php diff --git a/forms/PopupDateTimeField.php b/forms/PopupDateTimeField.php new file mode 100644 index 000000000..7607e7bbd --- /dev/null +++ b/forms/PopupDateTimeField.php @@ -0,0 +1,78 @@ +id(); + $val = $this->attrValue(); + + $date = $this->attrValueDate(); + $time = $this->attrValueTime(); + + $futureClass = $this->futureOnly ? ' futureonly' : ''; + + $innerHTMLDate = parent::HTMLField( $id . '_Date', $this->name . '[Date]', $date ); + $innerHTMLTime = DropdownTimeField::HTMLField( $id . '_Time', $this->name . '[Time]', $time ); + + return << + + +HTML; + } + + function attrValueDate() { + if( $this->value ) + return date( 'd/m/Y', strtotime( $this->value ) ); + else + return ''; + } + + function attrValueTime() { + if( $this->value ) + return date( 'h:i a', strtotime( $this->value ) ); + else + return ''; + } + + function setValue( $val ) { + if( is_array( $val ) ) { + + // 1) Date + + if( $val[ 'Date' ] && preg_match( '/^([\d]{1,2})\/([\d]{1,2})\/([\d]{2,4})/', $val[ 'Date' ], $parts ) ) + $date = "$parts[3]-$parts[2]-$parts[1]"; + else + $date = null; + + // 2) Time + + $time = $val[ 'Time' ] ? date( 'H:i:s', strtotime( $val[ 'Time' ] ) ) : null; + + if( $date == null ) + $this->value = $time; + else if( $time == null ) + $this->value = $date; + else + $this->value = $date . ' ' . $time; + } + else + $this->value = $val; + } + + function dataValue() { + return $this->value; + } +} + +?> \ No newline at end of file