11
11
12
12
/**
13
13
* Semantic Tab component
14
+ *
14
15
* @see http://semantic-ui.com/collections/tab.html
15
16
* @author jc
16
17
* @version 1.02
17
18
*/
18
- class HtmlTab extends HtmlSemCollection{
19
+ class HtmlTab extends HtmlSemCollection {
19
20
20
- protected $ params =[];
21
- protected $ _activated =false ;
21
+ protected $ params = [];
22
22
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 ;
28
30
$ this ->addItems ($ tabs );
29
31
}
30
32
31
33
/**
32
- * {@inheritDoc}
34
+ *
35
+ * {@inheritdoc}
33
36
* @see \Ajax\common\html\HtmlCollection::createItem()
34
37
* @return HtmlSegment
35
38
*/
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 ];
42
46
}
43
- $ menuItem= $ this ->content ["menu " ]->addItem ($ title );
47
+ $ menuItem = $ this ->content ["menu " ]->addItem ($ title );
44
48
$ menuItem ->addToProperty ("data-tab " , $ menuItem ->getIdentifier ());
45
49
$ 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 ;
48
52
return $ result ;
49
53
}
50
54
51
55
/**
56
+ *
52
57
* @param int $count
53
58
* @param string $content
54
59
* @param string $datatab
55
60
* @return \Ajax\semantic\html\elements\HtmlSegment
56
61
*/
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 );
60
67
return $ segment ;
61
68
}
62
69
63
70
/**
64
71
* 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
67
77
* @return \Ajax\semantic\html\modules\HtmlTab
68
78
*/
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
75
86
$ this ->content [$ index ]->setContent ($ content );
76
87
}
77
88
return $ this ;
78
89
}
79
90
80
91
/**
81
92
* Sets all contents of tabs
93
+ *
82
94
* @param array $contents
83
95
* @return \Ajax\semantic\html\modules\HtmlTab
84
96
*/
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 ++) {
88
100
$ this ->setTabContent ($ i , $ contents [$ i ]);
89
101
}
90
102
return $ this ;
91
103
}
92
104
93
105
/**
94
106
* Activates the tab element at $index
107
+ *
95
108
* @param int $index
96
109
* @return \Ajax\semantic\html\modules\HtmlTab
97
110
*/
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
+ }
102
118
return $ this ;
103
119
}
104
120
105
121
/**
106
122
* Adds a new tab
123
+ *
107
124
* @param string $title
108
125
* @param string $content
109
126
* @return \Ajax\semantic\html\elements\HtmlSegment
110
127
*/
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
+ ]);
113
133
}
114
134
115
135
/**
116
136
* Renders the content of $controller::$action and sets the response to the tab at $index position
137
+ *
117
138
* @param int $index
118
139
* @param JsUtils $js
119
- * @param string $title The panel title
140
+ * @param string $title
141
+ * The panel title
120
142
* @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
123
147
* @param array $params
124
148
* @return \Ajax\semantic\html\elements\HtmlSegment
125
149
*/
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 );
129
153
return $ this ->content [$ index ];
130
154
}
131
155
132
- return $ this ->addAndForwardTab ($ js , $ title , $ initialController , $ controller , $ action ,$ params );
156
+ return $ this ->addAndForwardTab ($ js , $ title , $ initialController , $ controller , $ action , $ params );
133
157
}
134
158
135
159
/**
136
160
* 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
138
164
* @param JsUtils $js
139
- * @param string $title The panel title
165
+ * @param string $title
166
+ * The panel title
140
167
* @param object $initialController
141
168
* @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
143
171
* @return \Ajax\semantic\html\elements\HtmlSegment
144
172
*/
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 );
148
176
return $ this ->content [$ index ];
149
177
}
150
- return $ this ->addAndRenderViewTab ($ js , $ title , $ initialController , $ viewName ,$ params );
178
+ return $ this ->addAndRenderViewTab ($ js , $ title , $ initialController , $ viewName , $ params );
151
179
}
152
180
153
-
154
181
/**
155
182
* render the content of $controller::$action and set the response to a new tab
183
+ *
156
184
* @param JsUtils $js
157
- * @param string $title The panel title
185
+ * @param string $title
186
+ * The panel title
158
187
* @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
161
192
* @param array $params
162
193
* @return \Ajax\semantic\html\elements\HtmlSegment
163
194
*/
164
- public function addAndForwardTab (JsUtils $ js ,$ title ,$ initialController ,$ controller ,$ action ,$ params= array ()){
195
+ public function addAndForwardTab (JsUtils $ js , $ title , $ initialController , $ controller , $ action , $ params = array ()) {
165
196
\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 );
169
200
}
170
201
171
202
/**
172
203
* render the content of an existing view : $controller/$action and set the response to a new tab
204
+ *
173
205
* @param JsUtils $js
174
- * @param string $title The panel title
206
+ * @param string $title
207
+ * The panel title
175
208
* @param object $initialController
176
209
* @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
178
212
* @return \Ajax\semantic\html\elements\HtmlSegment
179
213
*/
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 ));
182
216
}
183
217
184
- public function setPointing ($ value= Direction::NONE ) {
218
+ public function setPointing ($ value = Direction::NONE ) {
185
219
return $ this ->content ["menu " ]->setPointing ($ value );
186
220
}
187
221
@@ -191,46 +225,50 @@ public function setSecondary() {
191
225
192
226
/**
193
227
* Returns the menu item at position $index
228
+ *
194
229
* @param int $index
195
230
* @return HtmlMenuItem
196
231
*/
197
- public function getMenuTab ($ index ){
232
+ public function getMenuTab ($ index ) {
198
233
return $ this ->content ["menu " ]->getItem ($ index );
199
234
}
200
235
201
236
/**
202
237
* Returns the tab at position $index
238
+ *
203
239
* @param int $index
204
240
* @return HtmlSegment
205
241
*/
206
- public function getTab ($ index ){
242
+ public function getTab ($ index ) {
207
243
return $ this ->content [$ index ];
208
244
}
209
245
210
246
/**
211
247
* Sets the menu of tabs
248
+ *
212
249
* @param HtmlMenu $menu
213
250
* @return \Ajax\semantic\html\modules\HtmlTab
214
251
*/
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 " ));
221
258
}
222
259
}
223
260
}
224
- $ menuSize= $ menu ->count ();
225
- for ($ i= 0 ; $ i < $ menuSize ;$ i ++){
261
+ $ menuSize = $ menu ->count ();
262
+ for ($ i = 0 ; $ i < $ menuSize ; $ i ++) {
226
263
$ 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 ());
229
267
}
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 " ));
231
269
}
232
270
233
- $ this ->content ["menu " ]= $ menu ;
271
+ $ this ->content ["menu " ] = $ menu ;
234
272
return $ this ;
235
273
}
236
274
@@ -239,15 +277,15 @@ public function setMenu($menu){
239
277
* @see BaseHtml::run()
240
278
*/
241
279
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 ;
246
284
}
247
285
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 )
250
288
$ this ->activate (0 );
251
- return parent ::compile ($ js ,$ view );
289
+ return parent ::compile ($ js , $ view );
252
290
}
253
291
}
0 commit comments