|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content\view; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
|
6
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
|
7
|
|
|
use Ajax\semantic\html\elements\HtmlIcon; |
|
8
|
|
|
use Ajax\semantic\html\elements\html5\HtmlImg; |
|
9
|
|
|
use Ajax\JsUtils; |
|
10
|
|
|
use Ajax\service\JArray; |
|
11
|
|
|
use Ajax\semantic\html\elements\HtmlButtonGroups; |
|
12
|
|
|
|
|
13
|
|
|
class HtmlViewContent extends HtmlSemDoubleElement { |
|
14
|
|
|
use ContentPartTrait; |
|
15
|
|
|
public function __construct($identifier, $content=array()) { |
|
16
|
|
|
parent::__construct($identifier, "div", "content",[]); |
|
17
|
|
|
$this->setContent($content); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function setContent($value){ |
|
21
|
|
|
if (\is_array($value)) { |
|
22
|
|
|
$header=JArray::getValue($value, "header", 0); |
|
23
|
|
|
$metas=JArray::getValue($value, "metas", 1); |
|
24
|
|
|
$description=JArray::getValue($value, "description", 2); |
|
25
|
|
|
$image=JArray::getValue($value, "image", 3); |
|
26
|
|
|
$extra=JArray::getValue($value, "extra", 4); |
|
27
|
|
|
if (isset($image)) { |
|
28
|
|
|
$this->addImage($image); |
|
29
|
|
|
} |
|
30
|
|
|
$this->addHeaderContent($header, $metas, $description,$extra); |
|
31
|
|
|
} else |
|
32
|
|
|
$this->addContent($value); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
public function addElement($content, $baseClass="",$part=NULL) { |
|
|
|
|
|
|
36
|
|
|
$count=\sizeof($this->content); |
|
37
|
|
|
$result=new HtmlViewContent("element-" . $count . "-" . $this->identifier, $content); |
|
38
|
|
|
$result->setClass($baseClass); |
|
39
|
|
|
$this->addContent($result); |
|
40
|
|
|
return $result; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function addMeta($value, $direction=Direction::LEFT) { |
|
44
|
|
|
if (\array_key_exists("meta", $this->content) === false) { |
|
45
|
|
|
$this->content["meta"]=new HtmlSemDoubleElement("meta-" . $this->identifier, "div", "meta", array ()); |
|
46
|
|
|
} |
|
47
|
|
|
if ($direction === Direction::RIGHT) { |
|
48
|
|
|
$value=new HtmlSemDoubleElement("", "span", "", $value); |
|
49
|
|
|
$value->setFloated($direction); |
|
50
|
|
|
} |
|
51
|
|
|
$this->content["meta"]->addContent($value); |
|
52
|
|
|
return $this->content["meta"]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function addExtra($value) { |
|
56
|
|
|
if (\array_key_exists("extra", $this->content) === false) { |
|
57
|
|
|
$this->content["extra"]=new HtmlSemDoubleElement("extra-" . $this->identifier, "div", "extra", array ()); |
|
58
|
|
|
} |
|
59
|
|
|
$this->content["extra"]->addContent($value); |
|
60
|
|
|
return $this->content["extra"]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function addImage($src="", $alt="", $size=NULL) { |
|
64
|
|
|
$image=new HtmlImg("img-", $src, $alt); |
|
65
|
|
|
if (isset($size)) |
|
66
|
|
|
$image->setSize($size); |
|
67
|
|
|
$this->content['image']=$image; |
|
68
|
|
|
return $image; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param array $elements |
|
73
|
|
|
* @param boolean $asIcons |
|
74
|
|
|
* @param string $part |
|
75
|
|
|
* @param boolean $before |
|
76
|
|
|
* @return HtmlButtonGroups |
|
77
|
|
|
*/ |
|
78
|
|
|
public function addContentButtons($elements=array(), $asIcons=false,$part="extra",$before=false){ |
|
79
|
|
|
$buttons=new HtmlButtonGroups("buttons-".$this->identifier,$elements,$asIcons); |
|
80
|
|
|
$this->addElementInPart($buttons,$part, $before,true); |
|
81
|
|
|
return $buttons; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function addMetas($metas) { |
|
85
|
|
|
if (\is_array($metas)) { |
|
86
|
|
|
foreach ( $metas as $meta ) { |
|
87
|
|
|
$this->addMeta($meta); |
|
88
|
|
|
} |
|
89
|
|
|
} else |
|
90
|
|
|
$this->addMeta($metas); |
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function addContentIcon($icon, $caption=NULL, $direction=Direction::LEFT) { |
|
95
|
|
|
if ($direction === Direction::RIGHT) { |
|
96
|
|
|
if (isset($caption)) { |
|
97
|
|
|
$result=new HtmlSemDoubleElement("", "span", "", $caption); |
|
98
|
|
|
$result->addIcon($icon); |
|
99
|
|
|
$this->addContent($result); |
|
100
|
|
|
} else { |
|
101
|
|
|
$result=new HtmlIcon("", $icon); |
|
102
|
|
|
$this->addContent($result); |
|
103
|
|
|
} |
|
104
|
|
|
$result->setFloated($direction); |
|
105
|
|
|
} else { |
|
106
|
|
|
$this->addIcon($icon); |
|
107
|
|
|
$result=$this->addContent($caption); |
|
108
|
|
|
} |
|
109
|
|
|
return $result; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function addContentText($caption, $direction=Direction::LEFT) { |
|
113
|
|
|
if ($direction === Direction::RIGHT) { |
|
114
|
|
|
$result=new HtmlSemDoubleElement("", "span", "", $caption); |
|
115
|
|
|
$this->addContent($result); |
|
116
|
|
|
$result->setFloated($direction); |
|
117
|
|
|
} else |
|
118
|
|
|
$result=$this->addContent($caption); |
|
119
|
|
|
return $result; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function addContentIcons($icons, $direction=Direction::LEFT) { |
|
123
|
|
|
foreach ( $icons as $icon ) { |
|
124
|
|
|
$this->addContentIcon($icon, NULL, $direction); |
|
125
|
|
|
} |
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function addHeaderContent($header, $metas=array(), $description=NULL,$extra=NULL) { |
|
130
|
|
|
if(isset($header)) |
|
131
|
|
|
$this->addElement($header, "header"); |
|
132
|
|
|
$this->addMetas($metas); |
|
133
|
|
|
if (isset($description)) { |
|
134
|
|
|
$this->addElement($description, "description"); |
|
135
|
|
|
} |
|
136
|
|
|
if(isset($extra)){ |
|
137
|
|
|
$this->addExtra($extra); |
|
138
|
|
|
} |
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
143
|
|
|
//$this->content=JArray::sortAssociative($this->content, [ "header","meta","description","extra" ]); |
|
|
|
|
|
|
144
|
|
|
return parent::compile($js, $view); |
|
145
|
|
|
} |
|
146
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.