Completed
Pull Request — master (#43)
by Jakub
32:26 queued 30:23
created

manager::get_all_location_ids()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
crap 12
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\ads\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 39
	public function __construct($template_locations)
28
	{
29 39
		$this->register_template_locations($template_locations);
30 39
	}
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 16
	public function get_all_locations()
41
	{
42 16
		$location_types = array();
43
44 16
		foreach ($this->template_locations as $id => $location_type)
45
		{
46 16
			$location_types[$id] = array(
47 16
				'name'	=> $location_type->get_name(),
48 16
				'desc'	=> $location_type->get_desc(),
49
			);
50 16
		}
51
52 16
		return $location_types;
53
	}
54
55
	/**
56
	* Get a list of all template location IDs for display
57
	*
58
	* @return	array	Array containing a list of all template location IDs
59
	*/
60
	public function get_all_location_ids()
61
	{
62
		$template_locations = array();
63
64
		foreach ($this->template_locations as $location_id => $location)
65
		{
66
			if ($location->will_display())
67
			{
68
				$template_locations[] = $location_id;
69
			}
70
		}
71
72
		return $template_locations;
73
	}
74
75
	/**
76
	* Register template locations
77
	*
78
	* @param	array	$template_locations	Template location types passed via the service container
79
	*/
80 39
	protected function register_template_locations($template_locations)
81
	{
82 39
		if (!empty($template_locations))
83 39
		{
84 39
			foreach ($template_locations as $location)
85
			{
86 39
				$this->template_locations[$location->get_id()] = $location;
87 39
			}
88 39
		}
89 39
	}
90
}
91