1 | <?php |
||
18 | class HtmlNavzone extends BaseHtml { |
||
19 | protected $class="navbar-nav"; |
||
20 | protected $elements; |
||
21 | |||
22 | /** |
||
23 | * |
||
24 | * @param string $identifier the id |
||
25 | */ |
||
26 | public function __construct($identifier) { |
||
27 | parent::__construct($identifier); |
||
28 | $this->tagName="ul"; |
||
29 | $this->_template='<%tagName% id="%identifier%" class="nav navbar-nav %class%">%elements%</%tagName%>'; |
||
30 | $this->elements=array (); |
||
31 | } |
||
32 | |||
33 | public function setClass($value) { |
||
34 | $this->setMemberCtrl($this->class, $value, CssRef::navbarZoneClasses()); |
||
35 | } |
||
36 | |||
37 | public function asForm() { |
||
40 | |||
41 | public function addElement($element) { |
||
52 | |||
53 | public function setValues($class, $tagName, $elements=array()) { |
||
54 | $this->class=$class; |
||
55 | $this->tagName=$tagName; |
||
56 | $this->elements=$elements; |
||
57 | return $this; |
||
58 | } |
||
59 | |||
60 | public function addElements($elements) { |
||
61 | if (is_array($elements)) { |
||
62 | foreach ( $elements as $key => $element ) { |
||
63 | $iid=$this->getElementsCount()+1; |
||
64 | if ($element instanceof HtmlDropdownItem) |
||
65 | $this->elements []=$element; |
||
66 | else if (is_array($element)) { |
||
67 | if (is_string($key)===true) { |
||
68 | $dropdown=new HtmlDropdown($this->identifier."-dropdown-".$iid); |
||
69 | $dropdown->addItems($element); |
||
70 | $dropdown->setBtnCaption($key); |
||
71 | $dropdown->setMTagName("li"); |
||
72 | $this->addElement($dropdown); |
||
73 | } else { |
||
74 | $this->addLink(array_pop($element), array_pop($element)); |
||
75 | } |
||
76 | } else if (is_object($element)) { |
||
77 | $this->addElement($element); |
||
78 | } else if (is_string($element)) { |
||
79 | $this->addLink($element); |
||
80 | } |
||
81 | // TODO A vérifier |
||
82 | } |
||
83 | } |
||
84 | return $this; |
||
85 | } |
||
86 | |||
87 | public function addLink($caption, $href="#") { |
||
88 | $iid=$this->getElementsCount()+1; |
||
89 | $li=new HtmlBsDoubleElement($this->identifier."-li-".$iid, "li"); |
||
90 | if($caption instanceof HtmlLink){ |
||
91 | $link=$caption; |
||
92 | }else{ |
||
93 | $link=new HtmlLink($this->identifier."-link-".$iid, $href, $caption); |
||
94 | } |
||
95 | $li->setContent($link); |
||
96 | $this->addElement($li); |
||
97 | } |
||
98 | |||
99 | public static function form($identifier, $elements=array()) { |
||
100 | $result=new HtmlNavzone($identifier); |
||
101 | return $result->setValues("navbar-form navbar-left", "form", $elements); |
||
102 | } |
||
103 | |||
104 | public static function left($identifier, $elements=array()) { |
||
105 | $result=new HtmlNavzone($identifier); |
||
106 | return $result->setValues("navbar-left", "ul", $elements); |
||
107 | } |
||
108 | |||
109 | public static function right($identifier, $elements=array()) { |
||
110 | $result=new HtmlNavzone($identifier); |
||
111 | return $result->setValues("navbar-right", "ul", $elements); |
||
112 | } |
||
113 | |||
114 | public static function formRight($identifier, $elements=array()) { |
||
118 | |||
119 | public static function nav($identifier, $elements=array()) { |
||
120 | $result=new HtmlNavzone($identifier); |
||
121 | return $result->setValues("navbar-nav", "ul", $elements); |
||
122 | } |
||
123 | |||
124 | public function run(JsUtils $js) { |
||
125 | foreach ( $this->elements as $element ) { |
||
126 | $element->run($js); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | public function getElementsCount() { |
||
131 | return sizeof($this->elements); |
||
132 | } |
||
133 | |||
134 | public function fromArray($array) { |
||
135 | return $this->addElements($array); |
||
136 | } |
||
137 | |||
138 | public function __toString() { |
||
139 | return $this->compile(); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @param int $index |
||
144 | * @return BaseHtml |
||
145 | */ |
||
146 | public function getElement($index){ |
||
149 | } |