phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlNavbar.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ajax\bootstrap\html;
4 
5 use Ajax\JsUtils;
16 class HtmlNavbar extends BaseHtml {
17  protected $navZones;
18  protected $class="navbar-default";
19  protected $brand="Brand";
20  protected $brandHref="#";
21  protected $brandTarget="_self";
22  protected $brandImage="";
23  protected $scrollspy;
24  protected $hasScrollspy=false;
25  protected $scrollspyId="body";
26  protected $fluid="container-fluid";
27 
32  public function __construct($identifier, $brand="Brand", $brandHref="#") {
33  parent::__construct($identifier);
34  $this->_template=include 'templates/tplNavbar.php';
35  $this->navZones=array ();
36  $this->class="navbar-default";
37  $this->brand=$brand;
38  $this->brandHref=$brandHref;
39 
40  }
41 
42  public function setClass($class) {
43  $this->class=$class;
44  return $this;
45  }
46 
47  public function setBrand($brand) {
48  $this->brand=$brand;
49  return $this;
50  }
51 
52  public function setBrandHref($brandHref) {
53  $this->brandHref=$brandHref;
54  return $this;
55  }
56 
57  public function setBrandTarget($brandTarget) {
58  $this->brandTarget=$brandTarget;
59  return $this;
60  }
61 
62  public function setBrandImage($imageSrc) {
63  $this->brandImage=new HtmlImg("brand-img-".$this->_identifier,$imageSrc,$this->brand);
64  $this->brand="";
65  return $this;
66  }
67 
74  public function addZone($type="nav", $identifier=NULL) {
75  if (!isset($identifier)) {
76  $nb=sizeof($this->navZones)+1;
77  $identifier=$this->identifier."-navzone-".$nb;
78  }
79  $zone=HtmlNavzone::$type($identifier);
80  $this->navZones []=$zone;
81  return $zone;
82  }
83 
84  public function addElement($element, HtmlNavzone $zone=NULL) {
85  $zone=$this->getZoneToInsertIn($zone);
86  if ($element instanceof HtmlDropdown)
87  $element->setMTagName("li");
88  $zone->addElement($element);
89  }
90 
91  public function addElements($elements, HtmlNavzone $zone=NULL) {
92  $zone=$this->getZoneToInsertIn($zone);
93  $zone->addElements($elements);
94  return $zone;
95  }
96 
101  public function fromArray($array) {
102  return parent::fromArray($array);
103  }
104 
105  public function setNavZones($navZones) {
106  if (\is_array($navZones)) {
107  foreach ( $navZones as $zoneType => $zoneArray ) {
108  if (is_string($zoneType)) {
109  $zone=$this->addZone($zoneType);
110  $zone->fromArray($zoneArray);
111  } else if (is_string($zoneArray))
112  $this->addElement($zoneArray);
113  else
114  $this->addElements($zoneArray);
115  }
116  }
117  }
118 
124  public function getZoneToInsertIn($zone=NULL) {
125  if (!isset($zone)) {
126  $nb=sizeof($this->navZones);
127  if ($nb<1)
128  $zone=$this->addZone();
129  else
130  $zone=$this->navZones [$nb-1];
131  }
132  return $zone;
133  }
134 
140  public function getZone($index) {
141  $zone=null;
142  $nb=sizeof($this->navZones);
143  if (is_int($index)) {
144  if ($index<$nb)
145  $zone=$this->navZones [$index];
146  } else {
147  for($i=0; $i<$nb; $i++) {
148  if ($this->navZones [$i]->getIdentifier()===$index) {
149  $zone=$this->navZones [$i];
150  break;
151  }
152  }
153  }
154  return $zone;
155  }
156 
157  public function run(JsUtils $js) {
158  foreach ( $this->navZones as $zone ) {
159  $zone->run($js);
160  }
161  if ($this->hasScrollspy) {
162  $this->scrollspy=new Scrollspy($js);
163  $this->scrollspy->attach($this->scrollspyId);
164  $this->scrollspy->setTarget("#".$this->identifier);
165  $this->scrollspy->compile($js);
166  }
167  }
168 
169  public function cssInverse() {
170  $this->addToMember($this->class, CssNavbar::NAVBAR_INVERSE);
171  return $this;
172  }
173 
174  public function scrollspy($attachTo="body") {
175  $this->hasScrollspy=true;
176  $this->scrollspyId=$attachTo;
177  }
178 
179  public function setFluid($fluid) {
180  if($fluid===true){
181  $this->fluid="container-fluid";
182  }else{
183  $this->fluid="container";
184  }
185  return $this;
186  }
187 
188  /* (non-PHPdoc)
189  * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject()
190  */
191  public function fromDatabaseObject($object, $function) {
192  $this->addElement($function($object));
193  }
194 
195 }
BaseHtml for HTML components.
Definition: BaseHtml.php:17
Composant Twitter Bootstrap Scrollspy.
Definition: Scrollspy.php:13
Twitter Bootstrap HTML Navbar component.
Definition: HtmlNavbar.php:16
fromArray($array)
/* (non-PHPdoc)
Definition: HtmlNavbar.php:101
Inner element for Twitter Bootstrap HTML Navbar component.
Definition: HtmlNavzone.php:18
addZone($type="nav", $identifier=NULL)
adds a new zone of type $type
Definition: HtmlNavbar.php:74
fromDatabaseObject($object, $function)
Definition: HtmlNavbar.php:191
addElement($element, HtmlNavzone $zone=NULL)
Definition: HtmlNavbar.php:84
scrollspy($attachTo="body")
Definition: HtmlNavbar.php:174
addElements($elements, HtmlNavzone $zone=NULL)
Definition: HtmlNavbar.php:91
addToMember(&$name, $value, $separator=' ')
Definition: BaseHtml.php:99
JQuery PHP library.
Definition: JsUtils.php:23
Twitter Bootstrap HTML Dropdown component.
__construct($identifier, $brand="Brand", $brandHref="#")
Definition: HtmlNavbar.php:32