phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlBreadcrumbs.php
Go to the documentation of this file.
1<?php
2namespace Ajax\bootstrap\html;
3
6
17
21 protected $startIndex=0;
25 protected $autoActive;
26
30 protected $absolutePaths;
31
35 protected $_hrefFunction;
36
37
44 public function __construct($identifier,$elements=array(),$autoActive=true,$startIndex=0,$hrefFunction=NULL){
45 parent::__construct($identifier,"ol");
46 $this->startIndex=$startIndex;
47 $this->setProperty("class", "breadcrumb");
48 $this->content=array();
49 $this->autoActive=$autoActive;
51 $this->_hrefFunction=function (HtmlDoubleElement $e){return $e->getContent();};
52 if(isset($hrefFunction)){
53 $this->_hrefFunction=$hrefFunction;
54 }
55 $this->addElements($elements);
56 }
57
63 public function addElement($element,$href="",$glyph=NULL){
64 $size=sizeof($this->content);
65 if(\is_array($element)){
66 $elm=new HtmlLink("lnk-".$this->identifier."-".$size);
67 $elm->fromArray($element);
68 }else if($element instanceof HtmlLink){
69 $elm=$element;
70 }else{
71 $elm=new HtmlLink("lnk-".$this->identifier."-".$size,$href,$element);
72 if(isset($glyph)){
73 $elm->wrapContentWithGlyph($glyph);
74 }
75 }
76 $elm->wrap("<li>","</li>");
77 $this->content[]=$elm;
78 $elm->setProperty($this->attr, $this->getHref($size));
79 return $elm;
80 }
81
82 public function setActive($index=null){
83 if(!isset($index)){
84 $index=sizeof($this->content)-1;
85 }
86 $li=new HtmlBsDoubleElement("","li");
87 $li->setClass("active");
88 $li->setContent($this->content[$index]->getContent());
89 $this->content[$index]=$li;
90 }
91
92 public function addElements($elements){
93 foreach ( $elements as $element ) {
94 $this->addElement($element);
95 }
96 return $this;
97 }
98
99 public function fromArray($array){
100 $array=parent::fromArray($array);
101 $this->addElements($array);
102 return $array;
103 }
104
111 public function getHref($index=null,$separator="/"){
112 if(!isset($index)){
113 $index=sizeof($this->content);
114 }
115 if($this->absolutePaths===true){
116 return $this->_hrefFunction($this->content[$index]);
117 }else{
118 return $this->root.implode($separator, array_slice(array_map(function($e){return $this->_hrefFunction($e);}, $this->content),$this->startIndex,$index+1));
119 }
120 }
121
122 /*
123 * (non-PHPdoc)
124 * @see \Ajax\bootstrap\html\BaseHtml::compile()
125 */
126 public function compile(JsUtils $js=NULL, &$view=NULL) {
127 if($this->autoActive){
128 $this->setActive();
129 }
130 return parent::compile($js, $view);
131 }
132
133 /* (non-PHPdoc)
134 * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject()
135 */
136 public function fromDatabaseObject($object, $function) {
137 return $this->addElement($function($object));
138 }
139
140 /*
141 * (non-PHPdoc)
142 * @see \Ajax\bootstrap\html\base\BaseHtml::on()
143 */
144 public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
145 foreach ($this->content as $element){
146 $element->on($event,$jsCode,$stopPropagation,$preventDefault);
147 }
148 return $this;
149 }
150
151 public function setAutoActive($autoActive) {
152 $this->autoActive = $autoActive;
153 return $this;
154 }
155
156 public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) {
157 foreach ($this->content as $element){
158 $element->_ajaxOn($operation, $event, $url, $responseElement, $parameters);
159 }
160 return $this;
161 }
162
169 public function autoGetOnClick($targetSelector){
170 return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr));
171 }
172
173 public function contentAsString(){
174 if($this->autoActive){
175 $this->setActive();
176 }
177 return parent::contentAsString();
178 }
179
180 public function getElement($index){
181 return $this->content[$index];
182 }
183
189 public function addGlyph($glyph,$index=0){
190 $elm=$this->getElement($index);
191 return $elm->wrapContentWithGlyph($glyph);
192 }
193
200 public function fromDispatcher(JsUtils $js,$dispatcher,$startIndex=0){
201 $this->startIndex=$startIndex;
202 return $this->addElements($js->fromDispatcher($dispatcher));
203 }
204
205
212 $this->_hrefFunction = $_hrefFunction;
213 return $this;
214 }
215
216 public function setStartIndex($startIndex) {
217 $this->startIndex=$startIndex;
218 return $this;
219 }
220
221
222}
JQuery PHP library.
Definition JsUtils.php:23
fromDispatcher($dispatcher)
Collects url parts from the request dispatcher : controllerName, actionName, parameters Used internal...
Twitter Bootstrap Breadcrumbs component.
addElement($element, $href="", $glyph=NULL)
addGlyph($glyph, $index=0)
Add a glyphicon to the element at index $index.
fromDispatcher(JsUtils $js, $dispatcher, $startIndex=0)
Add new elements in breadcrumbs corresponding to request dispatcher : controllerName,...
autoGetOnClick($targetSelector)
Associate an ajax get to the breadcrumbs elements, displayed in $targetSelector $attr member is used ...
setHrefFunction($_hrefFunction)
sets the function who generates the href elements.
__construct($identifier, $elements=array(), $autoActive=true, $startIndex=0, $hrefFunction=NULL)
compile(JsUtils $js=NULL, &$view=NULL)
_ajaxOn($operation, $event, $url, $responseElement="", $parameters=array())
getHref($index=null, $separator="/")
Return the url of the element at $index or the breadcrumbs url if $index is ommited.
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
Bs class for navigation elements : Breadcrumbs and Pagination.
getOnClick($url, $responseElement="", $parameters=array())
Performs a get to $url on the click event on $element and display it in $responseElement.