subformfield.class.inc.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 SubFormField
  23. *
  24. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  25. */
  26. class SubFormField extends Field
  27. {
  28. protected $oForm;
  29. /**
  30. * Default constructor
  31. *
  32. * @param string $sId
  33. * @param string $sParentFormId
  34. * @param Closure $onFinalizeCallback
  35. */
  36. public function __construct($sId, $sParentFormId, Closure $onFinalizeCallback = null)
  37. {
  38. $this->oForm = new Form($sParentFormId.'-subform_'.$sId);
  39. parent::__construct($sId, $onFinalizeCallback);
  40. }
  41. /**
  42. *
  43. * @return \Combodo\iTop\Form\Form
  44. */
  45. public function GetForm()
  46. {
  47. return $this->oForm;
  48. }
  49. /**
  50. * Checks the validators to see if the field's current value is valid.
  51. * Then sets $bValid and $aErrorMessages.
  52. *
  53. * @return boolean
  54. */
  55. public function Validate()
  56. {
  57. return $this->oForm->Validate();
  58. }
  59. /**
  60. *
  61. * @return boolean
  62. */
  63. public function GetValid()
  64. {
  65. return $this->oForm->GetValid();
  66. }
  67. /**
  68. *
  69. * @return array
  70. */
  71. public function GetErrorMessages()
  72. {
  73. $aRet = array();
  74. foreach ($this->oForm->GetErrorMessages() as $sSubFieldId => $aSubFieldMessages)
  75. {
  76. $aRet[] = $sSubFieldId.': '.implode(', ', $aSubFieldMessages);
  77. }
  78. return $aRet;
  79. }
  80. /**
  81. *
  82. * @return array
  83. */
  84. public function GetCurrentValue()
  85. {
  86. return $this->oForm->GetCurrentValues();
  87. }
  88. /**
  89. *
  90. * @param array $value
  91. * @return \Combodo\iTop\Form\Field\SubFormField
  92. */
  93. public function SetCurrentValue($value)
  94. {
  95. $this->oForm->SetCurrentValues($value);
  96. return $this;
  97. }
  98. /**
  99. * @param $sFormPath
  100. * @return Form|null
  101. */
  102. public function FindSubForm($sFormPath)
  103. {
  104. return $this->oForm->FindSubForm($sFormPath);
  105. }
  106. }