XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
formelementtray.php
Go to the documentation of this file.
1 <?php
21 defined('XOOPS_ROOT_PATH') or die('Restricted access');
22 
33  var $_elements = array();
34 
40  var $_required = array();
41 
49 
56  function XoopsFormElementTray( $caption, $delimeter = "&nbsp;", $name = "" ) {
57  $this->setName( $name );
58  $this->setCaption( $caption );
59  $this->_delimeter = $delimeter;
60  }
61 
67  function isContainer() {
68  return true;
69  }
70 
76  function isRequired() {
77  return !empty( $this->_required );
78  }
79 
85  function addElement( &$formElement, $required = false ) {
86  $this->_elements[] = $formElement;
87  if ( !$formElement->isContainer() ) {
88  if ( $required ) {
89  $formElement->_required = true;
90  $this->_required[] = $formElement;
91  }
92  } else {
93  $required_elements = $formElement->getRequired();
94  $count = count( $required_elements );
95  for ( $i = 0 ; $i < $count; $i++ ) {
96  $this->_required[] = &$required_elements[$i];
97  }
98  }
99  }
100 
106  function &getRequired() {
107  return $this->_required;
108  }
109 
116  function &getElements( $recurse = false ) {
117  if ( !$recurse ) {
118  return $this->_elements;
119  } else {
120  $ret = array();
121  $count = count( $this->_elements );
122  for ( $i = 0; $i < $count; $i++ ) {
123  if ( !$this->_elements[$i]->isContainer() ) {
124  $ret[] = &$this->_elements[$i];
125  } else {
126  $elements = &$this->_elements[$i]->getElements( true );
127  $count2 = count( $elements );
128  for ( $j = 0; $j < $count2; $j++ ) {
129  $ret[] = &$elements[$j];
130  }
131  unset( $elements );
132  }
133  }
134  return $ret;
135  }
136  }
137 
144  function getDelimeter( $encode = false ) {
145  return $encode ? htmlspecialchars( str_replace( '&nbsp;', ' ', $this->_delimeter ) ) : $this->_delimeter;
146  }
147 
153  function render() {
154  $count = 0;
155  $ret = "";
156  foreach ( $this->getElements() as $ele ) {
157  if ( $count > 0 ) {
158  $ret .= $this->getDelimeter();
159  }
160  if ( $ele->getCaption() != '' ) {
161  $ret .= $ele->getCaption() . "&nbsp;";
162  }
163  $ret .= $ele->render() . NWLINE ;
164  if ( !$ele->isHidden() ) {
165  $count++;
166  }
167  }
168  return $ret;
169  }
170 }
171 
172 ?>