Completed
Pull Request — master (#4)
by Jakub
14:22
created

manager::get_all_locations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\admanagement\location;
12
13
class manager
14
{
15
	/**
16
	* Array that contains all available template location types which are passed
17
	* via the service container
18
	* @var array
19
	*/
20
	protected $template_locations;
21
22
	/**
23
	* Construct an template locations manager object
24
	*
25
	* @param	array	$template_locations	Template location types passed via the service container
26
	*/
27
	public function __construct($template_locations)
28
	{
29
		$this->register_template_locations($template_locations);
30
	}
31
32
	/**
33
	* Get a list of all template location types
34
	*
35
	* Returns an associated array where key is the location id
36
	* and value is array of location name and location description.
37
	*
38
	* @return	array	Array containing a list of all avatar drivers
39
	*/
40
	public function get_all_locations()
41
	{
42
		$location_types = array();
43
44
		foreach ($this->template_locations as $id => $location_type)
45
		{
46
			$location_types[$id] = array(
47
				'name'	=> $location_type->get_name(),
48
				'desc'	=> $location_type->get_desc(),
49
			);
50
		}
51
52
		return $location_types;
53
	}
54
55
	/**
56
	* Get a list of all template location IDs
57
	*
58
	* @return	array	Array containing a list of all template location IDs
59
	*/
60
	public function get_all_location_ids()
61
	{
62
		return array_keys($this->template_locations);
63
	}
64
65
	/**
66
	* Register template locations
67
	*
68
	* @param	array	$template_locations	Template location types passed via the service container
69
	*/
70
	protected function register_template_locations($template_locations)
71
	{
72
		if (!empty($template_locations))
73
		{
74
			foreach ($template_locations as $location)
75
			{
76
				if ($location->will_display())
77
				{
78
					$this->template_locations[$location->get_id()] = $location;
79
				}
80
			}
81
		}
82
	}
83
}
84