PageRenderTime 89ms CodeModel.GetById 49ms RepoModel.GetById 1ms app.codeStats 0ms

/source/endeleza/form/fields/list.php

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