66use Ajax \semantic \html \base \constants \Direction ;
77use Ajax \semantic \html \elements \HtmlIcon ;
88use Ajax \semantic \html \elements \html5 \HtmlImg ;
9+ use Ajax \JsUtils ;
10+ use Ajax \service \JReflection ;
11+ use Ajax \service \JArray ;
912
1013class HtmlViewContent extends HtmlSemDoubleElement {
1114
1215 public function __construct ($ identifier , $ content =array ()) {
13- parent ::__construct ($ identifier , "div " , "content " , $ content );
16+ parent ::__construct ($ identifier , "div " , "content " ,[]);
17+ $ this ->setContent ($ content );
1418 }
1519
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 ="" ) {
1736 $ 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 );
1939 $ this ->addContent ($ result );
2040 return $ result ;
2141 }
@@ -32,11 +52,19 @@ public function addMeta($value, $direction=Direction::LEFT) {
3252 return $ this ->content ["meta " ];
3353 }
3454
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+
3563 public function addImage ($ src ="" , $ alt ="" , $ size =NULL ) {
3664 $ image =new HtmlImg ("img- " , $ src , $ alt );
3765 if (isset ($ size ))
3866 $ image ->setSize ($ size );
39- $ this ->content [" image " ]=$ image ;
67+ $ this ->content [' image ' ]=$ image ;
4068 return $ image ;
4169 }
4270
@@ -85,12 +113,33 @@ public function addContentIcons($icons, $direction=Direction::LEFT) {
85113 return $ this ;
86114 }
87115
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 " );
90119 $ this ->addMetas ($ metas );
91120 if (isset ($ description )) {
92121 $ this ->addElement ($ description , "description " );
93122 }
123+ if (isset ($ extra )){
124+ $ this ->addExtra ($ extra );
125+ }
94126 return $ this ;
95127 }
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+ }
96145}
0 commit comments