Completed
Push — master ( 409900...f20dfb )
by Jean-Christophe
03:24
created

HtmlDropdownItem::asOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 4
nc 2
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
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){
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...
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){
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...
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
}