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