|
1
|
|
|
<?php |
|
2
|
|
|
namespace Ajax\semantic\html\base\traits; |
|
3
|
|
|
|
|
4
|
|
|
use Ajax\service\JArray; |
|
5
|
|
|
use Ajax\service\JString; |
|
6
|
|
|
use Ajax\semantic\html\elements\HtmlInput; |
|
7
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
|
8
|
|
|
|
|
9
|
|
|
trait MenuItemTrait { |
|
10
|
|
|
|
|
11
|
|
|
public function setContent($content){ |
|
12
|
|
|
if($content==="-"){ |
|
13
|
|
|
$this->asDivider(); |
|
14
|
|
|
}elseif($content==="-search-"){ |
|
15
|
|
|
$values=\explode(",",$content,-1); |
|
16
|
|
|
$this->asSearchInput(JArray::getDefaultValue($values, 0, "Search..."),JArray::getDefaultValue($values, 1, "search")); |
|
17
|
|
|
}elseif(JString::startswith($content, "-")){ |
|
18
|
|
|
$content=\ltrim($content,"-"); |
|
19
|
|
|
$this->asHeader($content); |
|
20
|
|
|
}else |
|
21
|
|
|
parent::setContent($content); |
|
22
|
|
|
return $this; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $placeholder |
|
27
|
|
|
* @param string $icon |
|
28
|
|
|
* @return \Ajax\semantic\html\content\HtmlDropdownItem|\Ajax\semantic\html\content\HtmlMenuItem |
|
29
|
|
|
*/ |
|
30
|
|
|
public function asSearchInput($placeholder=NULL,$icon=NULL){ |
|
31
|
|
|
$this->setClass("ui icon search input"); |
|
|
|
|
|
|
32
|
|
|
$input=new HtmlInput("search-".$this->identifier); |
|
|
|
|
|
|
33
|
|
|
if(isset($placeholder)) |
|
34
|
|
|
$input->setProperty("placeholder", $placeholder); |
|
35
|
|
|
$this->content=$input; |
|
|
|
|
|
|
36
|
|
|
if(isset($icon)) |
|
37
|
|
|
$this->addIcon($icon); |
|
|
|
|
|
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return \Ajax\semantic\html\content\HtmlDropdownItem|\Ajax\semantic\html\content\HtmlMenuItem |
|
43
|
|
|
*/ |
|
44
|
|
|
public function asDivider(){ |
|
45
|
|
|
$this->content=NULL; |
|
46
|
|
|
$this->tagName="div"; |
|
|
|
|
|
|
47
|
|
|
$this->setClass("divider"); |
|
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $caption |
|
53
|
|
|
* @param string $icon |
|
54
|
|
|
* @return \Ajax\semantic\html\content\HtmlDropdownItem|\Ajax\semantic\html\content\HtmlMenuItem |
|
55
|
|
|
*/ |
|
56
|
|
|
public function asHeader($caption=NULL,$icon=NULL){ |
|
57
|
|
|
$this->setClass("header"); |
|
|
|
|
|
|
58
|
|
|
$this->tagName="div"; |
|
59
|
|
|
$this->content=$caption; |
|
60
|
|
|
if(isset($icon)) |
|
61
|
|
|
$this->addIcon($icon,Direction::LEFT); |
|
|
|
|
|
|
62
|
|
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
} |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.