| 1 | <?php |
|---|
| 2 | // $Id: formelementtray.php,v 1.2 2005/03/18 12:51:55 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | // Author: Kazumi Ono (AKA onokazu) // |
|---|
| 28 | // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // |
|---|
| 29 | // Project: The XOOPS Project // |
|---|
| 30 | // ------------------------------------------------------------------------- // |
|---|
| 31 | /** |
|---|
| 32 | * |
|---|
| 33 | * |
|---|
| 34 | * @package kernel |
|---|
| 35 | * @subpackage form |
|---|
| 36 | * |
|---|
| 37 | * @author Kazumi Ono <[email protected]> |
|---|
| 38 | * @copyright copyright (c) 2000-2003 XOOPS.org |
|---|
| 39 | */ |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * A group of form elements |
|---|
| 43 | * |
|---|
| 44 | * @author Kazumi Ono <[email protected]> |
|---|
| 45 | * @copyright copyright (c) 2000-2003 XOOPS.org |
|---|
| 46 | * |
|---|
| 47 | * @package kernel |
|---|
| 48 | * @subpackage form |
|---|
| 49 | */ |
|---|
| 50 | class XoopsFormElementTray extends XoopsFormElement { |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * array of form element objects |
|---|
| 54 | * @var array |
|---|
| 55 | * @access private |
|---|
| 56 | */ |
|---|
| 57 | var $_elements = array(); |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * required elements |
|---|
| 61 | * @var array |
|---|
| 62 | */ |
|---|
| 63 | var $_required = array(); |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * HTML to seperate the elements |
|---|
| 67 | * @var string |
|---|
| 68 | * @access private |
|---|
| 69 | */ |
|---|
| 70 | var $_delimeter; |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | * constructor |
|---|
| 74 | * |
|---|
| 75 | * @param string $caption Caption for the group. |
|---|
| 76 | * @param string $delimiter HTML to separate the elements |
|---|
| 77 | */ |
|---|
| 78 | function XoopsFormElementTray($caption, $delimeter=" ", $name=""){ |
|---|
| 79 | $this->setName($name); |
|---|
| 80 | $this->setCaption($caption); |
|---|
| 81 | $this->_delimeter = $delimeter; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Is this element a container of other elements? |
|---|
| 86 | * |
|---|
| 87 | * @return bool true |
|---|
| 88 | */ |
|---|
| 89 | function isContainer() |
|---|
| 90 | { |
|---|
| 91 | return true; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Add an element to the group |
|---|
| 96 | * |
|---|
| 97 | * @param object &$element {@link XoopsFormElement} to add |
|---|
| 98 | */ |
|---|
| 99 | function addElement(&$formElement, $required=false){ |
|---|
| 100 | $this->_elements[] =& $formElement; |
|---|
| 101 | if ($required) { |
|---|
| 102 | if (!$formElement->isContainer()) { |
|---|
| 103 | $this->_required[] =& $formElement; |
|---|
| 104 | } else { |
|---|
| 105 | $required_elements =& $formElement->getElements(true); |
|---|
| 106 | $count = count($required_elements); |
|---|
| 107 | for ($i = 0 ; $i < $count; $i++) { |
|---|
| 108 | $this->_required[] =& $required_elements[$i]; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * get an array of "required" form elements |
|---|
| 116 | * |
|---|
| 117 | * @return array array of {@link XoopsFormElement}s |
|---|
| 118 | */ |
|---|
| 119 | function &getRequired() |
|---|
| 120 | { |
|---|
| 121 | return $this->_required; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | /** |
|---|
| 125 | * Get an array of the elements in this group |
|---|
| 126 | * |
|---|
| 127 | * @param bool $recurse get elements recursively? |
|---|
| 128 | * @return array Array of {@link XoopsFormElement} objects. |
|---|
| 129 | */ |
|---|
| 130 | function &getElements($recurse = false){ |
|---|
| 131 | if (!$recurse) { |
|---|
| 132 | return $this->_elements; |
|---|
| 133 | } else { |
|---|
| 134 | $ret = array(); |
|---|
| 135 | $count = count($this->_elements); |
|---|
| 136 | for ($i = 0; $i < $count; $i++) { |
|---|
| 137 | if (!$this->_elements[$i]->isContainer()) { |
|---|
| 138 | $ret[] =& $this->_elements[$i]; |
|---|
| 139 | } else { |
|---|
| 140 | $elements =& $this->_elements[$i]->getElements(true); |
|---|
| 141 | $count2 = count($elements); |
|---|
| 142 | for ($j = 0; $j < $count2; $j++) { |
|---|
| 143 | $ret[] =& $elements[$j]; |
|---|
| 144 | } |
|---|
| 145 | unset($elements); |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | return $ret; |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | /** |
|---|
| 153 | * Get the delimiter of this group |
|---|
| 154 | * |
|---|
| 155 | * @return string The delimiter |
|---|
| 156 | */ |
|---|
| 157 | function getDelimeter(){ |
|---|
| 158 | return $this->_delimeter; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | /** |
|---|
| 162 | * prepare HTML to output this group |
|---|
| 163 | * |
|---|
| 164 | * @return string HTML output |
|---|
| 165 | */ |
|---|
| 166 | function render(){ |
|---|
| 167 | $count = 0; |
|---|
| 168 | $ret = ""; |
|---|
| 169 | foreach ( $this->getElements() as $ele ) { |
|---|
| 170 | if ($count > 0) { |
|---|
| 171 | $ret .= $this->getDelimeter(); |
|---|
| 172 | } |
|---|
| 173 | if ($ele->getCaption() != '') { |
|---|
| 174 | $ret .= $ele->getCaption()." "; |
|---|
| 175 | } |
|---|
| 176 | $ret .= $ele->render()."\n"; |
|---|
| 177 | if (!$ele->isHidden()) { |
|---|
| 178 | $count++; |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | return $ret; |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | ?> |
|---|