Passed
Push — release-3.2.0 ( 24bcfb...4d8cca )
by Daniel
04:25
created

multi_input::prep_field()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 4
dl 0
loc 18
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2019 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\blocks\config\fields;
11
12
use blitze\sitemaker\services\blocks\config\cfg_utils;
13
14
/**
15
 * @package sitemaker
16
 */
17
class multi_input implements cfg_field_interface
18
{
19
	/** @var \phpbb\template\template */
20
	protected $template;
21
22
	/**
23
	 * Constructor
24
	 *
25
	 * @param \phpbb\template\template		$template		Template object
26
	 */
27
	public function __construct($ptemplate)
28
	{
29
		$this->ptemplate = $ptemplate;
0 ignored issues
show
Bug Best Practice introduced by
The property ptemplate does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
	}
31
32
	/**
33
	 * @inheritdoc
34
	 */
35
	public function get_name()
36
	{
37
		return 'multi_input';
38
	}
39
40
	/**
41
	 * {@inheritdoc}
42
	 */
43
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
44
	{
45
		// set defaults for types: field type, sortable, full width
46
		$type += array('', 0, 1);
47
48
		if ($type[2])
49
		{
50
			$vars['params'][] = $vars['lang'];
51
			$vars['lang'] = '';
52
		}
53
54
		$vars['params'][] = array_filter((array) $db_settings[$field]);
55
		$vars['params'][] = $type[1];	// sortable
56
		$vars['params'][] = $field;
57
58
		$type[0] = 'custom';
59
		$vars['method'] = 'build_multi_input';
60
		$vars['params'] = array_reverse($vars['params']);
61
	}
62
63
	/**
64
	 * Used to add multi-select drop down in blocks config
65
	 *
66
	 * @param string $field
67
	 * @param bool $sortable
68
	 * @param array $values
69
	 * @param string $label
70
	 * @return string
71
	 */
72
	public function build_multi_input($field, $sortable, array $values, $label = '')
73
	{
74
		$this->ptemplate->assign_vars(array(
75
			'field'		=> $field,
76
			'values'	=> array_filter((array) $values),
77
			'sortable'	=> $sortable,
78
			'label'		=> $label,
79
		));
80
81
		return $this->ptemplate->render_view('blitze/sitemaker', 'blocks/cfg_multi_input.html', 'multi_input_ui');
82
	}
83
}
84