. */ namespace SP\Modules\Web\Forms; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\ValidationException; use SP\DataModel\UserGroupData; /** * Class UserGroupForm * * @package SP\Modules\Web\Forms */ final class UserGroupForm extends FormBase implements FormInterface { /** * @var UserGroupData */ protected $groupData; /** * Validar el formulario * * @param $action * * @return bool * @throws \SP\Core\Exceptions\ValidationException */ public function validate($action) { switch ($action) { case ActionsInterface::GROUP_CREATE: case ActionsInterface::GROUP_EDIT: $this->analyzeRequestData(); $this->checkCommon(); break; } return true; } /** * Analizar los datos de la petición HTTP * * @return void */ protected function analyzeRequestData() { $this->groupData = new UserGroupData(); $this->groupData->setId($this->itemId); $this->groupData->setName($this->request->analyzeString('name')); $this->groupData->setDescription($this->request->analyzeString('description')); $this->groupData->setUsers($this->request->analyzeArray('users')); } /** * @throws ValidationException */ protected function checkCommon() { if (!$this->groupData->getName()) { throw new ValidationException(__u('Es necesario un nombre de grupo')); } } /** * @return UserGroupData */ public function getItemData() { return $this->groupData; } }