. */ namespace SP\Forms; use SP\Core\ActionsInterface; use SP\Core\Exceptions\ValidationException; use SP\DataModel\CustomerData; use SP\Http\Request; /** * Class CustomerForm * * @package SP\Forms */ class CustomerForm extends FormBase implements FormInterface { /** * @var CustomerData */ protected $CustomerData; /** * Validar el formulario * * @param $action * @return bool * @throws \SP\Core\Exceptions\ValidationException */ public function validate($action) { switch ($action) { case ActionsInterface::ACTION_MGM_CUSTOMERS_NEW: case ActionsInterface::ACTION_MGM_CUSTOMERS_EDIT: $this->checkCommon(); break; } return true; } /** * @throws ValidationException */ protected function checkCommon() { if (!$this->CustomerData->getCustomerName()) { throw new ValidationException(__('Es necesario un nombre de cliente', false)); } } /** * @return CustomerData */ public function getItemData() { return $this->CustomerData; } /** * Analizar los datos de la petición HTTP * * @return void */ protected function analyzeRequestData() { $this->CustomerData = new CustomerData(); $this->CustomerData->setCustomerId($this->itemId); $this->CustomerData->setCustomerName(Request::analyze('name')); $this->CustomerData->setCustomerDescription(Request::analyze('description')); } }