PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/content/code/trunk/administrator/components/com_artofcontent/libraries/jxtended/form/fields/list.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 102 lines | 54 code | 11 blank | 37 comment | 11 complexity | 33ad38a2d18f28f62ae3d0741f48811b MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: list.php 484 2010-12-20 23:40:27Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License
  8. * @link http://www.theartofjoomla.com
  9. */
  10. defined('JPATH_BASE') or die('Restricted Access');
  11. jimport('joomla.html.html');
  12. juimport('jxtended.form.formfield');
  13. /**
  14. * Form Field class for JXtended Libraries.
  15. *
  16. * @package JXtended.Libraries
  17. * @subpackage Form
  18. * @since 1.1
  19. */
  20. class JFormFieldList extends JFormField
  21. {
  22. /**
  23. * The field type.
  24. *
  25. * @var string
  26. */
  27. protected $type = 'List';
  28. /**
  29. * Method to get a list of options for a list input.
  30. *
  31. * @return array An array of JHtml options.
  32. */
  33. protected function _getOptions()
  34. {
  35. $options = array();
  36. // Iterate through the children and build an array of options.
  37. foreach ($this->_element->children() as $option) {
  38. $options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option->data())));
  39. }
  40. return $options;
  41. }
  42. /**
  43. * Method to get the field input.
  44. *
  45. * @return string The field input.
  46. */
  47. protected function _getInput()
  48. {
  49. $disabled = $this->_element->attributes('disabled') == 'true' ? true : false;
  50. $readonly = $this->_element->attributes('readonly') == 'true' ? true : false;
  51. $attributes = ' ';
  52. if ($v = $this->_element->attributes('size')) {
  53. $attributes .= 'size="'.$v.'"';
  54. }
  55. if ($v = $this->_element->attributes('class')) {
  56. $attributes .= 'class="'.$v.'"';
  57. }
  58. else {
  59. $attributes .= 'class="inputbox"';
  60. }
  61. if ($m = $this->_element->attributes('multiple'))
  62. {
  63. $attributes .= 'multiple="multiple"';
  64. }
  65. if ($disabled || $readonly) {
  66. $attributes .= ' disabled="disabled"';
  67. }
  68. $options = (array)$this->_getOptions();
  69. $return = null;
  70. // Handle a disabled list.
  71. if ($disabled)
  72. {
  73. // Create a disabled list.
  74. $return .= JHtml::_('select.genericlist', $options, $this->inputName, $attributes, 'value', 'text', $this->value, $this->inputId);
  75. }
  76. // Handle a read only list.
  77. else if ($readonly)
  78. {
  79. // Create a disabled list with a hidden input to store the value.
  80. $return .= JHtml::_('select.genericlist', $options, '', $attributes, 'value', 'text', $this->value, $this->inputId);
  81. $return .= '<input type="hidden" name="'.$this->inputName.'" value="'.$this->value.'" />';
  82. }
  83. // Handle a regular list.
  84. else
  85. {
  86. // Create a regular list.
  87. $return = JHtml::_('select.genericlist', $options, $this->inputName, $attributes, 'value', 'text', $this->value, $this->inputId);
  88. }
  89. return $return;
  90. }
  91. }