Issues (59)

Ajax/semantic/html/elements/HtmlList.php (1 issue)

Labels
1
<?php
2
namespace Ajax\semantic\html\elements;
3
4
use Ajax\semantic\html\base\HtmlSemCollection;
5
use Ajax\semantic\html\content\HtmlListItem;
6
use Ajax\semantic\html\collections\form\HtmlFormCheckbox;
7
use Ajax\JsUtils;
8
use Ajax\semantic\html\modules\checkbox\AbstractCheckbox;
9
use Ajax\semantic\components\Visibility;
10
use Ubiquity\utils\base\UString;
0 ignored issues
show
The type Ubiquity\utils\base\UString was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class HtmlList extends HtmlSemCollection {
13
14
	protected $_hasCheckedList;
15
16
	protected $_fireOnInit = false;
17
18
	protected $_ckItemChange = "";
19
20
	protected $_maxVisible;
21
22
	protected $_dataList;
23
24
	protected $_visibility;
25
26
	public function __construct($identifier, $items = array()) {
27
		parent::__construct($identifier, "div", "ui list");
28
		$this->addItems($items);
29
		$this->_hasCheckedList = false;
30
	}
31
32
	protected function createItem($value) {
33
		$count = $this->count();
34
		$item = new HtmlListItem("item-" . $this->identifier . "-" . $count, $value);
35
		return $item;
36
	}
37
38
	public function addHeader($niveau, $content) {
39
		$header = new HtmlHeader("header-" . $this->identifier, $niveau, $content, "page");
40
		$this->wrap($header);
41
		return $header;
42
	}
43
44
	public function getItemPart($index, $partName = "header") {
45
		return $this->getItem($index)->getPart($partName);
46
	}
47
48
	public function itemsAs($tagName) {
49
		return $this->contentAs($tagName);
50
	}
51
52
	public function asLinks($hrefs = [], $target = NUll) {
53
		$this->addToPropertyCtrl("class", "link", array(
54
			"link"
55
		));
56
		return parent::asLinks($hrefs, $target);
57
	}
58
59
	public function addList($items = array()) {
60
		$list = new HtmlList("", $items);
61
		$list->setClass("list");
62
		return $this->addItem($list);
63
	}
64
65
	/**
66
	 *
67
	 * @return HtmlListItem
68
	 */
69
	public function getItem($index) {
70
		return parent::getItem($index);
71
	}
72
73
	protected function getItemToAdd($item) {
74
		$itemO = parent::getItemToAdd($item);
75
		if ($itemO instanceof AbstractCheckbox)
76
			$itemO->addClass("item");
77
		return $itemO;
78
	}
79
80
	public function setCelled() {
81
		return $this->addToProperty("class", "celled");
82
	}
83
84
	public function setBulleted() {
85
		return $this->addToProperty("class", "bulleted");
86
	}
87
88
	public function setOrdered() {
89
		return $this->addToProperty("class", "ordered");
90
	}
91
92
	public function run(JsUtils $js) {
93
		if ($this->_hasCheckedList === true) {
94
			$jsCode = include dirname(__FILE__) . '/../../components/jsTemplates/tplCheckedList.php';
95
			$jsCode = \str_replace("%identifier%", "#" . $this->identifier, $jsCode);
96
			$jsCode = \str_replace("%fireOnInit%", $this->_fireOnInit, $jsCode);
97
			$jsCode = \str_replace("%onChange%", $this->_ckItemChange, $jsCode);
98
			$this->executeOnRun($jsCode);
99
		}
100
		/*
101
		 * if(isset($this->_visibility)){
102
		 * $this->_visibility->run($js);
103
		 * }
104
		 */
105
		return parent::run($js);
106
	}
107
108
	protected function addFollowPoints() {
109
		$count = $this->count();
110
		for ($i = $this->_maxVisible; $i < $count; $i ++) {
111
			$this->getItem($i)
112
				->addClass("notVisible")
113
				->setProperty("style", "display: none;");
114
		}
115
		$item = $this->addItem("...");
116
		$item->addClass("points");
117
		$item->onClick('$(this).hide();$("#' . $this->identifier . ' .notVisible").show();');
118
	}
119
120
	public function onCkItemChange($jsCode) {
121
		$this->_ckItemChange = $jsCode;
122
	}
123
124
	/**
125
	 *
126
	 * @param boolean $fireOnInit
127
	 */
128
	public function setFireOnInit($fireOnInit) {
129
		$this->_fireOnInit = $fireOnInit;
130
	}
131
132
	public function setRelaxed() {
133
		return $this->addToProperty("class", "relaxed");
134
	}
135
136
	public function setSelection() {
137
		return $this->addToProperty("class", "selection");
138
	}
139
140
	public function setDivided() {
141
		return $this->addToProperty("class", "divided");
142
	}
143
144
	public function setHorizontal() {
145
		return $this->addToProperty("class", "horizontal");
146
	}
147
148
	/**
149
	 *
150
	 * {@inheritdoc}
151
	 * @see \Ajax\common\html\HtmlCollection::compile()
152
	 */
153
	public function compile(JsUtils $js = NULL, &$view = NULL) {
154
		if (isset($this->_maxVisible) && $this->_maxVisible < $this->count()) {
155
			$this->addFollowPoints();
156
			if (isset($js)) {
157
				$visibility = new Visibility($js);
158
				$visibility->attach("#" . $this->identifier);
159
				$visibility->setOnTopVisible("$(this).children('.notVisible').hide();$(this).find('.points').show();");
160
				$visibility->compile($js, $view);
161
				$this->_visibility = $visibility;
162
			}
163
		}
164
		return parent::compile($js, $view);
165
	}
166
167
	/**
168
	 * Adds a grouped checked box to the list
169
	 *
170
	 * @param array $items
171
	 * @param string|array|null $masterItem
172
	 * @param array $values
173
	 * @param string $notAllChecked
174
	 * @return HtmlList
175
	 */
176
	public function addCheckedList($items = array(), $masterItem = NULL, $values = array(), $notAllChecked = false, $name = null) {
177
		$count = $this->count();
178
		$identifier = $this->identifier . "-" . $count;
179
		if (isset($masterItem)) {
180
			if (\is_array($masterItem)) {
181
				$masterO = new HtmlFormCheckbox("master-" . $identifier, @$masterItem[0], @$masterItem[1]);
182
				if (isset($name))
183
					$masterO->setName($name);
184
				if (isset($masterItem[1])) {
185
					if (\array_search($masterItem[1], $values) !== false) {
186
						$masterO->getDataField()->setProperty("checked", "");
187
					}
188
				}
189
			} else {
190
				$masterO = new HtmlFormCheckbox("master-" . $identifier, $masterItem);
191
			}
192
			if ($notAllChecked) {
193
				$masterO->getDataField()->addClass("_notAllChecked");
194
			}
195
			$masterO->getHtmlCk()->addToProperty("class", "master");
196
			$masterO->setClass("item");
197
			$this->addItem($masterO);
198
		}
199
		$fields = array();
200
		$i = 0;
201
		$this->setFireOnInit(UString::getBooleanStr($this->_fireOnInit || count($items) < 30));
202
		foreach ($items as $val => $caption) {
203
			$itemO = new HtmlFormCheckbox($identifier . "-" . $i ++, $caption, $val, "child");
204
			if (\array_search($val, $values) !== false) {
205
				$itemO->getDataField()->setProperty("checked", "");
206
			}
207
			if (isset($name))
208
				$itemO->setName($name);
209
			$itemO->setClass("item");
210
			$fields[] = $itemO;
211
		}
212
		if (isset($masterO) === true) {
213
			$list = new HtmlList("", $fields);
214
			$list->setClass("list");
215
			$masterO->addContent($list);
216
		} else {
217
			$this->addList($fields);
218
		}
219
		$this->_hasCheckedList = true;
220
		return $this;
221
	}
222
223
	public function setIcons($icons) {
224
		if (! \is_array($icons)) {
225
			$icons = \array_fill(0, \sizeof($this->content), $icons);
226
		}
227
		$max = \min(\sizeof($icons), \sizeof($this->content));
228
		for ($i = 0; $i < $max; $i ++) {
229
			$this->content[$i]->addIcon($icons[$i]);
230
		}
231
		return $this;
232
	}
233
234
	/**
235
	 *
236
	 * @return mixed
237
	 */
238
	public function getMaxVisible() {
239
		return $this->_maxVisible;
240
	}
241
242
	/**
243
	 *
244
	 * @param mixed $_maxVisible
245
	 */
246
	public function setMaxVisible($_maxVisible) {
247
		$this->_maxVisible = $_maxVisible;
248
		return $this;
249
	}
250
}
251