vendor/uvdesk/core-framework/Controller/GroupXHR.php line 23

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Symfony\Component\DependencyInjection\ContainerInterface;
  9. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportGroup;
  10. class GroupXHR extends AbstractController
  11. {
  12.     private $userService;
  13.     private $translator;
  14.     public function __construct(UserService $userServiceTranslatorInterface $translator)
  15.     {
  16.         $this->userService $userService;
  17.         $this->translator $translator;
  18.     }
  19.     public function listGroupsXHR(Request $requestContainerInterface $container)
  20.     {
  21.         if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_GROUP')) {
  22.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  23.         }
  24.         if (true === $request->isXmlHttpRequest()) {
  25.             $paginationResponse $this->getDoctrine()->getRepository(SupportGroup::class)->getAllGroups($request->query$container);
  26.             return new Response(json_encode($paginationResponse), 200, ['Content-Type' => 'application/json']);
  27.         }
  28.         
  29.         return new Response(json_encode([]), 404, ['Content-Type' => 'application/json']);
  30.     }
  31.     public function deleteGroupXHR($supportGroupId)
  32.     {
  33.         if(!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_GROUP')) {          
  34.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  35.         }
  36.         $request $this->get('request_stack')->getCurrentRequest();
  37.         if ($request->getMethod() == "DELETE") {
  38.             $entityManager $this->getDoctrine()->getManager();
  39.             $supportGroup $entityManager->getRepository(SupportGroup::class)->findOneById($supportGroupId);
  40.             if (!empty($supportGroup)) {
  41.                 $entityManager->remove($supportGroup);
  42.                 $entityManager->flush();
  43.                 
  44.                 return new Response(json_encode([
  45.                     'alertClass' => 'success',
  46.                     'alertMessage' => 'Support Group removed successfully.',
  47.                 ]), 200, ['Content-Type' => 'application/json']);
  48.             }
  49.         }
  50.         
  51.         return new Response(json_encode([]), 404, ['Content-Type' => 'application/json']);
  52.     }
  53. }