1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\elements\HtmlIcon; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
|
9
|
|
|
use Ajax\service\JArray; |
10
|
|
|
use Ajax\semantic\html\elements\html5\HtmlImg; |
11
|
|
|
|
12
|
|
|
abstract class HtmlAbsractItem extends HtmlSemDoubleElement { |
13
|
|
|
|
14
|
|
|
public function __construct($identifier, $baseClass,$content=NULL) { |
15
|
|
|
parent::__construct($identifier, "div", $baseClass); |
16
|
|
|
$this->content=array(); |
17
|
|
|
$this->initContent($content); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
protected abstract function initContent($content); |
|
|
|
|
21
|
|
|
|
22
|
|
|
public function setIcon($icon){ |
23
|
|
|
$this->content["icon"]=new HtmlIcon("icon-".$this->identifier, $icon); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function setImage($image){ |
27
|
|
|
$image=new HtmlImg("icon-".$this->identifier, $image); |
28
|
|
|
$image->asAvatar(); |
29
|
|
|
$this->content["image"]=$image; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private function createContent(){ |
33
|
|
|
$this->content["content"]=new HtmlSemDoubleElement("content-".$this->identifier,"div","content"); |
34
|
|
|
return $this->content["content"]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function setTitle($title,$description=NULL,$baseClass="title"){ |
38
|
|
|
$title=new HtmlSemDoubleElement("","div",$baseClass,$title); |
39
|
|
|
if(\array_key_exists("content", $this->content)===false){ |
40
|
|
|
$this->createContent(); |
41
|
|
|
} |
42
|
|
|
$this->content["content"]->addContent($title); |
43
|
|
|
if(isset($description)){ |
44
|
|
|
$description=new HtmlSemDoubleElement("","div","description",$description); |
45
|
|
|
$this->content["content"]->addContent($description); |
46
|
|
|
} |
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getPart($partName="header"){ |
51
|
|
|
$content=\array_merge($this->content["content"]->getContent(),array(@$this->content["icon"],@$this->content["image"])); |
52
|
|
|
return $this->getElementByPropertyValue("class", $partName, $content); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setActive(){ |
56
|
|
|
$this->setTagName("div"); |
57
|
|
|
$this->removeProperty("href"); |
58
|
|
|
return $this->addToPropertyCtrl("class", "active", array("active")); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function asLink($href=NULL,$part=NULL){ |
|
|
|
|
62
|
|
|
$this->setTagName("a"); |
63
|
|
|
if(isset($href)) |
64
|
|
|
$this->setProperty("href", $href); |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
* |
72
|
|
|
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
73
|
|
|
*/ |
74
|
|
|
public function compile(JsUtils $js=NULL, $view=NULL) { |
75
|
|
|
if(\is_array($this->content)) |
76
|
|
|
$this->content=JArray::sortAssociative($this->content, [ "icon","image","content" ]); |
77
|
|
|
return parent::compile($js, $view); |
78
|
|
|
} |
79
|
|
|
} |