2007-11-05 00:01:55 +01:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* Field for entering a date/time pair.
|
2009-05-22 04:00:50 +02:00
|
|
|
*
|
2009-04-02 19:17:04 +02:00
|
|
|
* @todo Add localization support, see http://open.silverstripe.com/ticket/2931
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-datetime
|
|
|
|
*/
|
2007-11-05 00:01:55 +01:00
|
|
|
class PopupDateTimeField extends CalendarDateField {
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
/**
|
|
|
|
* @todo js validation needs to be implemented.
|
|
|
|
* @see sapphire/forms/DateField#jsValidation()
|
|
|
|
*/
|
|
|
|
function jsValidation() {
|
|
|
|
}
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
/**
|
|
|
|
* @todo php validation needs to be implemented.
|
|
|
|
* @see sapphire/forms/DateField#validate($validator)
|
|
|
|
*/
|
|
|
|
function validate() {
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
function Field() {
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::css( SAPPHIRE_DIR . '/css/PopupDateTimeField.css' );
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
$field = parent::Field();
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
DropdownTimeField::Requirements();
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
$id = $this->id();
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
$val = $this->attrValue();
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
$date = $this->attrValueDate();
|
|
|
|
$time = $this->attrValueTime();
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
$futureClass = $this->futureOnly ? ' futureonly' : '';
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2009-11-21 03:31:23 +01:00
|
|
|
$innerHTMLDate = sprintf(
|
|
|
|
'<input type="text" id="%s" name="%s" value="%s" />',
|
|
|
|
$id . '_Date',
|
|
|
|
$this->name . '[Date]',
|
|
|
|
$date
|
|
|
|
);
|
2007-11-05 00:01:55 +01:00
|
|
|
$innerHTMLTime = DropdownTimeField::HTMLField( $id . '_Time', $this->name . '[Time]', $time );
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
return <<<HTML
|
|
|
|
<div class="popupdatetime">
|
|
|
|
<ul>
|
|
|
|
<li class="calendardate$futureClass">$innerHTMLDate</li>
|
|
|
|
<li class="dropdowntime">$innerHTMLTime</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
}
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
function attrValueDate() {
|
|
|
|
if( $this->value )
|
2009-05-22 04:00:50 +02:00
|
|
|
return date( 'd/m/Y', strtotime( $this->value ) );
|
2007-11-05 00:01:55 +01:00
|
|
|
else
|
|
|
|
return '';
|
|
|
|
}
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
function attrValueTime() {
|
|
|
|
if( $this->value )
|
2009-05-22 04:00:50 +02:00
|
|
|
return date( 'h:i a', strtotime( $this->value ) );
|
2007-11-05 00:01:55 +01:00
|
|
|
else
|
|
|
|
return '';
|
|
|
|
}
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
function setValue( $val ) {
|
2009-05-22 04:00:50 +02:00
|
|
|
if( is_array( $val ) ) {
|
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
// 1) Date
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
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;
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
// 2) Time
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
$time = $val[ 'Time' ] ? date( 'H:i:s', strtotime( $val[ 'Time' ] ) ) : null;
|
2009-05-22 04:00:50 +02:00
|
|
|
|
2007-11-05 00:01:55 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|