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