selectobjectfield.class.inc.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
  21. /**
  22. * Description of SelectObjectField
  23. *
  24. */
  25. class SelectObjectField extends Field
  26. {
  27. protected $sOqlQuery;
  28. protected $iMaximumComboLength;
  29. protected $iMinAutoCompleteChars;
  30. public function __construct($sId, Closure $onFinalizeCallback = null)
  31. {
  32. parent::__construct($sId, $onFinalizeCallback);
  33. $this->sOqlQuery = null;
  34. $this->iMaximumComboLength = null;
  35. $this->iMinAutoCompleteChars = 3;
  36. }
  37. public function SetOqlQuery($sOqlQuery)
  38. {
  39. $this->sOqlQuery = $sOqlQuery;
  40. }
  41. public function SetMaximumComboLength($iMaximumComboLength)
  42. {
  43. $this->iMaximumComboLength = $iMaximumComboLength;
  44. }
  45. public function SetMinAutoCompleteChars($iMinAutoCompleteChars)
  46. {
  47. $this->iMinAutoCompleteChars = $iMinAutoCompleteChars;
  48. }
  49. /**
  50. * Sets if the field is mandatory or not.
  51. * Setting the value will automatically add/remove a MandatoryValidator to the Field
  52. *
  53. * @param boolean $bMandatory
  54. * @return \Combodo\iTop\Form\Field\Field
  55. */
  56. public function SetMandatory($bMandatory)
  57. {
  58. // Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator
  59. if ($bMandatory && !$this->bMandatory)
  60. {
  61. $this->AddValidator(new NotEmptyExtKeyValidator());
  62. }
  63. if (!$bMandatory)
  64. {
  65. foreach ($this->aValidators as $iKey => $oValue)
  66. {
  67. if ($oValue::Getname() === NotEmptyExtKeyValidator::GetName())
  68. {
  69. unset($this->aValidators[$iKey]);
  70. }
  71. }
  72. }
  73. $this->bMandatory = $bMandatory;
  74. return $this;
  75. }
  76. public function GetOqlQuery()
  77. {
  78. return $this->sOqlQuery;
  79. }
  80. public function GetMaximumComboLength()
  81. {
  82. return $this->iMaximumComboLength;
  83. }
  84. public function GetMinAutoCompleteChars()
  85. {
  86. return $this->iMinAutoCompleteChars;
  87. }
  88. }