1: <?php
2: // $Id: formelementtray.php,v 1.1 2007/05/15 02:34:42 minahito 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: if (!defined('XOOPS_ROOT_PATH')) exit();
33:
34: /**
35: *
36: *
37: * @package kernel
38: * @subpackage form
39: *
40: * @author Kazumi Ono <onokazu@xoops.org>
41: * @copyright copyright (c) 2000-2003 XOOPS.org
42: */
43:
44: /**
45: * A group of form elements
46: *
47: * @author Kazumi Ono <onokazu@xoops.org>
48: * @copyright copyright (c) 2000-2003 XOOPS.org
49: *
50: * @package kernel
51: * @subpackage form
52: */
53: class XoopsFormElementTray extends XoopsFormElement {
54:
55: /**
56: * array of form element objects
57: * @var array
58: * @access private
59: */
60: var $_elements = array();
61:
62: /**
63: * required elements
64: * @var array
65: */
66: var $_required = array();
67:
68: /**
69: * HTML to seperate the elements
70: * @var string
71: * @access private
72: */
73: var $_delimeter;
74:
75: /**
76: * constructor
77: *
78: * @param string $caption Caption for the group.
79: * @param string $delimiter HTML to separate the elements
80: */
81: function XoopsFormElementTray($caption, $delimeter=" ", $name=""){
82: $this->setName($name);
83: $this->setCaption($caption);
84: $this->_delimeter = $delimeter;
85: }
86:
87: /**
88: * Is this element a container of other elements?
89: *
90: * @return bool true
91: */
92: function isContainer()
93: {
94: return true;
95: }
96:
97: /**
98: * Add an element to the group
99: *
100: * @param object &$element {@link XoopsFormElement} to add
101: */
102: function addElement(&$formElement, $required=false){
103: $this->_elements[] =& $formElement;
104: if ($required) {
105: if (!$formElement->isContainer()) {
106: $this->_required[] =& $formElement;
107: } else {
108: $required_elements =& $formElement->getElements(true);
109: $count = count($required_elements);
110: for ($i = 0 ; $i < $count; $i++) {
111: $this->_required[] =& $required_elements[$i];
112: }
113: }
114: }
115: }
116:
117: /**
118: * get an array of "required" form elements
119: *
120: * @return array array of {@link XoopsFormElement}s
121: */
122: function &getRequired()
123: {
124: return $this->_required;
125: }
126:
127: /**
128: * Get an array of the elements in this group
129: *
130: * @param bool $recurse get elements recursively?
131: * @return array Array of {@link XoopsFormElement} objects.
132: */
133: function &getElements($recurse = false){
134: if (!$recurse) {
135: return $this->_elements;
136: } else {
137: $ret = array();
138: $count = count($this->_elements);
139: for ($i = 0; $i < $count; $i++) {
140: if (!$this->_elements[$i]->isContainer()) {
141: $ret[] =& $this->_elements[$i];
142: } else {
143: $elements =& $this->_elements[$i]->getElements(true);
144: $count2 = count($elements);
145: for ($j = 0; $j < $count2; $j++) {
146: $ret[] =& $elements[$j];
147: }
148: unset($elements);
149: }
150: }
151: return $ret;
152: }
153: }
154:
155: /**
156: * Get the delimiter of this group
157: *
158: * @return string The delimiter
159: */
160: function getDelimeter(){
161: return $this->_delimeter;
162: }
163:
164: /**
165: * prepare HTML to output this group
166: *
167: * @return string HTML output
168: */
169: function render(){
170: $root =& XCube_Root::getSingleton();
171: $renderSystem =& $root->getRenderSystem(XOOPSFORM_DEPENDENCE_RENDER_SYSTEM);
172:
173: $renderTarget =& $renderSystem->createRenderTarget('main');
174:
175: $renderTarget->setAttribute('legacy_module', 'legacy');
176: $renderTarget->setTemplateName("legacy_xoopsform_elementtray.html");
177: $renderTarget->setAttribute("tray", $this);
178:
179: $renderSystem->render($renderTarget);
180:
181: return $renderTarget->getResult();
182: }
183: }
184: ?>