Field_Timezone::getGroups()   B
last analyzed

Complexity

Conditions 7
Paths 14

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 14
nop 0
dl 0
loc 49
rs 8.1793
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of the Joomla Framework Form Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE
7
 */
8
9
namespace Joomla\Form;
10
11
use Joomla\Form\Html\Select;
12
13
FormHelper::loadFieldClass('groupedList');
14
15
/**
16
 * Form Field class for the Joomla Framework.
17
 *
18
 * @since       1.0
19
 * @deprecated  The joomla/form package is deprecated
20
 */
21
class Field_Timezone extends Field_GroupedList
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Field_GroupedList has been deprecated with message: The joomla/form package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
{
23
	/**
24
	 * The form field type.
25
	 *
26
	 * @var    string
27
	 * @since  1.0
28
	 */
29
	protected $type = 'Timezone';
30
31
	/**
32
	 * The list of available timezone groups to use.
33
	 *
34
	 * @var    array
35
	 *
36
	 * @since  1.0
37
	 */
38
	protected static $zones = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
39
40
	/**
41
	 * Method to get the time zone field option groups.
42
	 *
43
	 * @return  array  The field option objects as a nested array in groups.
44
	 *
45
	 * @since   1.0
46
	 */
47
	protected function getGroups()
48
	{
49
		$groups = array();
50
51
		// Get the list of time zones from the server.
52
		$zones = \DateTimeZone::listIdentifiers();
53
54
		// Build the group lists.
55
		foreach ($zones as $zone)
56
		{
57
			// Time zones not in a group we will ignore.
58
			if (strpos($zone, '/') === false)
59
			{
60
				continue;
61
			}
62
63
			// Get the group/locale from the timezone.
64
			list ($group, $locale) = explode('/', $zone, 2);
65
66
			// Only use known groups.
67
			if (in_array($group, self::$zones))
68
			{
69
				// Initialize the group if necessary.
70
				if (!isset($groups[$group]))
71
				{
72
					$groups[$group] = array();
73
				}
74
75
				// Only add options where a locale exists.
76
				if (!empty($locale))
77
				{
78
					$groups[$group][$zone] = Select::option($zone, str_replace('_', ' ', $locale), 'value', 'text', false);
79
				}
80
			}
81
		}
82
83
		// Sort the group lists.
84
		ksort($groups);
85
86
		foreach ($groups as &$location)
87
		{
88
			sort($location);
89
		}
90
91
		// Merge any additional groups in the XML definition.
92
		$groups = array_merge(parent::getGroups(), $groups);
93
94
		return $groups;
95
	}
96
}
97