function _webform_render_time in Webform 6.2
Same name and namespace in other branches
- 5.2 components/time.inc \_webform_render_time()
- 5 components/time.inc \_webform_render_time()
- 6.3 components/time.inc \_webform_render_time()
- 7.4 components/time.inc \_webform_render_time()
- 7.3 components/time.inc \_webform_render_time()
Build a form item array containing all the properties of this component
Parameters
$component An array of information describing the component, directly correlating to the webform_component database schema:
Return value
An array of a form item to be displayed on the client-side webform
1 call to _webform_render_time()
- _webform_submission_display_time in components/
time.inc - Display the result of a textfield submission. The output of this function will be displayed under the "results" tab then "submissions".
File
- components/
time.inc, line 80 - Webform module time component.
Code
function _webform_render_time($component) {
if (drupal_strlen($component['value']) > 0) {
// Calculate the timestamp in GMT.
$timestamp = strtotime($component['value']);
if ($component['extra']['timezone'] == 'user') {
// Use the users timezone.
global $user;
$timestamp += (int) $user->timezone;
}
elseif ($component['extra']['timezone'] == 'gmt') {
// Use GMT.
$timestamp += 0;
}
else {
// Use the Drupal site time.
$timestamp += (int) variable_get('date_default_timezone', 0);
}
// Check for daylight savings time.
if ($component['extra']['check_daylight_savings'] && date('I')) {
$timestamp += 3600;
}
}
if ($component['extra']['hourformat'] == '12-hour') {
$first_hour = 1;
$last_hour = 12;
$hour_format = 'g';
}
else {
$first_hour = 0;
$last_hour = 23;
$hour_format = 'G';
}
if (drupal_strlen($component['value']) > 0) {
$hour = gmdate($hour_format, $timestamp);
$minute = gmdate('i', $timestamp);
$am_pm = gmdate('a', $timestamp);
}
// Generate the choices for drop-down selects.
$hours[''] = t('hour');
$minutes[''] = t('minute');
for ($i = $first_hour; $i <= $last_hour; $i++) {
$hours[$i] = $i;
}
for ($i = 0; $i <= 59; $i++) {
$minutes[$i < 10 ? "0{$i}" : $i] = $i < 10 ? "0{$i}" : $i;
}
$am_pms = array(
'am' => t('am'),
'pm' => t('pm'),
);
$form_item = array(
'#title' => $component['name'],
'#required' => $component['mandatory'],
'#weight' => $component['weight'],
'#description' => _webform_filter_descriptions($component['extra']['description']),
'#prefix' => '<div class="webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">',
'#suffix' => '</div>',
'#theme' => 'webform_time',
'#element_validate' => array(
'webform_validate_time',
),
'#webform_component' => $component,
);
$form_item['hour'] = array(
'#prefix' => '',
'#type' => 'select',
'#default_value' => $hour,
'#options' => $hours,
);
$form_item['minute'] = array(
'#prefix' => ':',
'#type' => 'select',
'#default_value' => $minute,
'#options' => $minutes,
);
if ($component['extra']['hourformat'] == '12-hour') {
$form_item['ampm'] = array(
'#type' => 'radios',
'#default_value' => $am_pm,
'#options' => $am_pms,
);
}
return $form_item;
}