subformfield.class.inc.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Form;
  21. /**
  22. * Description of StringField
  23. *
  24. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  25. */
  26. class SubFormField extends Field
  27. {
  28. protected $oForm;
  29. public function __construct($sId, $sParentFormId, Closure $onFinalizeCallback = null)
  30. {
  31. $this->oForm = new Form($sParentFormId.'-subform_'.$sId);
  32. parent::__construct($sId, $onFinalizeCallback);
  33. }
  34. public function GetForm()
  35. {
  36. return $this->oForm;
  37. }
  38. /**
  39. * Checks the validators to see if the field's current value is valid.
  40. * Then sets $bValid and $aErrorMessages.
  41. *
  42. * @return boolean
  43. */
  44. public function Validate()
  45. {
  46. $this->oForm->Validate();
  47. }
  48. public function GetValid()
  49. {
  50. return $this->oForm->GetValid();
  51. }
  52. public function GetErrorMessages()
  53. {
  54. $aRet = array();
  55. foreach ($this->oForm->GetErrorMessages() as $sSubFieldId => $aSubFieldMessages)
  56. {
  57. $aRet[] = $sSubFieldId.': '.implode(', ', $aSubFieldMessages);
  58. }
  59. return $aRet;
  60. }
  61. public function GetCurrentValue()
  62. {
  63. return $this->oForm->GetCurrentValues();
  64. }
  65. public function SetCurrentValue($value)
  66. {
  67. return $this->oForm->SetCurrentValues($value);
  68. }
  69. }