Elgg  Version 3.0
time.php
Go to the documentation of this file.
1 <?php
16 $vars['class'] = elgg_extract_class($vars, 'elgg-input-time');
17 
19  'value' => '',
20  'timestamp' => false,
21  'type' => 'select',
22  'format' => elgg_get_config('time_format', elgg_echo('input:time_format')),
23 ];
24 
25 $vars = array_merge($defaults, $vars);
26 
27 $timestamp = elgg_extract('timestamp', $vars);
28 unset($vars['timestamp']);
29 
30 $format = elgg_extract('format', $vars, $defaults['format'], false);
31 unset($vars['format']);
32 
33 $min = (int) elgg_extract('min', $vars, 0);
34 unset($vars['min']);
35 
36 $max = (int) elgg_extract('max', $vars, 24 * 60 * 60);
37 unset($vars['max']);
38 
39 $step = (int) elgg_extract('step', $vars, 15 * 60);
40 unset($vars['step']);
41 
45 if ($value) {
46  try {
48 
49  // round value to the closest divisible of a step
50  $next_step_ts = (int) ceil($dt->getTimestamp() / $step) * $step;
51  $dt->setTimestamp($next_step_ts);
52 
53  $value_timestamp = $dt->format('H') * 60 * 60 + $dt->format('i') * 60;
54  $value_time = $dt->format($format);
55  } catch (DataFormatException $ex) {
56  // $value is not a valid datetime, using blank value
57  }
58 }
59 
60 if ($timestamp) {
61  $vars['value'] = $value_timestamp;
62 } else {
63  $vars['value'] = $value_time;
64 }
65 
68 
69 $dt = new DateTime(null, new DateTimeZone('UTC'));
70 
71 foreach ($hour_options_ts as $ts) {
72  $dt->setTimestamp($ts);
73  $key = ($timestamp) ? $dt->getTimestamp() : $dt->format($format);
74  $hour_options[$key] = $dt->format($format);
75 }
76 
77 $vars['options_values'] = $hour_options;
78 
79 echo elgg_view('input/select', $vars);
$vars['class']
Elgg time input Displays a select field with time options.
Definition: time.php:16
$value
Definition: time.php:42
$min
Definition: time.php:33
$value_timestamp
Definition: time.php:44
$hour_options_ts
Definition: time.php:67
$defaults
Definition: time.php:18
$hour_options
Definition: time.php:66
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
$dt
Definition: time.php:69
elgg echo
Translates a string.
Definition: languages.js:43
$value_time
Definition: time.php:43
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$step
Definition: time.php:39
$format
Definition: time.php:30
static normalizeTime($time)
Returns DateTime object based on time representation.
Definition: Values.php:76
$max
Definition: time.php:36
$timestamp
Definition: time.php:27
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
elgg_get_config($name, $default=null)
Get an Elgg configuration value.