XOOPS  2.6.0
TabTray.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Form;
13 
25 class TabTray extends ElementTray
26 {
32  private $uiTheme = '';
33 
42  public function __construct($caption, $name, $uiTheme = 'base', $delimiter = "&nbsp;")
43  {
44  $this->setName($name);
45  $this->setCaption($caption);
46  $this->delimiter = $delimiter;
47  $this->uiTheme = $uiTheme;
48  }
49 
55  public function render()
56  {
58  $xoops->theme()->addBaseScriptAssets('@jquery');
59  $xoops->theme()->addBaseScriptAssets('@jqueryui');
60  $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
61  $xoops->theme()->addScript('', '', '$(function() { $("#tabs_' . $this->getName() . '").tabs(); });');
62 
63  $ret = '<div id="tabs_' . $this->getName() . '">' . NWLINE;
64  $ret .= '<ul>' . NWLINE;
65  foreach ($this->getElements() as $ele) {
66  if ($ele instanceof Tab) {
67  $ret .= '<li><a href="#tab_' . $ele->getName() . '"><span>'
68  . $ele->getCaption() . '</span></a></li>' . NWLINE;
69  }
70  }
71  $ret .= '</ul>' . NWLINE;
72 
73  $hidden = '';
74  $extras = array();
75 
76  foreach ($this->getElements() as $ele) {
77  /* @var $ele Element */
78  if (!$ele->isHidden()) {
79  if (!$ele instanceof Raw) {
80  if ($ele instanceof Tab) {
81  $ret .= '<div id="tab_' . $ele->getName() . '">' . NWLINE;
82  $ret .= '<table class="outer" cellspacing="1">' . NWLINE;
83  $ret .= $ele->render();
84  $ret .= '</table>' . NWLINE;
85  $ret .= '</div>' . NWLINE;
86  } else {
87  $extras[] = $ele;
88  }
89  } else {
90  $ret .= $ele->render();
91  }
92  } else {
93  $hidden .= $ele->render();
94  }
95  }
96  if (!empty($extras)) {
97  $tray = new ElementTray('', $this->getDelimiter());
98  foreach ($extras as $extra) {
99  $tray->addElement($extra);
100  }
101  $ret .= $tray->render();
102  $ret .= NWLINE;
103  }
104 
105  $ret .= $hidden . NWLINE;
106  $ret .= '</div>' . NWLINE;
107  return $ret;
108  }
109 }
static getInstance()
Definition: Xoops.php:160
setCaption($caption)
Definition: Element.php:396
__construct($caption, $name, $uiTheme= 'base', $delimiter="&nbsp;")
Definition: TabTray.php:42
$xoops
Definition: admin.php:25
getElements($recursively=false)
getDelimiter($encode=false)