Elgg  Version 4.3
time.php
Go to the documentation of this file.
1 <?php
18 
19 $vars['class'] = elgg_extract_class($vars, 'elgg-input-time');
20 
22  'value' => '',
23  'timestamp' => false,
24  'format' => elgg_get_config('time_format', elgg_echo('input:time_format')),
25 ];
26 
27 $vars = array_merge($defaults, $vars);
28 
29 $timestamp = elgg_extract('timestamp', $vars);
30 unset($vars['timestamp']);
31 
32 $format = elgg_extract('format', $vars, $defaults['format'], false);
33 unset($vars['format']);
34 
35 $min = (int) elgg_extract('min', $vars, 0);
36 unset($vars['min']);
37 
38 $max = (int) elgg_extract('max', $vars, 24 * 60 * 60);
39 unset($vars['max']);
40 
41 $step = (int) elgg_extract('step', $vars, 15 * 60);
42 unset($vars['step']);
43 
47 if ($value) {
48  try {
50 
51  // round value to the closest divisible of a step
52  $next_step_ts = (int) ceil($dt->getTimestamp() / $step) * $step;
53  $dt->setTimestamp($next_step_ts);
54 
55  $value_timestamp = $dt->format('H') * 60 * 60 + $dt->format('i') * 60;
56  $value_time = $dt->format($format);
57  } catch (DataFormatException $ex) {
58  // $value is not a valid datetime, using blank value
59  }
60 }
61 
62 if ($timestamp) {
63  $vars['value'] = $value_timestamp;
64 } else {
65  $vars['value'] = $value_time;
66 }
67 
70 
71 $dt = new DateTime('now', new DateTimeZone('UTC'));
72 
73 foreach ($hour_options_ts as $ts) {
74  $dt->setTimestamp($ts);
75  $key = ($timestamp) ? $dt->getTimestamp() : $dt->format($format);
76  $hour_options[$key] = $dt->format($format);
77 }
78 
79 $vars['options_values'] = $hour_options;
80 
81 echo elgg_view('input/select', $vars);
$vars['class']
Definition: time.php:19
$value
Definition: time.php:44
$min
Definition: time.php:35
$value_timestamp
Definition: time.php:46
$hour_options_ts
Definition: time.php:69
$defaults
Definition: time.php:21
$hour_options
Definition: time.php:68
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
$dt
Definition: time.php:71
$value_time
Definition: time.php:45
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:547
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
$step
Definition: time.php:41
$ts
CSRF security token view for use with secure forms.
An exception thrown when there is a problem in the format of some data.
$format
Definition: time.php:32
static normalizeTime($time)
Returns DateTime object based on time representation.
Definition: Values.php:76
elgg echo
Translates a string.
Definition: deprecated.js:530
$max
Definition: time.php:38
$timestamp
Definition: time.php:29
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
elgg_get_config($name, $default=null)
Get an Elgg configuration value.