本文整理汇总了PHP中DateField::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP DateField::setValue方法的具体用法?PHP DateField::setValue怎么用?PHP DateField::setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateField
的用法示例。
在下文中一共展示了DateField::setValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValue
public function setValue($val)
{
$this->cache = array();
if (is_array($val)) {
$val = $val['year'] . '-' . str_pad($val['month'], 2, 0, STR_PAD_LEFT) . '-' . str_pad($val['day'], 2, 0, STR_PAD_LEFT);
}
return parent::setValue($val);
}
示例2: setValue
/**
* Sets the internal value to ISO date format.
*
* @param String|Array $val
*/
public function setValue($val)
{
$date = $this->ConvertToTSorERROR($val);
if (is_numeric($date) && intval($date) == $date && $date > 0) {
$val = date("Y-m-d", $date);
} else {
$val = null;
}
return parent::setValue($val);
}
示例3: setValue
/**
* Sets the internal value to ISO date format.
*
* @param string|array $val String expects an ISO date format. Array notation with 'date' and 'time'
* keys can contain localized strings. If the 'dmyfields' option is used for {@link DateField},
* the 'date' value may contain array notation was well (see {@link DateField->setValue()}).
*/
function setValue($val)
{
if (empty($val)) {
$this->dateField->setValue(null);
$this->timeField->setValue(null);
} else {
// String setting is only possible from the database, so we don't allow anything but ISO format
if (is_string($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
// split up in date and time string values.
$valueObj = new Zend_Date($val, $this->getConfig('datavalueformat'), $this->locale);
// set date either as array, or as string
if ($this->dateField->getConfig('dmyfields')) {
$this->dateField->setValue($valueObj->toArray());
} else {
$this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat')));
}
// set time
$this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat')));
} elseif (is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) {
$this->dateField->setValue($val['date']);
$this->timeField->setValue($val['time']);
} else {
$this->dateField->setValue($val);
$this->timeField->setValue($val);
}
}
}
示例4: setValue
/**
* Sets the internal value to ISO date format, based on either a database value in ISO date format,
* or a form submssion in the user date format. Uses the individual date and time fields
* to take care of the actual formatting and value conversion.
*
* Value setting happens *before* validation, so we have to set the value even if its not valid.
*
* Caution: Only converts user timezones when value is passed as array data (= form submission).
* Weak indication, but unfortunately the framework doesn't support a distinction between
* setting a value from the database, application logic, and user input.
*
* @param string|array $val String expects an ISO date format. Array notation with 'date' and 'time'
* keys can contain localized strings. If the 'dmyfields' option is used for {@link DateField},
* the 'date' value may contain array notation was well (see {@link DateField->setValue()}).
*/
function setValue($val)
{
// If timezones are enabled, assume user data needs to be reverted to server timezone
if ($this->getConfig('usertimezone')) {
// Accept user input on timezone, but only when timezone support is enabled
$userTz = is_array($val) && array_key_exists('timezone', $val) ? $val['timezone'] : null;
if (!$userTz) {
$userTz = $this->getConfig('usertimezone');
}
// fall back to defined timezone
} else {
$userTz = null;
}
if (empty($val)) {
$this->value = null;
$this->dateField->setValue(null);
$this->timeField->setValue(null);
} else {
// Case 1: String setting from database, in ISO date format
if (is_string($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
$this->value = $val;
} elseif (is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) {
$dataTz = date_default_timezone_get();
// If timezones are enabled, assume user data needs to be converted to server timezone
if ($userTz) {
date_default_timezone_set($userTz);
}
// Uses sub-fields to temporarily write values and delegate dealing with their normalization,
// actual sub-field value setting happens later
$this->dateField->setValue($val['date']);
$this->timeField->setValue($val['time']);
if ($this->dateField->dataValue() && $this->timeField->dataValue()) {
$userValueObj = new Zend_Date(null, null, $this->locale);
$userValueObj->setDate($this->dateField->dataValue(), $this->dateField->getConfig('datavalueformat'));
$userValueObj->setTime($this->timeField->dataValue(), $this->timeField->getConfig('datavalueformat'));
if ($userTz) {
$userValueObj->setTimezone($dataTz);
}
$this->value = $userValueObj->get($this->getConfig('datavalueformat'), $this->locale);
unset($userValueObj);
} else {
// Validation happens later, so set the raw string in case Zend_Date doesn't accept it
$this->value = sprintf($this->getConfig('datetimeorder'), $val['date'], $val['time']);
}
if ($userTz) {
date_default_timezone_set($dataTz);
}
} else {
$this->dateField->setValue($val);
if (is_string($val)) {
$this->timeField->setValue($val);
}
$this->value = $val;
}
// view settings (dates might differ from $this->value based on user timezone settings)
if (Zend_Date::isDate($this->value, $this->getConfig('datavalueformat'), $this->locale)) {
$valueObj = new Zend_Date($this->value, $this->getConfig('datavalueformat'), $this->locale);
if ($userTz) {
$valueObj->setTimezone($userTz);
}
// Set view values in sub-fields
if ($this->dateField->getConfig('dmyfields')) {
$this->dateField->setValue($valueObj->toArray());
} else {
$this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat'), $this->locale));
}
$this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'), $this->locale));
}
}
}
示例5: testMDYFormat
/**
* Note: This is mostly tested for legacy reasons
*/
public function testMDYFormat()
{
$dateField = new DateField('Date', 'Date');
$dateField->setConfig('dateformat', 'd/M/Y');
$dateField->setValue('31/03/2003');
$this->assertEquals($dateField->dataValue(), '2003-03-31', "We get MM-DD-YYYY format as the data value for YYYY-MM-DD input value");
$dateField2 = new DateField('Date', 'Date');
$dateField2->setConfig('dateformat', 'd/M/Y');
$dateField2->setValue('04/3/03');
$this->assertEquals($dateField2->dataValue(), '2003-03-04', "Even if input value hasn't got leading 0's in it we still get the correct data value");
}
示例6: getHTMLFragments
public function getHTMLFragments($gridField)
{
$fields = new ArrayList();
$state = $gridField->State->UserFormsGridField;
$selectedField = $state->filter;
$selectedValue = $state->value;
// show dropdown of all the fields available from the submitted form fields
// that have been saved. Takes the titles from the currently live form.
$columnField = new DropdownField('FieldNameFilter', '');
$columnField->setSource($this->columns);
$columnField->setEmptyString(_t('UserFormsGridFieldFilterHeader.FILTERSUBMISSIONS', 'Filter Submissions..'));
$columnField->setHasEmptyDefault(true);
$columnField->setValue($selectedField);
$valueField = new TextField('FieldValue', '', $selectedValue);
$columnField->addExtraClass('ss-gridfield-sort');
$columnField->addExtraClass('no-change-track');
$valueField->addExtraClass('ss-gridfield-sort');
$valueField->addExtraClass('no-change-track');
$valueField->setAttribute('placeholder', _t('UserFormsGridFieldFilterHeader.WHEREVALUEIS', 'where value is..'));
$fields->push(new FieldGroup(new CompositeField($columnField, $valueField)));
$fields->push(new FieldGroup(new CompositeField($start = new DateField('StartFilter', 'From'), $end = new DateField('EndFilter', 'Till'))));
foreach (array($start, $end) as $date) {
$date->setConfig('showcalendar', true);
$date->setConfig('dateformat', 'y-mm-dd');
$date->setConfig('datavalueformat', 'y-mm-dd');
$date->addExtraClass('no-change-track');
}
$end->setValue($state->end);
$start->setValue($state->start);
$fields->push($actions = new FieldGroup(GridField_FormAction::create($gridField, 'filter', false, 'filter', null)->addExtraClass('ss-gridfield-button-filter')->setAttribute('title', _t('GridField.Filter', "Filter"))->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField), GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->addExtraClass('ss-gridfield-button-close')->setAttribute('title', _t('GridField.ResetFilter', "Reset"))->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)));
$actions->addExtraClass('filter-buttons');
$actions->addExtraClass('no-change-track');
$forTemplate = new ArrayData(array('Fields' => $fields));
return array('header' => $forTemplate->renderWith('GridFieldFilterHeader_Row'));
}