phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlTab.php
Go to the documentation of this file.
1<?php
3
11
20
21 protected $params = [];
22
23 protected $_activated = false;
24
25 public function __construct($identifier, $tabs = array()) {
26 parent::__construct($identifier, "div", "");
27 $menu = new HtmlMenu("menu" . $this->identifier);
28 $menu->asTab(false)->setAttachment(NULL, Side::TOP);
29 $this->content["menu"] = $menu;
30 $this->addItems($tabs);
31 }
32
33 public function getMenu(){
34 return $this->content['menu'];
35 }
36
43 protected function createItem($value) {
44 $count = $this->count();
45 $title = $value;
46 $content = NULL;
47 if (\is_array($value)) {
48 $title = @$value[0];
49 $content = @$value[1];
50 }
51 $menuItem = $this->content["menu"]->addItem($title);
52 $menuItem->addToProperty("data-tab", $menuItem->getIdentifier());
53 $menuItem->removeProperty("href");
54 $result = $this->createSegment($count, $content, $menuItem->getIdentifier());
55 $result->menuTab = $menuItem;
56 return $result;
57 }
58
66 private function createSegment($count, $content, $datatab) {
67 $segment = new HtmlSegment("item-" . $this->identifier . "-" . $count, $content);
68 $segment->setAttachment(NULL, Side::BOTTOM)
69 ->addToProperty("class", "tab")
70 ->addToProperty("data-tab", $datatab);
71 return $segment;
72 }
73
83 public function setTabContent($index, $content) {
84 $menu = $this->content["menu"];
85 if ($index < $menu->count()) {
86 if (isset($this->content[$index]) === false) {
87 $this->content[$index] = $this->createSegment($index, $content, $menu->getItem($index)
88 ->getIdentifier());
89 } else
90 $this->content[$index]->setContent($content);
91 }
92 return $this;
93 }
94
101 public function setTabsContent($contents) {
102 $size = \sizeof($contents);
103 for ($i = 0; $i < $size; $i ++) {
104 $this->setTabContent($i, $contents[$i]);
105 }
106 return $this;
107 }
108
115 public function activate($index) {
116 $item = $this->content["menu"]->getItem($index);
117 if ($item != null) {
118 $item->setActive(true);
119 $this->content[$index]->setActive(true);
120 $this->_activated = true;
121 }
122 return $this;
123 }
124
132 public function addTab($title, $content) {
133 return $this->addItem([
134 $title,
136 ]);
137 }
138
154 public function forwardTab($index, JsUtils $js, $title, $initialController, $controller, $action, $params = array()) {
155 if (\array_key_exists($index, $this->content)) {
156 $this->content[$index] = $js->forward($initialController, $controller, $action, $params);
157 return $this->content[$index];
158 }
159
160 return $this->addAndForwardTab($js, $title, $initialController, $controller, $action, $params);
161 }
162
177 public function renderViewTab($index, JsUtils $js, $title, $initialController, $viewName, $params = array()) {
178 if (\array_key_exists($index, $this->content)) {
179 $this->content[$index] = $js->renderContent($initialController, $viewName, $params);
180 return $this->content[$index];
181 }
182 return $this->addAndRenderViewTab($js, $title, $initialController, $viewName, $params);
183 }
184
199 public function addAndForwardTab(JsUtils $js, $title, $initialController, $controller, $action, $params = array()) {
200 \ob_start();
201 $js->forward($initialController, $controller, $action, $params);
202 $content = \ob_get_clean();
203 return $this->addTab($title, $content);
204 }
205
218 public function addAndRenderViewTab(JsUtils $js, $title, $initialController, $viewName, $params = array()) {
219 return $this->addTab($title, $js->renderContent($initialController, $viewName, $params));
220 }
221
222 public function setPointing($value = Direction::NONE) {
223 return $this->content["menu"]->setPointing($value);
224 }
225
226 public function setSecondary() {
227 return $this->content["menu"]->setSecondary();
228 }
229
236 public function getMenuTab($index) {
237 return $this->content["menu"]->getItem($index);
238 }
239
246 public function getTab($index) {
247 return $this->content[$index];
248 }
249
256 public function setMenu($menu) {
257 $contentSize = \sizeof($this->content);
258 for ($i = 0; $i < $contentSize; $i ++) {
259 if ($menu->getItem($i) !== NULL) {
260 if (isset($this->content[$i])) {
261 $menu->getItem($i)->addToProperty("data-tab", $this->content[$i]->getProperty("data-tab"));
262 }
263 }
264 }
265 $menuSize = $menu->count();
266 for ($i = 0; $i < $menuSize; $i ++) {
267 $menu->getItem($i)->removeProperty("href");
268 if (isset($this->content[$i]) === false) {
269 $this->content[$i] = $this->createSegment($i, "New content", $menu->getItem($i)
270 ->getIdentifier());
271 }
272 $menu->getItem($i)->addToProperty("data-tab", $this->content[$i]->getProperty("data-tab"));
273 }
274
275 $this->content["menu"] = $menu;
276 return $this;
277 }
278
279 /*
280 * (non-PHPdoc)
281 * @see BaseHtml::run()
282 */
283 public function run(JsUtils $js) {
284 if (isset($this->_bsComponent) === false)
285 $this->_bsComponent = $js->semantic()->tab("#" . $this->identifier . " .item", $this->params);
286 $this->addEventsOnRun($js);
287 return $this->_bsComponent;
288 }
289
290 public function compile(JsUtils $js = NULL, &$view = NULL) {
291 if (! $this->_activated && $this->content["menu"]->count() > 0 && \sizeof($this->content) > 1)
292 $this->activate(0);
293 return parent::compile($js, $view);
294 }
295
296 public function setInverted($recursive=true){
297 parent::setInverted($recursive);
298 $this->content['menu']->addClass('inverted');
299 }
300}
JQuery PHP library.
Definition JsUtils.php:23
forward($initialController, $controller, $action, $params)
Forwards to.
renderContent($initialControllerInstance, $viewName, $params=NULL)
render the content of an existing view : $viewName and set the response to the modal content Used int...
semantic(Semantic $semantic=NULL)
getter or setter of the Semantic-UI variable
Definition JsUtils.php:158
addItem($item)
adds and returns an item
Base class for Semantic Html collections.
Semantic Tab component.
Definition HtmlTab.php:19
setPointing($value=Direction::NONE)
Definition HtmlTab.php:222
setTabsContent($contents)
Sets all contents of tabs.
Definition HtmlTab.php:101
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\Bas...
Definition HtmlTab.php:283
getTab($index)
Returns the tab at position $index.
Definition HtmlTab.php:246
createItem($value)
{The item factory.}
Definition HtmlTab.php:43
forwardTab($index, JsUtils $js, $title, $initialController, $controller, $action, $params=array())
Renders the content of.
Definition HtmlTab.php:154
renderViewTab($index, JsUtils $js, $title, $initialController, $viewName, $params=array())
Renders the content of an existing view : $controller/$action and sets the response to the tab at $in...
Definition HtmlTab.php:177
setMenu($menu)
Sets the menu of tabs.
Definition HtmlTab.php:256
setInverted($recursive=true)
can be formatted to appear on dark backgrounds
Definition HtmlTab.php:296
addAndRenderViewTab(JsUtils $js, $title, $initialController, $viewName, $params=array())
render the content of an existing view : $controller/$action and set the response to a new tab
Definition HtmlTab.php:218
setTabContent($index, $content)
Sets the content of the tab at position $index.
Definition HtmlTab.php:83
compile(JsUtils $js=NULL, &$view=NULL)
Definition HtmlTab.php:290
addAndForwardTab(JsUtils $js, $title, $initialController, $controller, $action, $params=array())
render the content of
Definition HtmlTab.php:199
__construct($identifier, $tabs=array())
Definition HtmlTab.php:25
activate($index)
Activates the tab element at $index.
Definition HtmlTab.php:115
addTab($title, $content)
Adds a new tab.
Definition HtmlTab.php:132
getMenuTab($index)
Returns the menu item at position $index.
Definition HtmlTab.php:236
createSegment($count, $content, $datatab)
Definition HtmlTab.php:66