6
6
use Ajax \semantic \html \base \constants \Direction ;
7
7
use Ajax \semantic \html \elements \HtmlIcon ;
8
8
use Ajax \semantic \html \elements \html5 \HtmlImg ;
9
+ use Ajax \JsUtils ;
10
+ use Ajax \service \JReflection ;
11
+ use Ajax \service \JArray ;
9
12
10
13
class HtmlViewContent extends HtmlSemDoubleElement {
11
14
12
15
public function __construct ($ identifier , $ content =array ()) {
13
- parent ::__construct ($ identifier , "div " , "content " , $ content );
16
+ parent ::__construct ($ identifier , "div " , "content " ,[]);
17
+ $ this ->setContent ($ content );
14
18
}
15
19
16
- private function addElement ($ content , $ baseClass ) {
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
+ public function addElement ($ content , $ baseClass ="" ) {
17
36
$ count =\sizeof ($ this ->content );
18
- $ result =new HtmlSemDoubleElement ("element- " . $ count . "- " . $ this ->identifier , "div " , $ baseClass , $ content );
37
+ $ result =new HtmlViewContent ("element- " . $ count . "- " . $ this ->identifier , $ content );
38
+ $ result ->setClass ($ baseClass );
19
39
$ this ->addContent ($ result );
20
40
return $ result ;
21
41
}
@@ -32,11 +52,19 @@ public function addMeta($value, $direction=Direction::LEFT) {
32
52
return $ this ->content ["meta " ];
33
53
}
34
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
+
35
63
public function addImage ($ src ="" , $ alt ="" , $ size =NULL ) {
36
64
$ image =new HtmlImg ("img- " , $ src , $ alt );
37
65
if (isset ($ size ))
38
66
$ image ->setSize ($ size );
39
- $ this ->content [" image " ]=$ image ;
67
+ $ this ->content [' image ' ]=$ image ;
40
68
return $ image ;
41
69
}
42
70
@@ -85,12 +113,33 @@ public function addContentIcons($icons, $direction=Direction::LEFT) {
85
113
return $ this ;
86
114
}
87
115
88
- public function addHeaderContent ($ header , $ metas =array (), $ description =NULL ) {
89
- $ this ->addElement ($ header , "header " );
116
+ public function addHeaderContent ($ header , $ metas =array (), $ description =NULL ,$ extra =NULL ) {
117
+ if (isset ($ header ))
118
+ $ this ->addElement ($ header , "header " );
90
119
$ this ->addMetas ($ metas );
91
120
if (isset ($ description )) {
92
121
$ this ->addElement ($ description , "description " );
93
122
}
123
+ if (isset ($ extra )){
124
+ $ this ->addExtra ($ extra );
125
+ }
94
126
return $ this ;
95
127
}
128
+
129
+ public function getPart ($ part , $ index =NULL ) {
130
+ if ($ this ->content instanceof HtmlViewContent){
131
+ return $ this ->content ->getPart ($ part ,$ index );
132
+ }
133
+ if (\array_key_exists ($ part , $ this ->content )) {
134
+ if (isset ($ index ))
135
+ return $ this ->content [$ part ][$ index ];
136
+ return $ this ->content [$ part ];
137
+ }
138
+ return NULL ;
139
+ }
140
+
141
+ public function compile (JsUtils $ js =NULL , &$ view =NULL ) {
142
+ //$this->content=JArray::sortAssociative($this->content, [ "header","meta","description","extra" ]);
143
+ return parent ::compile ($ js , $ view );
144
+ }
96
145
}
0 commit comments