Completed
Pull Request — master (#4)
by Jakub
06:46
created

manager::register_template_locations()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 4
nop 1
crap 4
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 30
	public function __construct($template_locations)
28
	{
29 30
		$this->register_template_locations($template_locations);
30 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 template locations
39
	*/
40 8
	public function get_all_locations()
41
	{
42 8
		$location_types = array();
43
44 8
		foreach ($this->template_locations as $id => $location_type)
45
		{
46 8
			$location_types[$id] = array(
47 8
				'name'	=> $location_type->get_name(),
48 8
				'desc'	=> $location_type->get_desc(),
49
			);
50 8
		}
51
52 8
		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 30
	protected function register_template_locations($template_locations)
71
	{
72 30
		if (!empty($template_locations))
73 30
		{
74 30
			foreach ($template_locations as $location)
75
			{
76 30
				if ($location->will_display())
77 30
				{
78 30
					$this->template_locations[$location->get_id()] = $location;
79 30
				}
80 30
			}
81 30
		}
82 30
	}
83
}
84