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
|
|
|
|
11
|
|
|
class HtmlDropdownItem extends HtmlSemDoubleElement { |
12
|
|
|
|
13
|
|
|
public function __construct($identifier, $content="",$value=NULL,$image=NULL) { |
14
|
|
|
parent::__construct($identifier, "div"); |
15
|
|
|
$this->setClass("item"); |
16
|
|
|
$this->setContent($content); |
17
|
|
|
if($value!==NULL) |
18
|
|
|
$this->setData($value); |
19
|
|
|
if($image!==NULL) |
20
|
|
|
$this->asMiniAvatar($image); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function setDescription($description){ |
|
|
|
|
24
|
|
|
$descO=new HtmlDoubleElement("desc-".$this->identifier,"span"); |
25
|
|
|
$descO->setClass("description"); |
26
|
|
|
$descO->setContent($description); |
27
|
|
|
return $this->addContent($descO,true); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function setData($value){ |
31
|
|
|
$this->setProperty("data-value", $value); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function asOption(){ |
35
|
|
|
$this->tagName="option"; |
36
|
|
|
if($this->getProperty("data-value")!==null) |
37
|
|
|
$this->setProperty("value", $this->getProperty("data-value")); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $image the image src |
42
|
|
|
* @return \Ajax\common\html\html5\HtmlImg |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function asMiniAvatar($image){ |
|
|
|
|
45
|
|
|
$this->tagName="div"; |
46
|
|
|
$img=new HtmlImg("image-".$this->identifier,$image); |
47
|
|
|
$img->setClass("ui mini avatar image"); |
48
|
|
|
$this->addContent($img,true); |
49
|
|
|
return $img; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function asSearchInput($placeholder=NULL,$icon=NULL){ |
53
|
|
|
$this->setClass("ui icon search input"); |
54
|
|
|
$input=new HtmlInput("search-".$this->identifier); |
55
|
|
|
if(isset($placeholder)) |
56
|
|
|
$input->setProperty("placeholder", $placeholder); |
57
|
|
|
$this->content=$input; |
58
|
|
|
if(isset($icon)) |
59
|
|
|
$this->addIcon($icon); |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setContent($content){ |
64
|
|
|
if($content==="-"){ |
65
|
|
|
$this->asDivider(); |
66
|
|
|
}elseif($content==="-search-"){ |
67
|
|
|
$values=\explode(",",$content,-1); |
68
|
|
|
$this->asSearchInput(JArray::getDefaultValue($values, 0, "Search..."),JArray::getDefaultValue($values, 1, "search")); |
69
|
|
|
}else |
70
|
|
|
parent::setContent($content); |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function asDivider(){ |
75
|
|
|
$this->content=NULL; |
76
|
|
|
$this->setClass("divider"); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public static function searchInput($placeholder=NULL,$icon=NULL){ |
80
|
|
|
return (new HtmlDropdownItem(""))->asSearchInput($placeholder,$icon); |
81
|
|
|
} |
82
|
|
|
} |
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.