/libraries/piwi/Widget/Container/Container.php

https://github.com/jaws-project/jaws · PHP · 245 lines · 99 code · 27 blank · 119 comment · 10 complexity · 9606f5269efe44ee9cc452543cd05b7b MD5 · raw file

  1. <?php
  2. /*
  3. * Container.php - Main Class for all container widgets
  4. *
  5. * @version $Id $
  6. * @author Pablo Fischer <pablo@pablo.com.mx>
  7. *
  8. * <c> Pablo Fischer 2004
  9. * <c> Piwi
  10. */
  11. define ('PIWI_INVALID_FILTER', -1);
  12. define ('PIWI_INVALID_FILTER_MESSAGE', 'Invalid filter passed');
  13. require_once PIWI_PATH . '/Widget/Widget.php';
  14. class Container extends Widget
  15. {
  16. /**
  17. * An array with all the items contained in the widget
  18. *
  19. * @var array $_items
  20. * @access private
  21. * @see add(), delete()
  22. *
  23. */
  24. var $_items;
  25. /**
  26. * Border of the container
  27. *
  28. * @var array $_border
  29. * @access private
  30. * @see setBorder(), getBorder()
  31. *
  32. */
  33. var $_border;
  34. /**
  35. * Direction of the box (horizontal or vertical)
  36. *
  37. * @var $_direction
  38. * @access private
  39. * @see getDirection()
  40. */
  41. var $_direction;
  42. /**
  43. * Flag to determinate if widget should get the child items with their titles
  44. *
  45. * @var boolean $_useTitles
  46. * @access private
  47. */
  48. var $_useTitles;
  49. /**
  50. * The submitted values
  51. *
  52. * @var mixed string/array the values passed
  53. * @access private
  54. */
  55. var $_submitValues;
  56. /**
  57. * Container Initializer
  58. *
  59. * @access private
  60. */
  61. function init()
  62. {
  63. $this->_items = array();
  64. $this->_packable = true;
  65. $this->_useTitles = false;
  66. $this->_familyWidget = 'container';
  67. parent::init();
  68. }
  69. /**
  70. * Add an item to the container
  71. *
  72. * @param object The item
  73. * @param string If you want to identify your item, you should give it a name
  74. * @access public
  75. */
  76. function add(&$item, $identifier = '')
  77. {
  78. if (!isset($item)) {
  79. return false;
  80. }
  81. if (empty($identifier)) {
  82. $this->_items[] = $item;
  83. } else {
  84. $this->_items[$identifier] = $item;
  85. }
  86. }
  87. /**
  88. * Delete an item from the container (only if you know the ID!)
  89. *
  90. * @param string The ID of the item
  91. * @access public
  92. */
  93. function delete($identifier)
  94. {
  95. unset($this->_items[$identifier]);
  96. }
  97. /**
  98. * Get the items
  99. *
  100. * @param string The ID of the item
  101. * @access public
  102. */
  103. function getItem($id)
  104. {
  105. return $this->_items[$id];
  106. }
  107. /**
  108. * Get the items
  109. *
  110. * @access public
  111. */
  112. function getItems()
  113. {
  114. return $this->_items;
  115. }
  116. /**
  117. * Set the border
  118. *
  119. * @param int $border Border
  120. * @access public
  121. */
  122. function setBorder($border)
  123. {
  124. $this->_border = $border;
  125. }
  126. /**
  127. * Get the border
  128. *
  129. * @access public
  130. */
  131. function getBorder()
  132. {
  133. return $this->_border;
  134. }
  135. /**
  136. * Get the direction
  137. *
  138. * @access public
  139. * @return string Direction of the box
  140. */
  141. function getDirection()
  142. {
  143. return $this->_direction;
  144. }
  145. /**
  146. * Set the direction
  147. *
  148. * @param int $direction The Direction
  149. * @access public
  150. */
  151. function setDirection($direction)
  152. {
  153. $this->_direction = $direction;
  154. }
  155. /**
  156. * Build the basic piwiXML data, adding container params
  157. *
  158. * @access private
  159. */
  160. function buildBasicPiwiXML()
  161. {
  162. parent::buildBasicPiwiXML();
  163. if (is_numeric($this->_border)) {
  164. $this->_PiwiXML->addAttribute('border', $this->_border);
  165. }
  166. }
  167. /**
  168. * Build the basix XHTML data - Adding Container params
  169. *
  170. * @access private
  171. * @return string XHTML data
  172. */
  173. function buildBasicXHTML()
  174. {
  175. $xhtml = '';
  176. if (is_numeric($this->_border)) {
  177. $xhtml .= " border=\"".$this->_border."px\"";
  178. }
  179. $xhtml .= parent::buildBasicXHTML();
  180. return $xhtml;
  181. }
  182. /**
  183. * Get the items with their titles
  184. *
  185. * @access public
  186. */
  187. function getItemsWithTitles()
  188. {
  189. $this->_useTitles = true;
  190. $this->rebuild();
  191. return $this->get();
  192. }
  193. /**
  194. * Get item validators
  195. *
  196. * @access public
  197. * @return string javascript code to validate
  198. */
  199. function getItemValidators()
  200. {
  201. $js = '';
  202. foreach ($this->_items as $item) {
  203. //hey.. some containers have the controls in a hash!
  204. if (isset($item) && is_array($item) && isset($item['control'])) {
  205. $item = $item['control'];
  206. }
  207. if ($item->isPackable()) {
  208. $js .= $item->getItemValidators();
  209. } else {
  210. $validators = $item->getValidators();
  211. foreach ($validators as $validator) {
  212. $js .= $validator->getCode();
  213. }
  214. }
  215. }
  216. return $js;
  217. }
  218. }