. */ namespace SP\Modules\Web\Forms; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\ProfileData; use SP\DataModel\UserProfileData; use SP\Domain\Core\Acl\AclActionsInterface; /** * Class UserProfileForm * * @package SP\Modules\Web\Forms */ final class UserProfileForm extends FormBase implements FormInterface { protected ?UserProfileData $userProfileData = null; /** * Validar el formulario * * @param int $action * @param int|null $id * * @return UserProfileForm|FormInterface * @throws ValidationException */ public function validateFor(int $action, ?int $id = null): FormInterface { if ($id !== null) { $this->itemId = $id; } switch ($action) { case AclActionsInterface::PROFILE_CREATE: case AclActionsInterface::PROFILE_EDIT: $this->analyzeRequestData(); $this->checkCommon(); break; } return $this; } /** * Analizar los datos de la petición HTTP * * @return void */ protected function analyzeRequestData(): void { $profileData = $this->getProfileDataFromRequest(); $this->userProfileData = new UserProfileData(); $this->userProfileData->setName($this->request->analyzeString('profile_name')); $this->userProfileData->setId($this->itemId); $this->userProfileData->setProfile($profileData); } /** * @return ProfileData */ private function getProfileDataFromRequest(): ProfileData { $profileData = new ProfileData(); $profileData->setAccAdd($this->request->analyzeBool('profile_accadd', false)); $profileData->setAccView($this->request->analyzeBool('profile_accview', false)); $profileData->setAccViewPass($this->request->analyzeBool('profile_accviewpass', false)); $profileData->setAccViewHistory($this->request->analyzeBool('profile_accviewhistory', false)); $profileData->setAccEdit($this->request->analyzeBool('profile_accedit', false)); $profileData->setAccEditPass($this->request->analyzeBool('profile_acceditpass', false)); $profileData->setAccDelete($this->request->analyzeBool('profile_accdel', false)); $profileData->setAccFiles($this->request->analyzeBool('profile_accfiles', false)); $profileData->setAccPublicLinks($this->request->analyzeBool('profile_accpublinks', false)); $profileData->setAccPrivate($this->request->analyzeBool('profile_accprivate', false)); $profileData->setAccPrivateGroup($this->request->analyzeBool('profile_accprivategroup', false)); $profileData->setAccPermission($this->request->analyzeBool('profile_accpermissions', false)); $profileData->setAccGlobalSearch($this->request->analyzeBool('profile_accglobalsearch', false)); $profileData->setConfigGeneral($this->request->analyzeBool('profile_config', false)); $profileData->setConfigEncryption($this->request->analyzeBool('profile_configmpw', false)); $profileData->setConfigBackup($this->request->analyzeBool('profile_configback', false)); $profileData->setConfigImport($this->request->analyzeBool('profile_configimport', false)); $profileData->setMgmCategories($this->request->analyzeBool('profile_categories', false)); $profileData->setMgmCustomers($this->request->analyzeBool('profile_customers', false)); $profileData->setMgmCustomFields($this->request->analyzeBool('profile_customfields', false)); $profileData->setMgmUsers($this->request->analyzeBool('profile_users', false)); $profileData->setMgmGroups($this->request->analyzeBool('profile_groups', false)); $profileData->setMgmProfiles($this->request->analyzeBool('profile_profiles', false)); $profileData->setMgmApiTokens($this->request->analyzeBool('profile_apitokens', false)); $profileData->setMgmPublicLinks($this->request->analyzeBool('profile_publinks', false)); $profileData->setMgmAccounts($this->request->analyzeBool('profile_accounts', false)); $profileData->setMgmFiles($this->request->analyzeBool('profile_files', false)); $profileData->setMgmItemsPreset($this->request->analyzeBool('profile_items_preset', false)); $profileData->setMgmTags($this->request->analyzeBool('profile_tags', false)); $profileData->setEvl($this->request->analyzeBool('profile_eventlog', false)); return $profileData; } /** * @throws ValidationException */ protected function checkCommon(): void { if (!$this->userProfileData->getName()) { throw new ValidationException(__u('A profile name is needed')); } } /** * @throws SPException */ public function getItemData(): UserProfileData { if (null === $this->userProfileData) { throw new SPException(__u('Profile data not set')); } return $this->userProfileData; } }