2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-01-10 01:34:18 +01:00
|
|
|
* Time field.
|
2007-07-19 12:40:28 +02:00
|
|
|
* Default Value represented in the format passed as constructor.
|
|
|
|
*
|
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-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class TimeField extends TextField {
|
|
|
|
// Stores our time format;
|
|
|
|
protected $timeformat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor saves the format difference. Timefields shouldn't
|
|
|
|
* have a problem with length as times can only be represented in on way.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @param $name string The name of the field
|
|
|
|
* @param $title string The Title of the field
|
|
|
|
* @param $value string the value for the field
|
|
|
|
* @param $timeformat string The Time format in date php format e.g. G:ia
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function __construct($name, $title = null, $value = "",$timeformat = "g:ia"){
|
|
|
|
parent::__construct($name,$title,$value);
|
|
|
|
$this->timeformat = $timeformat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the setValue to store the time (in a datetime field)
|
|
|
|
* we store the current date as well (although we don't use it for this field)
|
|
|
|
*/
|
2007-11-02 04:12:37 +01:00
|
|
|
function setValue( $val ) {
|
|
|
|
if( $val )
|
|
|
|
$this->value = (date("Y-m-d",time()) . " " . date("H:i",strtotime($val)) );
|
|
|
|
else
|
|
|
|
$this->value = null;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new readonly field specified below
|
|
|
|
*/
|
|
|
|
function performReadonlyTransformation() {
|
|
|
|
return new TimeField_Readonly( $this->name, $this->title, $this->dataValue(),$this->timeformat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Added to the value of the input, put the date into the format
|
|
|
|
* specified in the constructer.
|
|
|
|
*/
|
|
|
|
function attrValue(){
|
|
|
|
if($this->value){
|
|
|
|
return date($this->timeformat,strtotime($this->value));
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-10 01:34:18 +01:00
|
|
|
* The readonly class for our {@link TimeField}.
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-datetime
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class TimeField_Readonly extends TimeField {
|
2007-11-06 21:43:19 +01:00
|
|
|
|
2008-08-12 04:58:48 +02:00
|
|
|
protected $readonly = true;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Field() {
|
2007-11-06 21:43:19 +01:00
|
|
|
if( $this->value )
|
|
|
|
$val = $this->attrValue();
|
|
|
|
else
|
|
|
|
$val = '<i>(not set)</i>';
|
|
|
|
|
|
|
|
return "<span class=\"readonly\" id=\"" . $this->id() . "\">$val</span>";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|