PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/contentmanager/code/trunk/administrator/components/com_contentmanager/libraries/jxtended/form/field.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 149 lines | 72 code | 19 blank | 58 comment | 7 complexity | f2cd46372d48ab2de74aab3c4c49c94b MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: field.php 160 2009-07-09 00:06:09Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright (C) 2008 - 2009 JXtended, LLC. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://jxtended.com
  9. */
  10. defined('JPATH_BASE') or die;
  11. jximport2('joomla.utilities.simplexml');
  12. /**
  13. * Form Field Object
  14. *
  15. * @package JXtended.Libraries
  16. * @subpackage Forms
  17. */
  18. class JXFormField extends JSimpleXMLElement
  19. {
  20. function addOption($attrs=array(), $data='')
  21. {
  22. //If there is no array already set for the tag name being added,
  23. //create an empty array for it
  24. if(!isset($this->option))
  25. $this->option = array();
  26. //Create the child object itself
  27. $child = new JXFormField('option', $attrs, $this->_level + 1);
  28. $child->setData($data);
  29. //Add the reference of it to the end of an array member named for the elements name
  30. $this->option[] =& $child;
  31. //Add the reference to the children array member
  32. $this->_children[] =& $child;
  33. }
  34. function setData($data)
  35. {
  36. $this->_data = $data;
  37. }
  38. }
  39. /**
  40. * Form field type base class
  41. *
  42. * The base class for all JXField objects
  43. *
  44. * @abstract
  45. * @author Louis Landry <louis.landry@ivivio.com>
  46. * @package ivivio
  47. * @subpackage Forms
  48. * @since 1.5
  49. */
  50. class JXFieldType extends JObject
  51. {
  52. /**
  53. * Field type
  54. *
  55. * This has to be set in the final
  56. * renderer classes.
  57. *
  58. * @access protected
  59. * @var string
  60. */
  61. var $_type = null;
  62. /**
  63. * reference to the object that instantiated the element
  64. *
  65. * @access protected
  66. * @var object
  67. */
  68. var $_parent = null;
  69. /**
  70. * Constructor
  71. *
  72. * @access protected
  73. */
  74. function __construct($parent = null) {
  75. $this->_parent = $parent;
  76. }
  77. /**
  78. * Method to get the field type
  79. *
  80. * @access public
  81. * @return string field type
  82. */
  83. function getType() {
  84. return $this->_type;
  85. }
  86. function render(&$xmlElement, $value, $controlName = 'jxform')
  87. {
  88. $name = $xmlElement->attributes('name');
  89. $label = $xmlElement->attributes('label');
  90. $descr = $xmlElement->attributes('description');
  91. $reqd = $xmlElement->attributes('required');
  92. $access = $xmlElement->attributes('access');
  93. //make sure we have a valid label
  94. $label = $label ? $label : $name;
  95. $result = new JObject();
  96. $result->set('type', $this->_type);
  97. $result->set('label', $this->fetchLabel($label, $descr, $xmlElement, $controlName, $name));
  98. $result->set('field', $this->fetchField($name, $value, $xmlElement, $controlName));
  99. $result->set('name', $name);
  100. $result->set('value', $value);
  101. // @todo Create handlers to set the control name and id
  102. $result->set('control.name', $controlName.'['.$name.']');
  103. $result->set('control.id', str_replace(']', '', str_replace('[', '_', $controlName.'_'.$name)));
  104. $result->set('label.text', JText::_($label));
  105. $result->set('description.text', JText::_($descr));
  106. $result->set('decorator.type', $xmlElement->attributes('decorator'));
  107. $result->set('decorator.text', $xmlElement->attributes('decorator_text'));
  108. $result->set('decorator.options', $xmlElement->attributes('decorator_options'));
  109. $result->set('default', $xmlElement->attributes('default'));
  110. $result->set('default.access', (int)$xmlElement->attributes('default_access'));
  111. $result->set('required', (int)($reqd == 'true' OR $reqd == '1'));
  112. $result->set('access', (int)($access == 'true' OR $access == '1'));
  113. return $result;
  114. }
  115. function fetchLabel($label, $description, &$xmlElement, $controlName='', $name='')
  116. {
  117. $id = str_replace(']', '', str_replace('[', '_', $controlName.'_'.$name));
  118. if ($description) {
  119. $output = '<label id="'.$id.'-lbl" for="'.$id.'" class="hasTip" title="'.JText::_($label, true).'::'.JText::_($description, true).'">';
  120. } else {
  121. $output = '<label id="'.$id.'-lbl" for="'.$id.'">';
  122. }
  123. $output .= JText::_($label);
  124. $output .= '</label>';
  125. return $output;
  126. }
  127. function fetchField($name, $value, &$xmlElement, $controlName) {
  128. return;
  129. }
  130. }