. */ namespace SP\Forms; use SP\Core\ActionsInterface; use SP\Core\Exceptions\ValidationException; use SP\DataModel\GroupData; use SP\Http\Request; /** * Class GroupForm * * @package SP\Forms */ class GroupForm extends FormBase implements FormInterface { /** * @var GroupData */ protected $GroupData; /** * Validar el formulario * * @param $action * @return bool * @throws \SP\Core\Exceptions\ValidationException */ public function validate($action) { switch ($action) { case ActionsInterface::ACTION_USR_GROUPS_NEW: case ActionsInterface::ACTION_USR_GROUPS_EDIT: $this->analyzeRequestData(); $this->checkCommon(); break; } return true; } /** * Analizar los datos de la petición HTTP * * @return void */ protected function analyzeRequestData() { $this->GroupData = new GroupData(); $this->GroupData->setUsergroupId($this->itemId); $this->GroupData->setUsergroupName(Request::analyze('name')); $this->GroupData->setUsergroupDescription(Request::analyze('description')); $this->GroupData->setUsers(Request::analyze('users', 0)); } /** * @throws ValidationException */ protected function checkCommon() { if (!$this->GroupData->getUsergroupName()) { throw new ValidationException(__('Es necesario un nombre de grupo', false)); } } /** * @return GroupData */ public function getItemData() { return $this->GroupData; } }