123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- // Copyright (C) 2010-2016 Combodo SARL
- //
- // This file is part of iTop.
- //
- // iTop is free software; you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // iTop is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with iTop. If not, see <http://www.gnu.org/licenses/>
- namespace Combodo\iTop\Form;
- use \Combodo\iTop\Form\Form;
- use \Combodo\iTop\Renderer\FormRenderer;
- /**
- * Description of formmanager
- *
- * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
- */
- abstract class FormManager
- {
- protected $oForm;
- protected $oRenderer;
- /**
- * Creates an instance of \Combodo\iTop\Form\FormManager from JSON data that must contain at least :
- * - formrenderer_class : The class of the FormRenderer to use in the FormManager
- * - formrenderer_endpoint : The endpoint of the renderer
- *
- * @param string $sJson
- * @return \Combodo\iTop\Form\FormManager
- */
- static function FromJSON($sJson)
- {
- // Overload in child class when needed
- $aJson = json_decode($sJson, true);
- $oFormManager = new static();
- $sFormRendererClass = $aJson['formrenderer_class'];
- $oFormRenderer = new $sFormRendererClass();
- $oFormRenderer->SetEndpoint($aJson['formrenderer_endpoint']);
- $oFormManager->SetRenderer($oFormRenderer);
- return $oFormManager;
- }
- public function __construct()
- {
- // Overload in child class when needed
- }
- /**
- *
- * @return \Combodo\iTop\Form\Form
- */
- public function GetForm()
- {
- return $this->oForm;
- }
- /**
- *
- * @param \Combodo\iTop\Form\Form $oForm
- * @return \Combodo\iTop\Form\FormManager
- */
- public function SetForm(Form $oForm)
- {
- $this->oForm = $oForm;
- return $this;
- }
- /**
- *
- * @return \Combodo\iTop\Renderer\FormRenderer
- */
- public function GetRenderer()
- {
- return $this->oRenderer;
- }
- /**
- *
- * @param \Combodo\iTop\Renderer\FormRenderer $oRenderer
- * @return \Combodo\iTop\Form\FormManager
- */
- public function SetRenderer(FormRenderer $oRenderer)
- {
- $this->oRenderer = $oRenderer;
- return $this;
- }
- /**
- *
- * @return string
- */
- public function GetClass()
- {
- return get_class($this);
- }
- /**
- * Creates a JSON string from the current object including :
- * - id : Id of the current Form
- * - formmanager_class
- * - formrenderer_class
- * - formrenderer_endpoint
- *
- * @return string
- */
- public function ToJSON()
- {
- // Overload in child class when needed
- return array(
- 'id' => $this->oForm->GetId(),
- 'formmanager_class' => $this->GetClass(),
- 'formrenderer_class' => get_class($this->GetRenderer()),
- 'formrenderer_endpoint' => $this->GetRenderer()->GetEndpoint()
- );
- }
- abstract public function Build();
- abstract public function OnUpdate($aArgs = null);
- abstract public function OnSubmit($aArgs = null);
- abstract public function OnCancel($aArgs = null);
- }
|