1111
1212/**
1313 * Semantic Tab component
14+ *
1415 * @see http://semantic-ui.com/collections/tab.html
1516 * @author jc
1617 * @version 1.02
1718 */
18- class HtmlTab extends HtmlSemCollection{
19+ class HtmlTab extends HtmlSemCollection {
1920
20- protected $ params =[];
21- protected $ _activated =false ;
21+ protected $ params = [];
2222
23- public function __construct ( $ identifier , $ tabs =array ()){
24- parent ::__construct ( $ identifier , "div " , "" );
25- $ menu =new HtmlMenu ("menu " .$ this ->identifier );
26- $ menu ->asTab (false )->setAttachment (NULL ,Side::TOP );
27- $ this ->content ["menu " ]=$ menu ;
23+ protected $ _activated = false ;
24+
25+ public function __construct ($ identifier , $ tabs = array ()) {
26+ parent ::__construct ($ identifier , "div " , "" );
27+ $ menu = new HtmlMenu ("menu " . $ this ->identifier );
28+ $ menu ->asTab (false )->setAttachment (NULL , Side::TOP );
29+ $ this ->content ["menu " ] = $ menu ;
2830 $ this ->addItems ($ tabs );
2931 }
3032
3133 /**
32- * {@inheritDoc}
34+ *
35+ * {@inheritdoc}
3336 * @see \Ajax\common\html\HtmlCollection::createItem()
3437 * @return HtmlSegment
3538 */
36- protected function createItem ($ value ){
37- $ count =$ this ->count ();
38- $ title =$ value ;
39- $ content =NULL ;
40- if (\is_array ($ value )){
41- $ title =@$ value [0 ];$ content =@$ value [1 ];
39+ protected function createItem ($ value ) {
40+ $ count = $ this ->count ();
41+ $ title = $ value ;
42+ $ content = NULL ;
43+ if (\is_array ($ value )) {
44+ $ title = @$ value [0 ];
45+ $ content = @$ value [1 ];
4246 }
43- $ menuItem= $ this ->content ["menu " ]->addItem ($ title );
47+ $ menuItem = $ this ->content ["menu " ]->addItem ($ title );
4448 $ menuItem ->addToProperty ("data-tab " , $ menuItem ->getIdentifier ());
4549 $ menuItem ->removeProperty ("href " );
46- $ result= $ this ->createSegment ($ count , $ content , $ menuItem ->getIdentifier ());
47- $ result ->menuTab = $ menuItem ;
50+ $ result = $ this ->createSegment ($ count , $ content , $ menuItem ->getIdentifier ());
51+ $ result ->menuTab = $ menuItem ;
4852 return $ result ;
4953 }
5054
5155 /**
56+ *
5257 * @param int $count
5358 * @param string $content
5459 * @param string $datatab
5560 * @return \Ajax\semantic\html\elements\HtmlSegment
5661 */
57- private function createSegment ($ count ,$ content ,$ datatab ){
58- $ segment =new HtmlSegment ("item- " .$ this ->identifier ."- " .$ count , $ content );
59- $ segment ->setAttachment (NULL ,Side::BOTTOM )->addToProperty ("class " , "tab " )->addToProperty ("data-tab " ,$ datatab );
62+ private function createSegment ($ count , $ content , $ datatab ) {
63+ $ segment = new HtmlSegment ("item- " . $ this ->identifier . "- " . $ count , $ content );
64+ $ segment ->setAttachment (NULL , Side::BOTTOM )
65+ ->addToProperty ("class " , "tab " )
66+ ->addToProperty ("data-tab " , $ datatab );
6067 return $ segment ;
6168 }
6269
6370 /**
6471 * Sets the content of the tab at position $index
65- * @param int $index index of the tab
66- * @param String $content new content
72+ *
73+ * @param int $index
74+ * index of the tab
75+ * @param String $content
76+ * new content
6777 * @return \Ajax\semantic\html\modules\HtmlTab
6878 */
69- public function setTabContent ($ index ,$ content ){
70- $ menu =$ this ->content ["menu " ];
71- if ($ index <$ menu ->count ()){
72- if (isset ($ this ->content [$ index ])===false ){
73- $ this ->content [$ index ]=$ this ->createSegment ($ index , $ content , $ menu ->getItem ($ index )->getIdentifier ());
74- }else
79+ public function setTabContent ($ index , $ content ) {
80+ $ menu = $ this ->content ["menu " ];
81+ if ($ index < $ menu ->count ()) {
82+ if (isset ($ this ->content [$ index ]) === false ) {
83+ $ this ->content [$ index ] = $ this ->createSegment ($ index , $ content , $ menu ->getItem ($ index )
84+ ->getIdentifier ());
85+ } else
7586 $ this ->content [$ index ]->setContent ($ content );
7687 }
7788 return $ this ;
7889 }
7990
8091 /**
8192 * Sets all contents of tabs
93+ *
8294 * @param array $contents
8395 * @return \Ajax\semantic\html\modules\HtmlTab
8496 */
85- public function setTabsContent ($ contents ){
86- $ size= \sizeof ($ contents );
87- for ($ i= 0 ; $ i < $ size ;$ i ++){
97+ public function setTabsContent ($ contents ) {
98+ $ size = \sizeof ($ contents );
99+ for ($ i = 0 ; $ i < $ size ; $ i ++) {
88100 $ this ->setTabContent ($ i , $ contents [$ i ]);
89101 }
90102 return $ this ;
91103 }
92104
93105 /**
94106 * Activates the tab element at $index
107+ *
95108 * @param int $index
96109 * @return \Ajax\semantic\html\modules\HtmlTab
97110 */
98- public function activate ($ index ){
99- $ this ->content ["menu " ]->getItem ($ index )->setActive (true );
100- $ this ->content [$ index ]->setActive (true );
101- $ this ->_activated =true ;
111+ public function activate ($ index ) {
112+ $ item = $ this ->content ["menu " ]->getItem ($ index );
113+ if ($ item != null ) {
114+ $ item ->setActive (true );
115+ $ this ->content [$ index ]->setActive (true );
116+ $ this ->_activated = true ;
117+ }
102118 return $ this ;
103119 }
104120
105121 /**
106122 * Adds a new tab
123+ *
107124 * @param string $title
108125 * @param string $content
109126 * @return \Ajax\semantic\html\elements\HtmlSegment
110127 */
111- public function addTab ($ title ,$ content ){
112- return $ this ->addItem ([$ title ,$ content ]);
128+ public function addTab ($ title , $ content ) {
129+ return $ this ->addItem ([
130+ $ title ,
131+ $ content
132+ ]);
113133 }
114134
115135 /**
116136 * Renders the content of $controller::$action and sets the response to the tab at $index position
137+ *
117138 * @param int $index
118139 * @param JsUtils $js
119- * @param string $title The panel title
140+ * @param string $title
141+ * The panel title
120142 * @param object $initialController
121- * @param string $controller a controller
122- * @param string $action an action
143+ * @param string $controller
144+ * a controller
145+ * @param string $action
146+ * an action
123147 * @param array $params
124148 * @return \Ajax\semantic\html\elements\HtmlSegment
125149 */
126- public function forwardTab ($ index ,JsUtils $ js ,$ title ,$ initialController ,$ controller ,$ action ,$ params= array ()){
127- if (\array_key_exists ($ index , $ this ->content )){
128- $ this ->content [$ index ]= $ js ->forward ($ initialController , $ controller , $ action ,$ params );
150+ public function forwardTab ($ index , JsUtils $ js , $ title , $ initialController , $ controller , $ action , $ params = array ()) {
151+ if (\array_key_exists ($ index , $ this ->content )) {
152+ $ this ->content [$ index ] = $ js ->forward ($ initialController , $ controller , $ action , $ params );
129153 return $ this ->content [$ index ];
130154 }
131155
132- return $ this ->addAndForwardTab ($ js , $ title , $ initialController , $ controller , $ action ,$ params );
156+ return $ this ->addAndForwardTab ($ js , $ title , $ initialController , $ controller , $ action , $ params );
133157 }
134158
135159 /**
136160 * Renders the content of an existing view : $controller/$action and sets the response to the tab at $index position
137- * @param $index
161+ *
162+ * @param
163+ * $index
138164 * @param JsUtils $js
139- * @param string $title The panel title
165+ * @param string $title
166+ * The panel title
140167 * @param object $initialController
141168 * @param string $viewName
142- * @param array $params The parameters to pass to the view
169+ * @param array $params
170+ * The parameters to pass to the view
143171 * @return \Ajax\semantic\html\elements\HtmlSegment
144172 */
145- public function renderViewTab ($ index ,JsUtils $ js ,$ title ,$ initialController , $ viewName , $ params= array ()) {
146- if (\array_key_exists ($ index , $ this ->content )){
147- $ this ->content [$ index ]= $ js ->renderContent ($ initialController , $ viewName ,$ params );
173+ public function renderViewTab ($ index , JsUtils $ js , $ title , $ initialController , $ viewName , $ params = array ()) {
174+ if (\array_key_exists ($ index , $ this ->content )) {
175+ $ this ->content [$ index ] = $ js ->renderContent ($ initialController , $ viewName , $ params );
148176 return $ this ->content [$ index ];
149177 }
150- return $ this ->addAndRenderViewTab ($ js , $ title , $ initialController , $ viewName ,$ params );
178+ return $ this ->addAndRenderViewTab ($ js , $ title , $ initialController , $ viewName , $ params );
151179 }
152180
153-
154181 /**
155182 * render the content of $controller::$action and set the response to a new tab
183+ *
156184 * @param JsUtils $js
157- * @param string $title The panel title
185+ * @param string $title
186+ * The panel title
158187 * @param object $initialController
159- * @param string $controller a controller
160- * @param string $action an action
188+ * @param string $controller
189+ * a controller
190+ * @param string $action
191+ * an action
161192 * @param array $params
162193 * @return \Ajax\semantic\html\elements\HtmlSegment
163194 */
164- public function addAndForwardTab (JsUtils $ js ,$ title ,$ initialController ,$ controller ,$ action ,$ params= array ()){
195+ public function addAndForwardTab (JsUtils $ js , $ title , $ initialController , $ controller , $ action , $ params = array ()) {
165196 \ob_start ();
166- $ js ->forward ($ initialController , $ controller , $ action ,$ params );
167- $ content= \ob_get_clean ();
168- return $ this ->addTab ($ title ,$ content );
197+ $ js ->forward ($ initialController , $ controller , $ action , $ params );
198+ $ content = \ob_get_clean ();
199+ return $ this ->addTab ($ title , $ content );
169200 }
170201
171202 /**
172203 * render the content of an existing view : $controller/$action and set the response to a new tab
204+ *
173205 * @param JsUtils $js
174- * @param string $title The panel title
206+ * @param string $title
207+ * The panel title
175208 * @param object $initialController
176209 * @param string $viewName
177- * @param array $params The parameters to pass to the view
210+ * @param array $params
211+ * The parameters to pass to the view
178212 * @return \Ajax\semantic\html\elements\HtmlSegment
179213 */
180- public function addAndRenderViewTab (JsUtils $ js ,$ title ,$ initialController , $ viewName , $ params= array ()) {
181- return $ this ->addTab ($ title , $ js ->renderContent ($ initialController , $ viewName ,$ params ));
214+ public function addAndRenderViewTab (JsUtils $ js , $ title , $ initialController , $ viewName , $ params = array ()) {
215+ return $ this ->addTab ($ title , $ js ->renderContent ($ initialController , $ viewName , $ params ));
182216 }
183217
184- public function setPointing ($ value= Direction::NONE ) {
218+ public function setPointing ($ value = Direction::NONE ) {
185219 return $ this ->content ["menu " ]->setPointing ($ value );
186220 }
187221
@@ -191,46 +225,50 @@ public function setSecondary() {
191225
192226 /**
193227 * Returns the menu item at position $index
228+ *
194229 * @param int $index
195230 * @return HtmlMenuItem
196231 */
197- public function getMenuTab ($ index ){
232+ public function getMenuTab ($ index ) {
198233 return $ this ->content ["menu " ]->getItem ($ index );
199234 }
200235
201236 /**
202237 * Returns the tab at position $index
238+ *
203239 * @param int $index
204240 * @return HtmlSegment
205241 */
206- public function getTab ($ index ){
242+ public function getTab ($ index ) {
207243 return $ this ->content [$ index ];
208244 }
209245
210246 /**
211247 * Sets the menu of tabs
248+ *
212249 * @param HtmlMenu $menu
213250 * @return \Ajax\semantic\html\modules\HtmlTab
214251 */
215- public function setMenu ($ menu ){
216- $ contentSize= \sizeof ($ this ->content );
217- for ($ i= 0 ; $ i < $ contentSize ;$ i ++){
218- if ($ menu ->getItem ($ i )!==NULL ){
219- if (isset ($ this ->content [$ i ])){
220- $ menu ->getItem ($ i )->addToProperty ("data-tab " ,$ this ->content [$ i ]->getProperty ("data-tab " ));
252+ public function setMenu ($ menu ) {
253+ $ contentSize = \sizeof ($ this ->content );
254+ for ($ i = 0 ; $ i < $ contentSize ; $ i ++) {
255+ if ($ menu ->getItem ($ i ) !== NULL ) {
256+ if (isset ($ this ->content [$ i ])) {
257+ $ menu ->getItem ($ i )->addToProperty ("data-tab " , $ this ->content [$ i ]->getProperty ("data-tab " ));
221258 }
222259 }
223260 }
224- $ menuSize= $ menu ->count ();
225- for ($ i= 0 ; $ i < $ menuSize ;$ i ++){
261+ $ menuSize = $ menu ->count ();
262+ for ($ i = 0 ; $ i < $ menuSize ; $ i ++) {
226263 $ menu ->getItem ($ i )->removeProperty ("href " );
227- if (isset ($ this ->content [$ i ])===false ){
228- $ this ->content [$ i ]=$ this ->createSegment ($ i , "New content " , $ menu ->getItem ($ i )->getIdentifier ());
264+ if (isset ($ this ->content [$ i ]) === false ) {
265+ $ this ->content [$ i ] = $ this ->createSegment ($ i , "New content " , $ menu ->getItem ($ i )
266+ ->getIdentifier ());
229267 }
230- $ menu ->getItem ($ i )->addToProperty ("data-tab " ,$ this ->content [$ i ]->getProperty ("data-tab " ));
268+ $ menu ->getItem ($ i )->addToProperty ("data-tab " , $ this ->content [$ i ]->getProperty ("data-tab " ));
231269 }
232270
233- $ this ->content ["menu " ]= $ menu ;
271+ $ this ->content ["menu " ] = $ menu ;
234272 return $ this ;
235273 }
236274
@@ -239,15 +277,15 @@ public function setMenu($menu){
239277 * @see BaseHtml::run()
240278 */
241279 public function run (JsUtils $ js ) {
242- if (isset ($ this ->_bsComponent )===false )
243- $ this ->_bsComponent = $ js ->semantic ()->tab ("# " . $ this ->identifier . " .item " ,$ this ->params );
244- $ this ->addEventsOnRun ($ js );
245- return $ this ->_bsComponent ;
280+ if (isset ($ this ->_bsComponent ) === false )
281+ $ this ->_bsComponent = $ js ->semantic ()->tab ("# " . $ this ->identifier . " .item " , $ this ->params );
282+ $ this ->addEventsOnRun ($ js );
283+ return $ this ->_bsComponent ;
246284 }
247285
248- public function compile (JsUtils $ js= NULL , &$ view= NULL ) {
249- if (! $ this ->_activated && $ this ->content ["menu " ]->count ()> 0 && \sizeof ($ this ->content )> 1 )
286+ public function compile (JsUtils $ js = NULL , &$ view = NULL ) {
287+ if (! $ this ->_activated && $ this ->content ["menu " ]->count () > 0 && \sizeof ($ this ->content ) > 1 )
250288 $ this ->activate (0 );
251- return parent ::compile ($ js ,$ view );
289+ return parent ::compile ($ js , $ view );
252290 }
253291}
0 commit comments