Completed
Push — master ( 2c01a5...172c54 )
by Jean-Christophe
03:09
created

HtmlDropdownItem::asDivider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Ajax\semantic\html\content;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\common\html\HtmlDoubleElement;
7
use Ajax\common\html\html5\HtmlImg;
8
use Ajax\common\html\html5\HtmlInput;
9
use Ajax\service\JArray;
10
use Ajax\semantic\html\base\traits\IconTrait;
11
use Ajax\semantic\html\elements\HtmlLabel;
12
use Ajax\semantic\html\elements\HtmlIcon;
13
14
class HtmlDropdownItem extends HtmlSemDoubleElement {
15
	use IconTrait;
16
	public function __construct($identifier, $content="",$value=NULL,$image=NULL,$description=NULL) {
17
		parent::__construct($identifier, "a");
18
		$this->setClass("item");
19
		$this->setContent($content);
20
		if($value!==NULL)
21
			$this->setData($value);
22
		if($image!==NULL)
23
			$this->asMiniAvatar($image);
24
		if($description!==NULL)
25
			$this->setDescription($description);
26
	}
27
28 View Code Duplication
	public function setDescription($description){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
		$descO=new HtmlDoubleElement("desc-".$this->identifier,"span");
30
		$descO->setClass("description");
31
		$descO->setContent($description);
32
		return $this->addContent($descO,true);
33
	}
34
35
	public function setData($value){
36
		$this->setProperty("data-value", $value);
37
	}
38
39
	public function asOption(){
40
		$this->tagName="option";
41
		if($this->getProperty("data-value")!==null)
42
			$this->setProperty("value", $this->getProperty("data-value"));
43
	}
44
45
	/**
46
	 * @param string $image the image src
47
	 * @return \Ajax\common\html\html5\HtmlImg
48
	 */
49 View Code Duplication
	public function asMiniAvatar($image){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
		$this->tagName="div";
51
		$img=new HtmlImg("image-".$this->identifier,$image);
52
		$img->setClass("ui mini avatar image");
53
		$this->addContent($img,true);
54
		return $this;
55
	}
56
57
	/**
58
	 * @param string $caption
59
	 * @param string $icon
60
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
61
	 */
62
	public function asIcon($caption,$icon){
63
		$this->setContent($caption);
64
		$this->addContent(new HtmlIcon("", $icon),true);
65
		return $this;
66
	}
67
68
	/**
69
	 * Adds a circular label to the item
70
	 * @param string $color
71
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
72
	 */
73
	public function asCircularLabel($caption,$color){
74
		$this->setContent($caption);
75
		$lbl=new HtmlLabel("");
76
		$lbl->setCircular()->setColor($color)->setEmpty();
77
		$this->addContent($lbl,true);
78
		return $this;
79
	}
80
81
	public function asSearchInput($placeholder=NULL,$icon=NULL){
82
		$this->setClass("ui icon search input");
83
		$input=new HtmlInput("search-".$this->identifier);
84
		if(isset($placeholder))
85
			$input->setProperty("placeholder", $placeholder);
86
		$this->content=$input;
87
		if(isset($icon))
88
			$this->addIcon($icon);
89
		return $this;
90
	}
91
92
	public function setContent($content){
93
		if($content==="-"){
94
			$this->asDivider();
95
		}elseif($content==="-search-"){
96
			$values=\explode(",",$content,-1);
97
			$this->asSearchInput(JArray::getDefaultValue($values, 0, "Search..."),JArray::getDefaultValue($values, 1, "search"));
98
		}else
99
			parent::setContent($content);
100
		return $this;
101
	}
102
103
	/**
104
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
105
	 */
106
	public function asDivider(){
107
		$this->content=NULL;
108
		$this->setClass("divider");
109
		return $this;
110
	}
111
112
	/**
113
	 * @param string $caption
114
	 * @param string $icon
115
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
116
	 */
117
	public function asHeader($caption=NULL,$icon=NULL){
118
		$this->setClass("header");
119
		$this->content=$caption;
120
		if(isset($icon))
121
			$this->addIcon($icon,true);
122
		return $this;
123
	}
124
125
	/**
126
	 * @param string $placeholder
127
	 * @param string $icon
128
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
129
	 */
130
	public static function searchInput($placeholder=NULL,$icon=NULL){
131
		return (new HtmlDropdownItem(""))->asSearchInput($placeholder,$icon);
132
	}
133
134
	/**
135
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
136
	 */
137
	public static function divider(){
138
		return (new HtmlDropdownItem(""))->asDivider();
139
	}
140
141
	/**
142
	 * @param string $caption
143
	 * @param string $icon
144
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
145
	 */
146
	public static function header($caption=NULL,$icon=NULL){
147
		return (new HtmlDropdownItem(""))->asHeader($caption,$icon);
148
	}
149
150
	/**
151
	 * @param string $caption
152
	 * @param string $color
153
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
154
	 */
155
	public static function circular($caption,$color){
156
		return (new HtmlDropdownItem(""))->asCircularLabel($caption,$color);
157
	}
158
159
	/**
160
	 * @param string $caption
161
	 * @param string $icon
162
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
163
	 */
164
	public static function icon($caption,$icon){
165
		return (new HtmlDropdownItem(""))->asIcon($caption,$icon);
166
	}
167
168
	/**
169
	 * @param unknown $caption
170
	 * @param unknown $image
171
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
172
	 */
173
	public static function avatar($caption,$image){
174
		return (new HtmlDropdownItem("",$caption))->asMiniAvatar($image);
175
	}
176
}