77use Ajax \common \components \SimpleExtComponent ;
88use Ajax \JsUtils ;
99use Ajax \common \html \traits \BaseHtmlEventsTrait ;
10+ use Ajax \common \html \traits \BaseHtmlPropertiesTrait ;
1011
1112/**
1213 * BaseHtml for HTML components
1314 * @author jc
1415 * @version 1.2
1516 */
1617abstract class BaseHtml extends BaseWidget {
17- use BaseHtmlEventsTrait;
18+ use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait ;
1819 protected $ _template ;
1920 protected $ tagName ;
20- protected $ properties =array ();
2121 protected $ _wrapBefore =array ();
2222 protected $ _wrapAfter =array ();
2323 protected $ _bsComponent ;
@@ -35,47 +35,6 @@ protected function getTemplate(JsUtils $js=NULL) {
3535 return PropertyWrapper::wrap ($ this ->_wrapBefore , $ js ) . $ this ->_template . PropertyWrapper::wrap ($ this ->_wrapAfter , $ js );
3636 }
3737
38- public function getProperties () {
39- return $ this ->properties ;
40- }
41-
42- public function setProperties ($ properties ) {
43- $ this ->properties =$ properties ;
44- return $ this ;
45- }
46-
47- public function setProperty ($ name , $ value ) {
48- $ this ->properties [$ name ]=$ value ;
49- return $ this ;
50- }
51-
52- public function getProperty ($ name ) {
53- if (array_key_exists ($ name , $ this ->properties ))
54- return $ this ->properties [$ name ];
55- }
56-
57- public function addToProperty ($ name , $ value , $ separator =" " ) {
58- if (\is_array ($ value )) {
59- foreach ( $ value as $ v ) {
60- $ this ->addToProperty ($ name , $ v , $ separator );
61- }
62- } else if ($ value !== "" && $ this ->propertyContains ($ name , $ value ) === false ) {
63- $ v =@$ this ->properties [$ name ];
64- if (isset ($ v ) && $ v !== "" )
65- $ v =$ v . $ separator . $ value ;
66- else
67- $ v =$ value ;
68-
69- return $ this ->setProperty ($ name , $ v );
70- }
71- return $ this ;
72- }
73-
74- public function addProperties ($ properties ) {
75- $ this ->properties =array_merge ($ this ->properties , $ properties );
76- return $ this ;
77- }
78-
7938 public function compile (JsUtils $ js =NULL , &$ view =NULL ) {
8039 $ result =$ this ->getTemplate ($ js );
8140 foreach ( $ this as $ key => $ value ) {
@@ -110,19 +69,7 @@ protected function ctrl($name, $value, $typeCtrl) {
11069 return true ;
11170 }
11271
113- public function propertyContains ($ propertyName , $ value ) {
114- $ values =$ this ->getProperty ($ propertyName );
115- if (isset ($ values )) {
116- return JString::contains ($ values , $ value );
117- }
118- return false ;
119- }
12072
121- protected function setPropertyCtrl ($ name , $ value , $ typeCtrl ) {
122- if ($ this ->ctrl ($ name , $ value , $ typeCtrl ) === true )
123- return $ this ->setProperty ($ name , $ value );
124- return $ this ;
125- }
12673
12774 protected function setMemberCtrl (&$ name , $ value , $ typeCtrl ) {
12875 if ($ this ->ctrl ($ name , $ value , $ typeCtrl ) === true ) {
@@ -139,21 +86,7 @@ protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ")
13986 return $ this ;
14087 }
14188
142- protected function removePropertyValue ($ name , $ value ) {
143- $ this ->properties [$ name ]=\str_replace ($ value , "" , $ this ->properties [$ name ]);
144- return $ this ;
145- }
146-
147- protected function removePropertyValues ($ name , $ values ) {
148- $ this ->removeOldValues ($ this ->properties [$ name ], $ values );
149- return $ this ;
150- }
15189
152- public function removeProperty ($ name ) {
153- if (\array_key_exists ($ name , $ this ->properties ))
154- unset($ this ->properties [$ name ]);
155- return $ this ;
156- }
15790
15891 protected function addToMemberCtrl (&$ name , $ value , $ typeCtrl , $ separator =" " ) {
15992 if ($ this ->ctrl ($ name , $ value , $ typeCtrl ) === true ) {
@@ -170,25 +103,7 @@ protected function addToMember(&$name, $value, $separator=" ") {
170103 return $ this ;
171104 }
172105
173- protected function addToPropertyUnique ($ name , $ value , $ typeCtrl ) {
174- if (@class_exists ($ typeCtrl , true ))
175- $ typeCtrl =$ typeCtrl ::getConstants ();
176- if (\is_array ($ typeCtrl )) {
177- $ this ->removeOldValues ($ this ->properties [$ name ], $ typeCtrl );
178- }
179- return $ this ->addToProperty ($ name , $ value );
180- }
181106
182- public function addToPropertyCtrl ($ name , $ value , $ typeCtrl ) {
183- return $ this ->addToPropertyUnique ($ name , $ value , $ typeCtrl );
184- }
185-
186- public function addToPropertyCtrlCheck ($ name , $ value , $ typeCtrl ) {
187- if ($ this ->ctrl ($ name , $ value , $ typeCtrl ) === true ) {
188- return $ this ->addToProperty ($ name , $ value );
189- }
190- return $ this ;
191- }
192107
193108 protected function removeOldValues (&$ oldValue , $ allValues ) {
194109 $ oldValue =str_ireplace ($ allValues , "" , $ oldValue );
@@ -278,24 +193,6 @@ public function getElementById($identifier, $elements) {
278193 return null ;
279194 }
280195
281- protected function getElementByPropertyValue ($ propertyName ,$ value , $ elements ) {
282- if (\is_array ($ elements )) {
283- $ flag =false ;
284- $ index =0 ;
285- while ( !$ flag && $ index < sizeof ($ elements ) ) {
286- if ($ elements [$ index ] instanceof BaseHtml)
287- $ flag =($ elements [$ index ]->propertyContains ($ propertyName , $ value ) === true );
288- $ index ++;
289- }
290- if ($ flag === true )
291- return $ elements [$ index - 1 ];
292- } elseif ($ elements instanceof BaseHtml) {
293- if ($ elements ->propertyContains ($ propertyName , $ value ) === true )
294- return $ elements ;
295- }
296- return null ;
297- }
298-
299196 public function __toString () {
300197 return $ this ->compile ();
301198 }
0 commit comments