1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content\view; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\elements\HtmlHeader; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
use Ajax\service\JArray; |
9
|
|
|
|
10
|
|
|
use Ajax\semantic\html\elements\HtmlImage; |
11
|
|
|
use Ajax\semantic\html\elements\HtmlReveal; |
12
|
|
|
use Ajax\semantic\html\base\constants\RevealType; |
13
|
|
|
use Ajax\semantic\html\elements\HtmlButtonGroups; |
14
|
|
|
use Ajax\semantic\html\content\view\HtmlViewContent; |
15
|
|
|
use Ajax\service\JReflection; |
16
|
|
|
|
17
|
|
|
abstract class HtmlViewItem extends HtmlSemDoubleElement { |
18
|
|
|
|
19
|
|
|
protected $_sortContentBy=[]; |
20
|
|
|
|
21
|
|
|
public function __construct($identifier,$baseClass,$content=NULL) { |
22
|
|
|
parent::__construct($identifier, "div", $baseClass); |
23
|
|
|
$this->content=["content"=>new HtmlViewContent("content-".$this->identifier)]; |
24
|
|
|
if(isset($content)) |
25
|
|
|
$this->setContent($content); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setContent($value){ |
29
|
|
|
if (\is_array($value)) { |
30
|
|
|
$image=JArray::getValue($value, "image", 0); |
31
|
|
|
$content=JArray::getValue($value, "content", 1); |
32
|
|
|
$extra=JArray::getValue($value, "extra", 2); |
33
|
|
|
if (isset($image)) { |
34
|
|
|
$this->addImage($image); |
35
|
|
|
} |
36
|
|
|
if(isset($content)) |
37
|
|
|
$this->content["content"]->setContent($content); |
38
|
|
|
if(isset($extra)) |
39
|
|
|
$this->addExtraContent($extra); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function createContent($content, $baseClass="content") { |
44
|
|
|
$count=\sizeof($this->content); |
45
|
|
|
$result=new HtmlViewContent("content-" . $count . "-" . $this->identifier, $content); |
46
|
|
|
$result->setClass($baseClass); |
47
|
|
|
return $result; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function addElementInContent($key, $element) { |
51
|
|
|
if (\array_key_exists($key, $this->content) === false) { |
52
|
|
|
$this->content[$key]=array (); |
53
|
|
|
} |
54
|
|
|
if($this->content[$key] instanceof HtmlViewContent) |
55
|
|
|
$this->content[$key]->addElement($element); |
56
|
|
|
else |
57
|
|
|
$this->content[$key][]=$element; |
58
|
|
|
return $element; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
private function getPart($part, $index=NULL) { |
|
|
|
|
62
|
|
|
if($this->content instanceof HtmlViewContent){ |
63
|
|
|
return $this->content->getPart($part,$index); |
64
|
|
|
} |
65
|
|
|
if (\array_key_exists($part, $this->content)) { |
66
|
|
|
if (isset($index)) |
67
|
|
|
return $this->content[$part][$index]; |
68
|
|
|
return $this->content[$part]; |
69
|
|
|
} |
70
|
|
|
return NULL; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function addHeader($header, $niveau=4, $type="page") { |
74
|
|
|
if (!$header instanceof HtmlHeader) { |
75
|
|
|
$header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type); |
76
|
|
|
} |
77
|
|
|
return $this->addElementInContent("header",$this->createContent($header)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function addImage($image, $title="") { |
81
|
|
|
if (!$image instanceof HtmlImage) { |
82
|
|
|
$image=new HtmlImage("image-" . $this->identifier, $image, $title); |
83
|
|
|
} |
84
|
|
|
$image->setClass("ui image"); |
85
|
|
|
return $this->content["image"]= $image; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
View Code Duplication |
public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) { |
|
|
|
|
89
|
|
|
$reveal=$visibleContent; |
90
|
|
|
if (!$visibleContent instanceof HtmlReveal) { |
91
|
|
|
$reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType); |
92
|
|
|
} |
93
|
|
|
return $this->content["image"]= $reveal; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
View Code Duplication |
public function addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) { |
|
|
|
|
97
|
|
|
$reveal=$visibleContent; |
98
|
|
|
if (!$visibleContent instanceof HtmlReveal) { |
99
|
|
|
return $this->addReveal(new HtmlImage("", $visibleContent), new HtmlImage("", $hiddenContent), $type, $attributeType); |
100
|
|
|
} |
101
|
|
|
return $this->content["image"]= $reveal; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function addExtraContent($content=array()) { |
105
|
|
|
return $this->content["extra-content"]= $this->createContent($content, "extra content"); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function addContent($content=array(), $before=false) { |
109
|
|
|
if (!$content instanceof HtmlViewContent) { |
110
|
|
|
$content=$this->createContent($content); |
111
|
|
|
} |
112
|
|
|
$this->content["content"]->addElement($content); |
113
|
|
|
return $content; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param array $elements |
118
|
|
|
* @param boolean $asIcons |
119
|
|
|
* @return \Ajax\semantic\html\elements\HtmlButtonGroups |
120
|
|
|
*/ |
121
|
|
|
public function addButtons($elements=array(), $asIcons=false,$key="extra-content"){ |
122
|
|
|
$buttons=new HtmlButtonGroups("buttons-".$this->identifier,$elements,$asIcons); |
123
|
|
|
$this->addElementInContent($key, $buttons); |
124
|
|
|
return $buttons; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function addItemHeaderContent($header, $metas=array(), $description=NULL,$extra=NULL) { |
130
|
|
|
return $this->content["content"]->addHeaderContent($header, $metas, $description,$extra); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function addItemContent($content=array()) { |
134
|
|
|
$count=\sizeof($this->content); |
135
|
|
|
return $this->addElementInContent("content", new HtmlViewContent("content-" . $count . "-" . $this->identifier, $content)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getItemContent($index=NULL) { |
139
|
|
|
return $this->content["content"]->getPart($index); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getItemExtraContent() { |
143
|
|
|
return $this->getPart("extra-content"); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function getItemImage() { |
147
|
|
|
return $this->getPart("image"); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function getItemHeader() { |
151
|
|
|
return $this->getPart("header"); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* |
156
|
|
|
* {@inheritDoc} |
157
|
|
|
* |
158
|
|
|
* @see HtmlSemDoubleElement::compile() |
159
|
|
|
*/ |
160
|
|
|
public function compile(JsUtils $js=NULL, &$view=NULL) { |
161
|
|
|
$this->content=JArray::sortAssociative($this->content, ["header","image","content","extra-content"]); |
162
|
|
|
return parent::compile($js, $view); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function asLink($href="",$target=NULL) { |
166
|
|
|
$this->addToProperty("class", "link"); |
167
|
|
|
if ($href !== "") { |
168
|
|
|
$this->setProperty("href", $href); |
169
|
|
|
if (isset($target)) |
170
|
|
|
$this->setProperty("target", $target); |
171
|
|
|
} |
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
} |
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.