. */ namespace SP\Modules\Web\Controllers\UserProfile; use Exception; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; /** * Class DeleteController */ final class DeleteController extends UserProfileSaveBase { use JsonTrait, ItemTrait; /** * Delete action * * @param int|null $id * * @return bool * @throws \JsonException */ public function deleteAction(?int $id = null): bool { try { if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_DELETE)) { return $this->returnJsonResponse( JsonResponse::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } if ($id === null) { $this->userProfileService->deleteByIdBatch($this->getItemsIdFromRequest($this->request)); $this->eventDispatcher->notify( 'delete.userProfile.selection', new Event($this, EventMessage::factory()->addDescription(__u('Profiles deleted'))) ); $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id, $this->customFieldService); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Profiles deleted')); } $this->userProfileService->delete($id); $this->eventDispatcher->notify( 'delete.userProfile', new Event( $this, EventMessage::factory() ->addDescription(__u('Profile deleted')) ->addDetail(__u('Profile'), $id) ->addExtra('userProfileId', $id) ) ); $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id, $this->customFieldService); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Profile deleted')); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }