### Attributes:
- monthNames If false, 2 digit numbers will be used instead of text.
If a array, the given array will be used.
- minYear The lowest year to use in the year select
- maxYear The maximum year to use in the year select
- interval The interval for the minutes select. Defaults to 1
- separator The contents of the string between select elements. Defaults to '-'
- empty - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- round - Set to up or down if you want to force rounding in either direction. Defaults to null.
- value | default The default value to be used by the input. A value in $this->data
matching the field name will override this value. If no default is provided time() will be used.
public dateTime ( string $fieldName, string $dateFormat = 'DMY', string $timeFormat = '12', array $attributes = [] ) : string | ||
$fieldName | string | Prefix name for the SELECT element |
$dateFormat | string | DMY, MDY, YMD, or null to not generate date inputs. - W が入力された場合、和暦のselectと年月日の接尾辞が付与される |
$timeFormat | string | 12, 24, or null to not generate time inputs. |
$attributes | array | Array of Attributes |
return | string | Generated set of select boxes for the date and time formats chosen. |
/** * 日付タグを表示 * * @param string $fieldName フィールド文字列 * @param string $dateFormat 日付フォーマット * @param string $timeFormat 時間フォーマット * @param array $attributes html属性 * - 凍結時、$attributes['selected']に要素を格納することで日付を選択する * (例) $attributes['selected'] = array('selected' => array('year' => '2010', 'month' => '4', 'day' => '1')) * @return string htmlタグ * @access public */ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $attributes = array()) { if ($this->freezed) { $year = $month = $day = $hour = $min = $meridian = $showEmpty = $selected = null; if (isset($attributes['selected'])) { $selected = $attributes['selected']; } if (isset($attributes['empty'])) { $showEmpty = $attributes['empty']; } if (empty($selected)) { $selected = $this->value($fieldName); } if ($selected === null && $showEmpty != true) { $selected = time(); } if (!empty($selected)) { if (is_array($selected)) { extract($selected); } else { if (is_numeric($selected)) { $selected = strftime('%Y-%m-%d %H:%M:%S', $selected); } $meridian = 'am'; $pos = strpos($selected, '-'); if ($pos !== false) { $date = explode('-', $selected); $days = explode(' ', $date[2]); $day = $days[0]; $month = $date[1]; $year = $date[0]; } else { $days[1] = $selected; } if ($timeFormat != 'NONE' && !empty($timeFormat)) { $time = explode(':', $days[1]); $check = str_replace(':', '', $days[1]); if ($check > 115959 && $timeFormat == '12') { $time[0] = $time[0] - 12; $meridian = 'pm'; } elseif ($time[0] == '00' && $timeFormat == '12') { $time[0] = 12; } elseif ($time[0] > 12) { $meridian = 'pm'; } if ($time[0] == 0 && $timeFormat == '12') { $time[0] = 12; } $hour = $time[0]; $min = $time[1]; } } } $elements = array('Day', 'Month', 'Year', 'Hour', 'Minute', 'Meridian'); $defaults = array('minYear' => null, 'maxYear' => null, 'separator' => ' '); $attributes = array_merge($defaults, (array) $attributes); $minYear = $attributes['minYear']; $maxYear = $attributes['maxYear']; $separator = $attributes['separator']; if (isset($attributes['id'])) { if (is_string($attributes['id'])) { // build out an array version foreach ($elements as $element) { $selectAttrName = 'select' . $element . 'Attr'; ${$selectAttrName} = $attributes; ${$selectAttrName}['id'] = $attributes['id'] . $element; } } elseif (is_array($attributes['id'])) { // check for missing ones and build selectAttr for each element foreach ($elements as $element) { $selectAttrName = 'select' . $element . 'Attr'; ${$selectAttrName} = $attributes; ${$selectAttrName}['id'] = $attributes['id'][strtolower($element)]; } } } else { // build the selectAttrName with empty id's to pass foreach ($elements as $element) { $selectAttrName = 'select' . $element . 'Attr'; ${$selectAttrName} = $attributes; } } $selects = array(); if (preg_match('/^W/', $dateFormat)) { $selects[] = $this->wyear($fieldName, $minYear, $maxYear, $year, $selectYearAttr, $showEmpty) . "年"; } else { $selectYearAttr['value'] = $year; $selects[] = $this->freezeControll($fieldName . ".year", array(), $selectYearAttr) . "年"; } // TODO 値の出力はBcTextにまとめた方がよいかも // メール本文への出力も同じ処理を利用する。(改行の処理などはどうするか。。) $selectMonthAttr['value'] = $month; $selectDayAttr['value'] = $day; $selects[] = $this->freezeControll($fieldName . ".month", array(), $selectMonthAttr) . "月"; $selects[] = $this->freezeControll($fieldName . ".day", array(), $selectDayAttr) . "日"; $selects[] = $this->freezeControll($fieldName . ".hour", array(), array('value' => $hour)) . "時"; $selects[] = $this->freezeControll($fieldName . ".min", array(), array('value' => $min)) . "分"; return implode($separator, $selects); } else { return parent::dateTime($fieldName, $dateFormat, $timeFormat, $attributes); } }