selectobjectfield.class.inc.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Form\Field;
  19. use \Closure;
  20. use \DBSearch;
  21. use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
  22. /**
  23. * Description of SelectObjectField
  24. *
  25. */
  26. class SelectObjectField extends Field
  27. {
  28. protected $oSearch;
  29. protected $iMaximumComboLength;
  30. protected $iMinAutoCompleteChars;
  31. protected $iControlType;
  32. const CONTROL_SELECT = 1;
  33. const CONTROL_RADIO_VERTICAL = 2;
  34. public function __construct($sId, Closure $onFinalizeCallback = null)
  35. {
  36. parent::__construct($sId, $onFinalizeCallback);
  37. $this->oSearch = null;
  38. $this->iMaximumComboLength = null;
  39. $this->iMinAutoCompleteChars = 3;
  40. $this->iControlType = self::CONTROL_SELECT;
  41. }
  42. public function SetSearch(DBSearch $oSearch)
  43. {
  44. $this->oSearch = $oSearch;
  45. }
  46. public function SetMaximumComboLength($iMaximumComboLength)
  47. {
  48. $this->iMaximumComboLength = $iMaximumComboLength;
  49. }
  50. public function SetMinAutoCompleteChars($iMinAutoCompleteChars)
  51. {
  52. $this->iMinAutoCompleteChars = $iMinAutoCompleteChars;
  53. }
  54. public function SetControlType($iControlType)
  55. {
  56. $this->iControlType = $iControlType;
  57. }
  58. /**
  59. * Sets if the field is mandatory or not.
  60. * Setting the value will automatically add/remove a MandatoryValidator to the Field
  61. *
  62. * @param boolean $bMandatory
  63. * @return \Combodo\iTop\Form\Field\Field
  64. */
  65. public function SetMandatory($bMandatory)
  66. {
  67. // Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator
  68. if ($bMandatory && !$this->bMandatory)
  69. {
  70. $this->AddValidator(new NotEmptyExtKeyValidator());
  71. }
  72. if (!$bMandatory)
  73. {
  74. foreach ($this->aValidators as $iKey => $oValue)
  75. {
  76. if ($oValue::Getname() === NotEmptyExtKeyValidator::GetName())
  77. {
  78. unset($this->aValidators[$iKey]);
  79. }
  80. }
  81. }
  82. $this->bMandatory = $bMandatory;
  83. return $this;
  84. }
  85. public function GetSearch()
  86. {
  87. return $this->oSearch;
  88. }
  89. public function GetMaximumComboLength()
  90. {
  91. return $this->iMaximumComboLength;
  92. }
  93. public function GetMinAutoCompleteChars()
  94. {
  95. return $this->iMinAutoCompleteChars;
  96. }
  97. public function GetControlType()
  98. {
  99. return $this->iControlType;
  100. }
  101. }