Completed
Push — master ( df8ec4...96358d )
by Nazar
04:25
created

layout_elements   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 25
lcom 1
cbo 3
dl 0
loc 108
rs 10
c 1
b 0
f 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A vertical_table() 0 3 1
A horizontal_table() 0 3 1
A list_center_table() 0 6 2
D core_input() 0 41 10
B core_textarea() 0 21 6
B core_select() 0 15 5
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\admin\Controller;
11
use
12
	cs\Config,
13
	cs\Language,
14
	h;
15
16
trait layout_elements {
17
	/**
18
	 * @param string[][] $rows
19
	 *
20
	 * @return string
21
	 */
22
	protected static function vertical_table ($rows) {
0 ignored issues
show
Unused Code introduced by
The parameter $rows is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
		return h::{'table.cs-table[right-left] tr| td'}(func_get_args());
24
	}
25
	/**
26
	 * @param string[] $header_columns
27
	 * @param string[] $columns
28
	 *
29
	 * @return string
30
	 */
31
	protected static function horizontal_table ($header_columns, $columns) {
32
		return h::{'table.cs-table[center] tr| td'}($header_columns, $columns);
33
	}
34
	/**
35
	 * @param string[]   $header_columns
36
	 * @param string[][] $rows
37
	 *
38
	 * @return string
39
	 */
40
	protected static function list_center_table ($header_columns, $rows) {
41
		return h::{'table.cs-table[center][list]'}(
42
			h::{'tr th'}($header_columns).
43
			h::{'tr| td'}($rows ? [$rows] : false)
44
		);
45
	}
46
	protected static function core_input ($item, $type = 'text', $info_item = null, $disabled = false, $min = false, $max = false, $post_text = '') {
47
		$Config = Config::instance();
48
		$L      = Language::instance();
49
		if ($type != 'radio') {
50
			switch ($item) {
51
				default:
52
					$value = $Config->core[$item];
53
					break;
54
				case 'name':
55
				case 'closed_title':
56
				case 'mail_from_name':
57
					$value = get_core_ml_text($item);
58
			}
59
			return [
60
				$info_item !== false ? h::info($info_item ?: $item) : $L->$item,
61
				h::{'input[is=cs-input-text]'}(
62
					[
63
						'name'  => "core[$item]",
64
						'value' => $value,
65
						'min'   => $min,
66
						'max'   => $max,
67
						'type'  => $type,
68
						($disabled ? 'disabled' : '')
69
					]
70
				).
71
				$post_text
72
			];
73
		} else {
74
			return [
75
				$info_item !== false ? h::info($info_item ?: $item) : $L->$item,
76
				h::radio(
77
					[
78
						'name'    => "core[$item]",
79
						'checked' => $Config->core[$item],
80
						'value'   => [0, 1],
81
						'in'      => [$L->off, $L->on]
82
					]
83
				)
84
			];
85
		}
86
	}
87
	protected static function core_textarea ($item, $editor = null, $info_item = null) {
88
		switch ($item) {
89
			default:
90
				$content = Config::instance()->core[$item];
91
				break;
92
			case 'closed_text':
93
			case 'mail_signature':
94
			case 'rules':
95
				$content = get_core_ml_text($item);
96
		}
97
		return [
98
			h::info($info_item ?: $item),
99
			h::{'textarea[is=cs-textarea][autosize]'}(
100
				$content,
101
				[
102
					'name'  => "core[$item]",
103
					'class' => $editor ? " $editor" : ''
104
				]
105
			)
106
		];
107
	}
108
	protected static function core_select ($items_array, $item, $id = null, $info_item = null, $multiple = false, $size = 5) {
109
		return [
110
			h::info($info_item ?: $item),
111
			h::{'select[is=cs-select]'}(
112
				$items_array,
113
				[
114
					'name'     => "core[$item]".($multiple ? '[]' : ''),
115
					'selected' => Config::instance()->core[$item],
116
					'size'     => $size,
117
					'id'       => $id ?: false,
118
					$multiple ? 'multiple' : false
119
				]
120
			)
121
		];
122
	}
123
}
124