1
1
<?php
2
-
3
2
namespace Ajax \semantic \html \collections ;
4
3
5
4
use Ajax \semantic \html \base \HtmlSemNavElement ;
6
5
use Ajax \semantic \html \base \HtmlSemDoubleElement ;
7
-
8
6
use Ajax \semantic \html \elements \HtmlIcon ;
9
7
use Ajax \JsUtils ;
10
8
17
15
* @version 1.001
18
16
*/
19
17
class HtmlBreadcrumb extends HtmlSemNavElement {
18
+
20
19
/**
21
20
*
22
21
* @var integer the start index for href generation
23
22
*/
24
- protected $ startIndex =0 ;
23
+ protected $ startIndex = 0 ;
24
+
25
25
/**
26
26
*
27
27
* @var boolean $autoActive sets the last element's class to <b>active</b> if true
@@ -32,7 +32,7 @@ class HtmlBreadcrumb extends HtmlSemNavElement {
32
32
*
33
33
* @var boolean if set to true, the path of the elements is absolute
34
34
*/
35
- protected $ absolutePaths= false ;
35
+ protected $ absolutePaths = false ;
36
36
37
37
/**
38
38
*
@@ -44,31 +44,37 @@ class HtmlBreadcrumb extends HtmlSemNavElement {
44
44
*
45
45
* @param string $identifier
46
46
* @param array $items
47
- * @param boolean $autoActive sets the last element's class to <b>active</b> if true
48
- * @param callable $hrefFunction the function who generates the href elements. default : function($e){return $e->getContent()}
47
+ * @param boolean $autoActive
48
+ * sets the last element's class to <b>active</b> if true
49
+ * @param callable $hrefFunction
50
+ * the function who generates the href elements. default : function($e){return $e->getContent()}
49
51
*/
50
- public function __construct ($ identifier , $ items= array (), $ autoActive= true , $ startIndex= 0 , $ hrefFunction= NULL ) {
52
+ public function __construct ($ identifier , $ items = array (), $ autoActive = true , $ startIndex = 0 , $ hrefFunction = NULL ) {
51
53
parent ::__construct ($ identifier , "div " , "ui breadcrumb " );
52
- $ this ->startIndex = $ startIndex ;
53
- $ this ->autoActive = $ autoActive ;
54
- $ this ->_contentSeparator = "<div class='divider'> / </div> " ;
55
- $ this ->_hrefFunction = function (HtmlSemDoubleElement $ e ) {
54
+ $ this ->startIndex = $ startIndex ;
55
+ $ this ->autoActive = $ autoActive ;
56
+ $ this ->_contentSeparator = "<div class='divider'> / </div> " ;
57
+ $ this ->_hrefFunction = function (HtmlSemDoubleElement $ e ) {
56
58
return $ e ->getContent ();
57
59
};
58
60
if (isset ($ hrefFunction )) {
59
- $ this ->_hrefFunction = $ hrefFunction ;
61
+ $ this ->_hrefFunction = $ hrefFunction ;
60
62
}
61
63
$ this ->addItems ($ items );
62
64
}
63
65
64
66
/**
65
67
* Associate an ajax get to the breadcrumb elements, displayed in $targetSelector
66
68
* $this->attr member is used to build each element url
67
- * @param string $targetSelector the target of the get
69
+ *
70
+ * @param string $targetSelector
71
+ * the target of the get
68
72
* @return HtmlBreadcrumb
69
73
*/
70
74
public function autoGetOnClick ($ targetSelector ) {
71
- return $ this ->getOnClick ($ this ->root , $ targetSelector , array ("attr " => $ this ->attr ));
75
+ return $ this ->getOnClick ($ this ->root , $ targetSelector , array (
76
+ "attr " => $ this ->attr
77
+ ));
72
78
}
73
79
74
80
public function contentAsString () {
@@ -79,37 +85,41 @@ public function contentAsString() {
79
85
}
80
86
81
87
/**
88
+ *
82
89
* @param int $index
83
90
*/
84
- public function setActive ($ index= null ) {
85
- if (!isset ($ index )) {
86
- $ index= sizeof ($ this ->content ) - 1 ;
91
+ public function setActive ($ index = null ) {
92
+ if (! isset ($ index )) {
93
+ $ index = sizeof ($ this ->content ) - 1 ;
87
94
}
88
- $ activeItem= $ this ->content [$ index ];
95
+ $ activeItem = $ this ->content [$ index ];
89
96
$ activeItem ->addToProperty ("class " , "active " );
90
97
$ activeItem ->setTagName ("div " );
91
98
}
92
99
93
100
/**
94
101
* Adds new elements in breadcrumbs corresponding to request dispatcher : controllerName, actionName, parameters
102
+ *
95
103
* @param JsUtils $js
96
- * @param object $dispatcher the request dispatcher
104
+ * @param object $dispatcher
105
+ * the request dispatcher
97
106
* @return HtmlBreadcrumb
98
107
*/
99
- public function fromDispatcher (JsUtils $ js ,$ dispatcher , $ startIndex= 0 ) {
100
- $ this ->startIndex = $ startIndex ;
108
+ public function fromDispatcher (JsUtils $ js , $ dispatcher , $ startIndex = 0 ) {
109
+ $ this ->startIndex = $ startIndex ;
101
110
return $ this ->addItems ($ js ->fromDispatcher ($ dispatcher ));
102
111
}
103
112
104
113
/**
105
114
* Returns the url of the element at $index or the breadcrumbs url if $index is ommited
115
+ *
106
116
* @param int $index
107
117
* @param string $separator
108
118
* @return string
109
119
*/
110
- public function getHref ($ index= null , $ separator= "/ " ) {
111
- if (!isset ($ index )) {
112
- $ index= sizeof ($ this ->content );
120
+ public function getHref ($ index = null , $ separator = "/ " ) {
121
+ if (! isset ($ index )) {
122
+ $ index = sizeof ($ this ->content );
113
123
}
114
124
if ($ this ->absolutePaths === true ) {
115
125
return $ this ->_hrefFunction ($ this ->content [$ index ]);
@@ -123,34 +133,35 @@ public function getHref($index=null, $separator="/") {
123
133
/**
124
134
* sets the function who generates the href elements.
125
135
* default : function($element){return $element->getContent()}
136
+ *
126
137
* @param callable $_hrefFunction
127
138
* @return HtmlBreadcrumb
128
139
*/
129
140
public function setHrefFunction ($ _hrefFunction ) {
130
- $ this ->_hrefFunction = $ _hrefFunction ;
141
+ $ this ->_hrefFunction = $ _hrefFunction ;
131
142
return $ this ;
132
143
}
133
144
134
145
public function setStartIndex ($ startIndex ) {
135
- $ this ->startIndex = $ startIndex ;
146
+ $ this ->startIndex = $ startIndex ;
136
147
return $ this ;
137
148
}
138
149
139
150
public function setAutoActive ($ autoActive ) {
140
- $ this ->autoActive = $ autoActive ;
151
+ $ this ->autoActive = $ autoActive ;
141
152
return $ this ;
142
153
}
143
154
144
155
/*
145
156
* (non-PHPdoc)
146
157
* @see \Ajax\bootstrap\html\BaseHtml::compile()
147
158
*/
148
- public function compile (JsUtils $ js= NULL , &$ view= NULL ) {
159
+ public function compile (JsUtils $ js = NULL , &$ view = NULL ) {
149
160
if ($ this ->autoActive ) {
150
161
$ this ->setActive ();
151
162
}
152
- $ count= $ this ->count ();
153
- for ($ i= 1 ; $ i < $ count ; $ i ++) {
163
+ $ count = $ this ->count ();
164
+ for ($ i = 1 ; $ i < $ count ; $ i ++) {
154
165
$ this ->content [$ i ]->wrap ($ this ->getContentDivider ($ i - 1 ));
155
166
}
156
167
return parent ::compile ($ js , $ view );
@@ -160,16 +171,16 @@ public function compile(JsUtils $js=NULL, &$view=NULL) {
160
171
* (non-PHPdoc)
161
172
* @see \Ajax\bootstrap\html\base\BaseHtml::on()
162
173
*/
163
- public function on ($ event , $ jsCode , $ stopPropagation= false , $ preventDefault= false ) {
164
- foreach ( $ this ->content as $ element ) {
174
+ public function on ($ event , $ jsCode , $ stopPropagation = false , $ preventDefault = false ) {
175
+ foreach ($ this ->content as $ element ) {
165
176
$ element ->on ($ event , $ jsCode , $ stopPropagation , $ preventDefault );
166
177
}
167
178
return $ this ;
168
179
}
169
180
170
- public function _ajaxOn ($ operation , $ event , $ url , $ responseElement= "" , $ parameters= array ()) {
171
- foreach ( $ this ->content as $ element ) {
172
- if ($ element ->getProperty ($ this ->attr ) != NULL ){
181
+ public function _ajaxOn ($ operation , $ event , $ url , $ responseElement = "" , $ parameters = array ()) {
182
+ foreach ($ this ->content as $ element ) {
183
+ if ($ element ->getProperty ($ this ->attr ) != NULL ) {
173
184
$ element ->_ajaxOn ($ operation , $ event , $ url , $ responseElement , $ parameters );
174
185
}
175
186
}
@@ -178,33 +189,37 @@ public function _ajaxOn($operation, $event, $url, $responseElement="", $paramete
178
189
179
190
/**
180
191
*
181
- * {@inheritDoc }
192
+ * {@inheritdoc }
182
193
*
183
194
* @see \Ajax\common\html\HtmlCollection::createItem()
184
195
*/
185
196
protected function createItem ($ value ) {
186
- $ count =$ this ->count ();
187
- $ itemO =new HtmlSemDoubleElement ("item- " . $ this ->identifier . "- " . $ count , "a " , "section " );
188
- if (\is_array ($ value ))
189
- $ itemO ->fromArray ($ value );
190
- else {
197
+ $ count = $ this ->count ();
198
+ $ itemO = new HtmlSemDoubleElement ("item- " . $ this ->identifier . "- " . $ count , "a " , "section " );
199
+ if (\is_array ($ value )) {
200
+ @list ($ text , $ href ) = $ value ;
201
+ $ itemO ->setContent ($ text );
202
+ $ itemO ->setProperty ('href ' , $ href );
203
+ } else {
191
204
$ itemO ->setContent ($ value );
192
205
}
193
206
return $ itemO ;
194
207
}
195
208
196
209
public function addIconAt ($ icon , $ index ) {
197
- $ item= $ this ->getItem ($ index );
210
+ $ item = $ this ->getItem ($ index );
198
211
if (isset ($ item )) {
199
- $ icon= new HtmlIcon ("icon- " . $ this ->identifier , $ icon );
212
+ $ icon = new HtmlIcon ("icon- " . $ this ->identifier , $ icon );
200
213
$ item ->wrapContent ($ icon );
201
214
}
202
215
}
203
216
204
217
public function addItem ($ item ) {
205
- $ count =$ this ->count ();
206
- $ itemO =parent ::addItem ($ item );
207
- $ this ->addToPropertyCtrl ("class " , "section " , array ("section " ));
218
+ $ count = $ this ->count ();
219
+ $ itemO = parent ::addItem ($ item );
220
+ $ this ->addToPropertyCtrl ("class " , "section " , array (
221
+ "section "
222
+ ));
208
223
$ itemO ->setProperty ($ this ->attr , $ this ->getHref ($ count ));
209
224
return $ itemO ;
210
225
}
@@ -214,12 +229,11 @@ public function asTexts() {
214
229
}
215
230
216
231
public function setAbsolutePaths ($ absolutePaths ) {
217
- $ this ->absolutePaths = $ absolutePaths ;
218
- $ size= \sizeof ($ this ->content );
219
- for ($ i= 0 ; $ i < $ size ;$ i ++){
232
+ $ this ->absolutePaths = $ absolutePaths ;
233
+ $ size = \sizeof ($ this ->content );
234
+ for ($ i = 0 ; $ i < $ size ; $ i ++) {
220
235
$ this ->content [$ i ]->setProperty ($ this ->attr , $ this ->getHref ($ i ));
221
236
}
222
237
return $ this ;
223
238
}
224
-
225
239
}
0 commit comments