. */ namespace SP\Modules\Web\Controllers\UserProfile; use Exception; use JsonException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; /** * Class SaveEditController */ final class SaveEditController extends UserProfileSaveBase { use ItemTrait; use JsonTrait; /** * Saves edit action * * @param int $id * * @return bool * @throws JsonException */ public function saveEditAction(int $id): bool { try { if (!$this->acl->checkUserAccess(AclActionsInterface::PROFILE_EDIT)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(AclActionsInterface::PROFILE_EDIT, $id); $profileData = $this->form->getItemData(); $this->userProfileService->update($profileData); $this->eventDispatcher->notify( 'edit.userProfile', new Event( $this, EventMessage::build() ->addDescription(__u('Profile updated')) ->addDetail(__u('Name'), $profileData->getName()) ->addExtra('userProfileId', $id) ) ); $this->updateCustomFieldsForItem(AclActionsInterface::PROFILE, $id, $this->request, $this->customFieldService); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Profile updated')); } catch (ValidationException $e) { return $this->returnJsonResponseException($e); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }