Passed
Push — master ( f3b1f4...8f7203 )
by Jean-Christophe
02:25
created

HtmlFormDropdown::multipleDropdown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 5
dl 0
loc 2
rs 10
1
<?php
2
namespace Ajax\semantic\html\collections\form;
3
4
use Ajax\semantic\html\base\constants\Direction;
5
use Ajax\semantic\html\elements\HtmlButton;
6
use Ajax\semantic\html\modules\HtmlDropdown;
7
8
class HtmlFormDropdown extends HtmlFormField {
9
10
	public function __construct($identifier, $items = array(), $label = NULL, $value = "", $multiple = false, $associative = true) {
11
		parent::__construct("field-" . $identifier, (new HtmlDropdown("dropdown-" . $identifier, $value, $items, $associative))->asSelect($identifier, $multiple), $label);
12
		$this->_identifier = $identifier;
13
	}
14
15
	public function setItems($items) {
16
		return $this->getField()->setItems($items);
17
	}
18
19
	public function addItem($item, $value = NULL, $image = NULL) {
20
		return $this->getField()->addItem($item, $value, $image);
21
	}
22
23
	public static function multipleDropdown($identifier, $items = array(), $label = NULL, $value = "", $associative = true) {
24
		return new HtmlFormDropdown($identifier, $items, $label, $value, true, $associative);
25
	}
26
27
	/**
28
	 *
29
	 * @return HtmlDropdown
30
	 */
31
	public function getDataField() {
32
		return $this->getField()->getInput();
33
	}
34
35
	public function asSelect($name = NULL, $multiple = false, $selection = true) {
36
		$this->getField()->asSelect($name, $multiple, $selection);
37
		return $this;
38
	}
39
40
	/**
41
	 *
42
	 * @param boolean $floating
43
	 * @return HtmlDropdown
44
	 */
45
	public function asButton($floating = false) {
46
		$field = $this->content["field"];
47
		$label = $this->content["label"];
48
		$field->addContent($label);
49
		$this->content = [
50
			"field" => $field
51
		];
52
		$this->content["field"]->asButton($floating);
53
		return $this->content["field"];
54
	}
55
56
	/**
57
	 *
58
	 * @param string $action
59
	 * @param string $direction
60
	 * @param string $icon
61
	 * @param boolean $labeled
62
	 * @return mixed|HtmlButton
63
	 */
64
	public function addAction($action, $direction = Direction::RIGHT, $icon = NULL, $labeled = false) {
65
		$this->getField()->setStyle('display:inline-block; width: auto');
66
		$actionO = $action;
67
		if (\is_object($action) === false) {
0 ignored issues
show
introduced by
The condition is_object($action) === false is always true.
Loading history...
68
			$actionO = new HtmlButton("action-" . $this->identifier, $action);
0 ignored issues
show
Bug introduced by
$action of type object is incompatible with the type string expected by parameter $value of Ajax\semantic\html\eleme...mlButton::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
			$actionO = new HtmlButton("action-" . $this->identifier, /** @scrutinizer ignore-type */ $action);
Loading history...
69
			if (isset($icon))
70
				$actionO->addIcon($icon, true, $labeled);
71
		}
72
		$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
73
		return $actionO;
74
	}
75
}
76