formmanager.class.inc.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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;
  19. use \Combodo\iTop\Form\Form;
  20. use \Combodo\iTop\Renderer\FormRenderer;
  21. /**
  22. * Description of formmanager
  23. *
  24. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  25. */
  26. abstract class FormManager
  27. {
  28. protected $oForm;
  29. protected $oRenderer;
  30. static function FromJSON($sJson)
  31. {
  32. // Overload in child class when needed
  33. $aJson = json_decode($sJson, true);
  34. $oFormManager = new static();
  35. $sFormRendererClass = $aJson['formrenderer_class'];
  36. $oFormRenderer = new $sFormRendererClass();
  37. $oFormRenderer->SetEndpoint($aJson['formrenderer_endpoint']);
  38. $oFormManager->SetRenderer($oFormRenderer);
  39. return $oFormManager;
  40. }
  41. public function __construct()
  42. {
  43. // Overload in child class when needed
  44. }
  45. public function GetForm()
  46. {
  47. return $this->oForm;
  48. }
  49. public function GetRenderer()
  50. {
  51. return $this->oRenderer;
  52. }
  53. public function SetRenderer(FormRenderer $oRenderer)
  54. {
  55. $this->oRenderer = $oRenderer;
  56. return $this;
  57. }
  58. public function GetClass()
  59. {
  60. return get_class($this);
  61. }
  62. public function ToJSON()
  63. {
  64. // Overload in child class when needed
  65. return array(
  66. 'id' => $this->oForm->GetId(),
  67. 'formmanager_class' => $this->GetClass(),
  68. 'formrenderer_class' => get_class($this->GetRenderer()),
  69. 'formrenderer_endpoint' => $this->GetRenderer()->GetEndpoint()
  70. );
  71. }
  72. abstract public function Build();
  73. abstract public function OnUpdate($aArgs = null);
  74. abstract public function OnSubmit($aArgs = null);
  75. abstract public function OnCancel($aArgs = null);
  76. }