Completed
Push — release-3.2.0 ( 5118c1...fcf3db )
by Daniel
15:42
created

checkbox   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build_checkbox() 0 14 1
A get_name() 0 3 1
A prep_field() 0 5 1
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 checkbox extends cfg_field_base
18
{
19
	/**
20
	 * @inheritdoc
21
	 */
22
	public function get_name()
23
	{
24
		return 'checkbox';
25
	}
26
27
	/**
28
	 * {@inheritdoc}
29
	 */
30
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
31
	{
32
		$vars['method'] = 'build_checkbox';
33
		$vars['params'][] = $field;
34
		$type[0] = 'custom';
35
	}
36
37
	/**
38
	 * Used to build multi-column checkboxes for blocks config
39
	 *
40
	 * if multi-dimensional array, we break the checkboxes into columns ex.
41
	 * array(
42
	 * 		'news' => array(
43
	 * 			'field1' => 'Label 1',
44
	 * 			'field2' => 'Label 2',
45
	 * 		),
46
	 * 		'articles' => array(
47
	 * 			'field1' => 'Label 1',
48
	 * 			'field2' => 'Label 2',
49
	 * 		),
50
	 * )
51
	 * @param array $option_ary
52
	 * @param mixed $selected_items
53
	 * @param string $field
54
	 * @return string
55
	 */
56
	public function build_checkbox(array $option_ary, $selected_items, $field)
57
	{
58
		$column_class = 'col ';
59
		$selected_items = cfg_utils::ensure_array($selected_items);
60
		$option_ary = cfg_utils::ensure_multi_array($option_ary, $column_class);
61
62
		$this->ptemplate->assign_vars(array(
63
			'field'		=> $field,
64
			'selected'	=> $selected_items,
65
			'columns'	=> $option_ary,
66
			'class'		=> $column_class,
67
		));
68
69
		return $this->ptemplate->render_view('blitze/sitemaker', 'cfg_fields/checkbox.html', 'checkbox');
70
	}
71
}
72