Completed
Push — master ( faaf91...5eca3e )
by Jean-Christophe
03:08
created

HtmlDropdownItem::divider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
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 function asHeader($caption=NULL,$icon=NULL){
80
		$this->setClass("header");
81
		$this->content=$caption;
82
		if(isset($icon))
83
			$this->addIcon($icon,true);
84
		return $this;
85
	}
86
87
	public static function searchInput($placeholder=NULL,$icon=NULL){
88
		return (new HtmlDropdownItem(""))->asSearchInput($placeholder,$icon);
89
	}
90
91
	public static function divider($placeholder=NULL,$icon=NULL){
0 ignored issues
show
Unused Code introduced by
The parameter $placeholder is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $icon is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
		return (new HtmlDropdownItem(""))->asDivider();
93
	}
94
95
	public static function header($caption=NULL,$icon=NULL){
96
		return (new HtmlDropdownItem(""))->asHeader($caption,$icon);
97
	}
98
}