selectobjectfield.class.inc.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // Copyright (C) 2010-2017 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. * @author Romain Quetiez <romain.quetiez@combodo.com>
  26. */
  27. class SelectObjectField extends Field
  28. {
  29. protected $oSearch;
  30. protected $iMaximumComboLength;
  31. protected $iMinAutoCompleteChars;
  32. protected $bHierarchical;
  33. protected $iControlType;
  34. protected $sSearchEndpoint;
  35. const CONTROL_SELECT = 1;
  36. const CONTROL_RADIO_VERTICAL = 2;
  37. public function __construct($sId, Closure $onFinalizeCallback = null)
  38. {
  39. parent::__construct($sId, $onFinalizeCallback);
  40. $this->oSearch = null;
  41. $this->iMaximumComboLength = null;
  42. $this->iMinAutoCompleteChars = 3;
  43. $this->bHierarchical = false;
  44. $this->iControlType = self::CONTROL_SELECT;
  45. $this->sSearchEndpoint = null;
  46. }
  47. public function SetSearch(DBSearch $oSearch)
  48. {
  49. $this->oSearch = $oSearch;
  50. return $this;
  51. }
  52. public function SetMaximumComboLength($iMaximumComboLength)
  53. {
  54. $this->iMaximumComboLength = $iMaximumComboLength;
  55. return $this;
  56. }
  57. public function SetMinAutoCompleteChars($iMinAutoCompleteChars)
  58. {
  59. $this->iMinAutoCompleteChars = $iMinAutoCompleteChars;
  60. return $this;
  61. }
  62. public function SetHierarchical($bHierarchical)
  63. {
  64. $this->bHierarchical = $bHierarchical;
  65. return $this;
  66. }
  67. public function SetControlType($iControlType)
  68. {
  69. $this->iControlType = $iControlType;
  70. }
  71. public function SetSearchEndpoint($sSearchEndpoint)
  72. {
  73. $this->sSearchEndpoint = $sSearchEndpoint;
  74. return $this;
  75. }
  76. /**
  77. * Sets if the field is mandatory or not.
  78. * Setting the value will automatically add/remove a MandatoryValidator to the Field
  79. *
  80. * @param boolean $bMandatory
  81. * @return \Combodo\iTop\Form\Field\Field
  82. */
  83. public function SetMandatory($bMandatory)
  84. {
  85. // Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator
  86. if ($bMandatory && !$this->bMandatory)
  87. {
  88. $this->AddValidator(new NotEmptyExtKeyValidator());
  89. }
  90. if (!$bMandatory)
  91. {
  92. foreach ($this->aValidators as $iKey => $oValue)
  93. {
  94. if ($oValue::Getname() === NotEmptyExtKeyValidator::GetName())
  95. {
  96. unset($this->aValidators[$iKey]);
  97. }
  98. }
  99. }
  100. $this->bMandatory = $bMandatory;
  101. return $this;
  102. }
  103. /**
  104. * @return \DBSearch
  105. */
  106. public function GetSearch()
  107. {
  108. return $this->oSearch;
  109. }
  110. public function GetMaximumComboLength()
  111. {
  112. return $this->iMaximumComboLength;
  113. }
  114. public function GetMinAutoCompleteChars()
  115. {
  116. return $this->iMinAutoCompleteChars;
  117. }
  118. public function GetHierarchical()
  119. {
  120. return $this->bHierarchical;
  121. }
  122. public function GetControlType()
  123. {
  124. return $this->iControlType;
  125. }
  126. public function GetSearchEndpoint()
  127. {
  128. return $this->sSearchEndpoint;
  129. }
  130. }