Skip to content

Commit c627f69

Browse files
committed
Update HtmlBreadcrumb.php
1 parent ab2190d commit c627f69

File tree

1 file changed

+64
-50
lines changed

1 file changed

+64
-50
lines changed
Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
2-
32
namespace Ajax\semantic\html\collections;
43

54
use Ajax\semantic\html\base\HtmlSemNavElement;
65
use Ajax\semantic\html\base\HtmlSemDoubleElement;
7-
86
use Ajax\semantic\html\elements\HtmlIcon;
97
use Ajax\JsUtils;
108

@@ -17,11 +15,13 @@
1715
* @version 1.001
1816
*/
1917
class HtmlBreadcrumb extends HtmlSemNavElement {
18+
2019
/**
2120
*
2221
* @var integer the start index for href generation
2322
*/
24-
protected $startIndex=0;
23+
protected $startIndex = 0;
24+
2525
/**
2626
*
2727
* @var boolean $autoActive sets the last element's class to <b>active</b> if true
@@ -32,7 +32,7 @@ class HtmlBreadcrumb extends HtmlSemNavElement {
3232
*
3333
* @var boolean if set to true, the path of the elements is absolute
3434
*/
35-
protected $absolutePaths=false;
35+
protected $absolutePaths = false;
3636

3737
/**
3838
*
@@ -44,31 +44,37 @@ class HtmlBreadcrumb extends HtmlSemNavElement {
4444
*
4545
* @param string $identifier
4646
* @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()}
4951
*/
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) {
5153
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) {
5658
return $e->getContent();
5759
};
5860
if (isset($hrefFunction)) {
59-
$this->_hrefFunction=$hrefFunction;
61+
$this->_hrefFunction = $hrefFunction;
6062
}
6163
$this->addItems($items);
6264
}
6365

6466
/**
6567
* Associate an ajax get to the breadcrumb elements, displayed in $targetSelector
6668
* $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
6872
* @return HtmlBreadcrumb
6973
*/
7074
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+
));
7278
}
7379

7480
public function contentAsString() {
@@ -79,37 +85,41 @@ public function contentAsString() {
7985
}
8086

8187
/**
88+
*
8289
* @param int $index
8390
*/
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;
8794
}
88-
$activeItem=$this->content[$index];
95+
$activeItem = $this->content[$index];
8996
$activeItem->addToProperty("class", "active");
9097
$activeItem->setTagName("div");
9198
}
9299

93100
/**
94101
* Adds new elements in breadcrumbs corresponding to request dispatcher : controllerName, actionName, parameters
102+
*
95103
* @param JsUtils $js
96-
* @param object $dispatcher the request dispatcher
104+
* @param object $dispatcher
105+
* the request dispatcher
97106
* @return HtmlBreadcrumb
98107
*/
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;
101110
return $this->addItems($js->fromDispatcher($dispatcher));
102111
}
103112

104113
/**
105114
* Returns the url of the element at $index or the breadcrumbs url if $index is ommited
115+
*
106116
* @param int $index
107117
* @param string $separator
108118
* @return string
109119
*/
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);
113123
}
114124
if ($this->absolutePaths === true) {
115125
return $this->_hrefFunction($this->content[$index]);
@@ -123,34 +133,35 @@ public function getHref($index=null, $separator="/") {
123133
/**
124134
* sets the function who generates the href elements.
125135
* default : function($element){return $element->getContent()}
136+
*
126137
* @param callable $_hrefFunction
127138
* @return HtmlBreadcrumb
128139
*/
129140
public function setHrefFunction($_hrefFunction) {
130-
$this->_hrefFunction=$_hrefFunction;
141+
$this->_hrefFunction = $_hrefFunction;
131142
return $this;
132143
}
133144

134145
public function setStartIndex($startIndex) {
135-
$this->startIndex=$startIndex;
146+
$this->startIndex = $startIndex;
136147
return $this;
137148
}
138149

139150
public function setAutoActive($autoActive) {
140-
$this->autoActive=$autoActive;
151+
$this->autoActive = $autoActive;
141152
return $this;
142153
}
143154

144155
/*
145156
* (non-PHPdoc)
146157
* @see \Ajax\bootstrap\html\BaseHtml::compile()
147158
*/
148-
public function compile(JsUtils $js=NULL, &$view=NULL) {
159+
public function compile(JsUtils $js = NULL, &$view = NULL) {
149160
if ($this->autoActive) {
150161
$this->setActive();
151162
}
152-
$count=$this->count();
153-
for($i=1; $i < $count; $i++) {
163+
$count = $this->count();
164+
for ($i = 1; $i < $count; $i ++) {
154165
$this->content[$i]->wrap($this->getContentDivider($i - 1));
155166
}
156167
return parent::compile($js, $view);
@@ -160,16 +171,16 @@ public function compile(JsUtils $js=NULL, &$view=NULL) {
160171
* (non-PHPdoc)
161172
* @see \Ajax\bootstrap\html\base\BaseHtml::on()
162173
*/
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) {
165176
$element->on($event, $jsCode, $stopPropagation, $preventDefault);
166177
}
167178
return $this;
168179
}
169180

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) {
173184
$element->_ajaxOn($operation, $event, $url, $responseElement, $parameters);
174185
}
175186
}
@@ -178,33 +189,37 @@ public function _ajaxOn($operation, $event, $url, $responseElement="", $paramete
178189

179190
/**
180191
*
181-
* {@inheritDoc}
192+
* {@inheritdoc}
182193
*
183194
* @see \Ajax\common\html\HtmlCollection::createItem()
184195
*/
185196
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 {
191204
$itemO->setContent($value);
192205
}
193206
return $itemO;
194207
}
195208

196209
public function addIconAt($icon, $index) {
197-
$item=$this->getItem($index);
210+
$item = $this->getItem($index);
198211
if (isset($item)) {
199-
$icon=new HtmlIcon("icon-" . $this->identifier, $icon);
212+
$icon = new HtmlIcon("icon-" . $this->identifier, $icon);
200213
$item->wrapContent($icon);
201214
}
202215
}
203216

204217
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+
));
208223
$itemO->setProperty($this->attr, $this->getHref($count));
209224
return $itemO;
210225
}
@@ -214,12 +229,11 @@ public function asTexts() {
214229
}
215230

216231
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 ++) {
220235
$this->content[$i]->setProperty($this->attr, $this->getHref($i));
221236
}
222237
return $this;
223238
}
224-
225239
}

0 commit comments

Comments
 (0)