phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlBreadcrumb.php
Go to the documentation of this file.
1 <?php
3 
7 use Ajax\JsUtils;
8 
18 
23  protected $startIndex = 0;
24 
29  protected $autoActive;
30 
35  protected $absolutePaths = false;
36 
41  protected $_hrefFunction;
42 
52  public function __construct($identifier, $items = array(), $autoActive = true, $startIndex = 0, $hrefFunction = NULL) {
53  parent::__construct($identifier, "div", "ui breadcrumb");
54  $this->startIndex = $startIndex;
55  $this->autoActive = $autoActive;
56  $this->_contentSeparator = "<div class='divider'> / </div>";
57  $this->_hrefFunction = function (HtmlSemDoubleElement $e) {
58  return $e->getContent();
59  };
60  if (isset($hrefFunction)) {
61  $this->_hrefFunction = $hrefFunction;
62  }
63  $this->addItems($items);
64  }
65 
74  public function autoGetOnClick($targetSelector) {
75  return $this->getOnClick($this->root, $targetSelector, array(
76  "attr" => $this->attr
77  ));
78  }
79 
80  public function contentAsString() {
81  if ($this->autoActive) {
82  $this->setActive();
83  }
84  return parent::contentAsString();
85  }
86 
91  public function setActive($index = null) {
92  if (! isset($index)) {
93  $index = sizeof($this->content) - 1;
94  }
95  $activeItem = $this->content[$index];
96  $activeItem->addToProperty("class", "active");
97  $activeItem->setTagName("div");
98  }
99 
108  public function fromDispatcher(JsUtils $js, $dispatcher, $startIndex = 0) {
109  $this->startIndex = $startIndex;
110  return $this->addItems($js->fromDispatcher($dispatcher));
111  }
112 
120  public function getHref($index = null, $separator = "/") {
121  if (! isset($index)) {
122  $index = sizeof($this->content);
123  }
124  if ($this->absolutePaths === true) {
125  return $this->_hrefFunction($this->content[$index]);
126  } else {
127  return $this->root . implode($separator, array_slice(array_map(function ($e) {
128  return $this->_hrefFunction($e);
129  }, $this->content), $this->startIndex, $index + 1));
130  }
131  }
132 
140  public function setHrefFunction($_hrefFunction) {
141  $this->_hrefFunction = $_hrefFunction;
142  return $this;
143  }
144 
145  public function setStartIndex($startIndex) {
146  $this->startIndex = $startIndex;
147  return $this;
148  }
149 
150  public function setAutoActive($autoActive) {
151  $this->autoActive = $autoActive;
152  return $this;
153  }
154 
155  /*
156  * (non-PHPdoc)
157  * @see \Ajax\bootstrap\html\BaseHtml::compile()
158  */
159  public function compile(JsUtils $js = NULL, &$view = NULL) {
160  if ($this->autoActive) {
161  $this->setActive();
162  }
163  $count = $this->count();
164  for ($i = 1; $i < $count; $i ++) {
165  $this->content[$i]->wrap($this->getContentDivider($i - 1));
166  }
167  return parent::compile($js, $view);
168  }
169 
170  /*
171  * (non-PHPdoc)
172  * @see \Ajax\bootstrap\html\base\BaseHtml::on()
173  */
174  public function on($event, $jsCode, $stopPropagation = false, $preventDefault = false) {
175  foreach ($this->content as $element) {
176  $element->on($event, $jsCode, $stopPropagation, $preventDefault);
177  }
178  return $this;
179  }
180 
181  public function _ajaxOn($operation, $event, $url, $responseElement = "", $parameters = array()) {
182  foreach ($this->content as $element) {
183  if ($element->getProperty($this->attr) != NULL) {
184  $element->_ajaxOn($operation, $event, $url, $responseElement, $parameters);
185  }
186  }
187  return $this;
188  }
189 
196  protected function createItem($value) {
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 {
204  $itemO->setContent($value);
205  }
206  return $itemO;
207  }
208 
209  public function addIconAt($icon, $index) {
210  $item = $this->getItem($index);
211  if (isset($item)) {
212  $icon = new HtmlIcon("icon-" . $this->identifier, $icon);
213  $item->wrapContent($icon);
214  }
215  }
216 
217  public function addItem($item) {
218  $count = $this->count();
219  $itemO = parent::addItem($item);
220  $this->addToPropertyCtrl("class", "section", array(
221  "section"
222  ));
223  $itemO->setProperty($this->attr, $this->getHref($count));
224  return $itemO;
225  }
226 
227  public function asTexts() {
228  $this->contentAs("div");
229  }
230 
231  public function setAbsolutePaths($absolutePaths) {
232  $this->absolutePaths = $absolutePaths;
233  $size = \sizeof($this->content);
234  for ($i = 0; $i < $size; $i ++) {
235  $this->content[$i]->setProperty($this->attr, $this->getHref($i));
236  }
237  return $this;
238  }
239 }
Sem class for navigation elements : Breadcrumbs and Pagination.
fromDispatcher($dispatcher)
Collects url parts from the request dispatcher : controllerName, actionName, parameters Used internal...
setHrefFunction($_hrefFunction)
sets the function who generates the href elements.
Semantic UI Breadcrumb component.
Semantic Icon component.
Definition: HtmlIcon.php:14
_ajaxOn($operation, $event, $url, $responseElement="", $parameters=array())
__construct($identifier, $items=array(), $autoActive=true, $startIndex=0, $hrefFunction=NULL)
autoGetOnClick($targetSelector)
Associate an ajax get to the breadcrumb elements, displayed in $targetSelector $this->attr member is ...
getItem($index)
Return the item at index.
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
compile(JsUtils $js=NULL, &$view=NULL)
Base class for Semantic double elements.
JQuery PHP library.
Definition: JsUtils.php:23
getOnClick($url, $responseElement="", $parameters=array())
Performs a get to $url on the click event on $element and display it in $responseElement.
attr($element='this', $attributeName='id', $value="", $immediatly=false)
Get or set the value of an attribute for the first element in the set of matched elements or set one ...
getHref($index=null, $separator="/")
Returns the url of the element at $index or the breadcrumbs url if $index is ommited.
addToPropertyCtrl($name, $value, $typeCtrl)
fromDispatcher(JsUtils $js, $dispatcher, $startIndex=0)
Adds new elements in breadcrumbs corresponding to request dispatcher : controllerName, actionName, parameters.