vendor/uvdesk/api-bundle/API/Tickets.php line 294

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\ApiBundle\API;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8. use Symfony\Component\EventDispatcher\GenericEvent;
  9. use Symfony\Component\Serializer\Serializer;
  10. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  11. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  12. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Attachment;
  15. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportGroup;
  16. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportLabel;
  17. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportRole;
  18. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportTeam;
  19. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  20. use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketPriority;
  21. use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketStatus;
  22. use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketType;
  23. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  24. use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
  25. use Webkul\UVDesk\CoreFrameworkBundle\Services\UVDeskService;
  26. class Tickets extends AbstractController
  27. {
  28.     /**
  29.      * Return support tickets.
  30.      *
  31.      * @param Request $request
  32.      */
  33.     public function fetchTickets(Request $requestContainerInterface $containerUVDeskService $uvdesk)
  34.     {
  35.         $json = [];
  36.         $entityManager $this->getDoctrine()->getManager();
  37.         
  38.         $ticketRepository $this->getDoctrine()->getRepository(Ticket::class);
  39.         $userRepository $this->getDoctrine()->getRepository(User::class);
  40.         if ($request->query->get('actAsType')) {    
  41.             switch($request->query->get('actAsType')) {
  42.                 case 'customer'
  43.                     $email $request->query->get('actAsEmail');
  44.                     $customer $entityManager->getRepository(User::class)->findOneByEmail($email);
  45.                     if ($customer) {
  46.                         $json $ticketRepository->getAllCustomerTickets($request->query$container$customer);
  47.                     } else {
  48.                         $json['error'] = $container->get('translator')->trans('Error! Resource not found.');
  49.                         return new JsonResponse($jsonResponse::HTTP_NOT_FOUND);
  50.                     }
  51.                     return new JsonResponse($json);
  52.                 case 'agent':
  53.                     $email $request->query->get('actAsEmail');
  54.                     $user $entityManager->getRepository(User::class)->findOneByEmail($email);
  55.                     
  56.                     if ($user) {
  57.                         $request->query->set('agent'$user->getId());
  58.                     } else {
  59.                         $json['error'] = $container->get('translator')->trans('Error! Resource not found.');
  60.                         return new JsonResponse($jsonResponse::HTTP_NOT_FOUND);
  61.                     }
  62.                     break;
  63.                 default:
  64.                     $json['error'] = $container->get('translator')->trans('Error! invalid actAs details.');
  65.                     return new JsonResponse($jsonResponse::HTTP_BAD_REQUEST);
  66.             }
  67.         }
  68.         $json $ticketRepository->getAllTickets($request->query$container);
  69.         $collection $json['tickets'];
  70.         $pagination $json['pagination'];
  71.         // Resolve asset paths
  72.         $defaultAgentProfileImagePath $this->getParameter('assets_default_agent_profile_image_path');
  73.         $defaultCustomerProfileImagePath $this->getParameter('assets_default_customer_profile_image_path');
  74.         $user $this->getUser();
  75.         $userInstance $user->getCurrentInstance();
  76.         $currentUserDetails = [
  77.             'id' => $user->getId(), 
  78.             'email' => $user->getEmail(), 
  79.             'name' => $user->getFirstName() . ' ' $user->getLastname(), 
  80.             'profileImagePath' => $uvdesk->generateCompleteLocalResourcePathUri($userInstance->getProfileImagePath() ?? $defaultAgentProfileImagePath)
  81.         ];
  82.         foreach ($collection as $index => $ticket) {
  83.             // Resolve assets: Assigned agent
  84.             if (!empty($ticket['agent'])) {
  85.                 $profileImagePath $uvdesk->generateCompleteLocalResourcePathUri($ticket['agent']['profileImagePath'] ?? $defaultAgentProfileImagePath);
  86.                 $smallThumbnailPath $uvdesk->generateCompleteLocalResourcePathUri($ticket['agent']['smallThumbnail'] ?? $defaultAgentProfileImagePath);
  87.                 $collection[$index]['agent']['profileImagePath'] = $profileImagePath;
  88.                 $collection[$index]['agent']['smallThumbnail'] = $smallThumbnailPath;
  89.             }
  90.             // Resolve assets: Customer
  91.             if (!empty($ticket['customer'])) {
  92.                 $profileImagePath $uvdesk->generateCompleteLocalResourcePathUri($ticket['customer']['profileImagePath'] ?? $defaultCustomerProfileImagePath);
  93.                 $smallThumbnailPath $uvdesk->generateCompleteLocalResourcePathUri($ticket['customer']['smallThumbnail'] ?? $defaultCustomerProfileImagePath);
  94.                 $collection[$index]['customer']['profileImagePath'] = $profileImagePath;
  95.                 $collection[$index]['customer']['smallThumbnail'] = $smallThumbnailPath;
  96.             }
  97.         }
  98.         // Available helpdesk agents collection
  99.         $agents $container->get('user.service')->getAgentsPartialDetails();
  100.         return new JsonResponse([
  101.             'tickets' => $collection
  102.             'pagination' => $pagination
  103.             'userDetails' => $currentUserDetails
  104.             'agents' => $agents
  105.             'status' => $container->get('ticket.service')->getStatus(), 
  106.             'group' => $userRepository->getSupportGroups(), 
  107.             'team' =>  $userRepository->getSupportTeams(), 
  108.             'priority' => $container->get('ticket.service')->getPriorities(), 
  109.             'type' => $container->get('ticket.service')->getTypes(), 
  110.             'source' => $container->get('ticket.service')->getAllSources(), 
  111.         ]);
  112.         return new JsonResponse($json);
  113.     }
  114.     /**
  115.      * Return support tickets metadata.
  116.      *
  117.      * @param Request $request
  118.      */
  119.     public function fetchTicketsMetadata(Request $request
  120.     {
  121.         return new JsonResponse([]);
  122.     }
  123.     /**
  124.      * Trash support tickets.
  125.      *
  126.      * @param Request $request
  127.      * @return void
  128.      */
  129.     public function trashTicket(Request $requestContainerInterface $container)
  130.     {
  131.         $ticketId $request->attributes->get('ticketId');
  132.         $entityManager $this->getDoctrine()->getManager();
  133.         $ticket $entityManager->getRepository(Ticket::class)->find($ticketId);
  134.         
  135.         if (!$ticket) {
  136.             throw new NotFoundHttpException('Page Not Found');
  137.         }
  138.         if (!$ticket->getIsTrashed()) {
  139.             $ticket->setIsTrashed(1);
  140.             $entityManager->persist($ticket);
  141.             $entityManager->flush();
  142.             $json['success'] = $container->get('translator')->trans('Success ! Ticket moved to trash successfully.');
  143.             $statusCode Response::HTTP_OK;
  144.             // Trigger ticket delete event
  145.             $event = new CoreWorkflowEvents\Ticket\Delete();
  146.             $event
  147.                 ->setTicket($ticket)
  148.             ;
  149.             $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  150.         } else {
  151.             $json['error'] = $container->get('translator')->trans('Warning ! Ticket is already in trash.');
  152.             $statusCode Response::HTTP_BAD_REQUEST;
  153.         }
  154.         return new JsonResponse($json$statusCode);
  155.     }
  156.     /**
  157.      * Create support tickets.
  158.      *
  159.      * @param Request $request
  160.      * @return void
  161.      */
  162.     public function createTicket(Request $requestContainerInterface $container)
  163.     {
  164.         $data $request->request->all()? : json_decode($request->getContent(),true);
  165.         foreach($data as $key => $value) {
  166.             if(!in_array($key, ['subject''group''type''status','locale','domain''priority''agent''replies''createdAt''updatedAt''customFields''files''from''name''message''tags''actAsType''actAsEmail','agent_id'])) {
  167.                 unset($data[$key]);
  168.             }
  169.         }
  170.   
  171.         if(!(isset($data['from']) && isset($data['name']) && isset($data['subject']) && isset($data['message']) &&  isset($data['actAsType']) || isset($data['actAsEmail']) )) {
  172.             $json['error'] = $container->get('translator')->trans('required fields: name ,from, message, actAsType or actAsEmail');
  173.             return new JsonResponse($jsonResponse::HTTP_BAD_REQUEST);
  174.         }
  175.         if($data) {
  176.             $error false;
  177.             $message '';
  178.             $entityManager $this->getDoctrine()->getManager();
  179.             if ($data['subject'] == '') {
  180.                 $message $container->get('translator')->trans("Warning! Please complete subject field value!");
  181.                 $statusCode Response::HTTP_BAD_REQUEST;
  182.             } elseif($data['message'] == '') {
  183.                 $json['message'] = $container->get('translator')->trans("Warning! Please complete message field value!");
  184.                 $statusCode Response::HTTP_BAD_REQUEST;
  185.             } elseif(filter_var($data['from'], FILTER_VALIDATE_EMAIL) === false) {
  186.                 $json['message'] = $container->get('translator')->trans("Warning! Invalid from Email Address!");
  187.                 $statusCode Response::HTTP_BAD_REQUEST;
  188.             }
  189.             elseif ($data['actAsType'] == ''  &&  $data['actAsEmail'] == '') {
  190.                 $json['message'] = $container->get('translator')->trans("Warning! Provide atleast one parameter actAsType(agent or customer) or actAsEmail");
  191.                 $statusCode Response::HTTP_BAD_REQUEST;
  192.             }
  193.             
  194.             if (!$error) {
  195.                 $name explode(' ',$data['name']);
  196.                 $ticketData['firstName'] = $name[0];
  197.                 $ticketData['lastName'] = isset($name[1]) ? $name[1] : '';
  198.                 $ticketData['role'] = 4;
  199.              
  200.                 if ((array_key_exists('actAsType'$data)) && strtolower($data['actAsType']) == 'customer') {
  201.                     $actAsType strtolower($data['actAsType']);             
  202.                 } else if((array_key_exists('actAsEmail'$data)) && strtolower($data['actAsType']) == 'agent') {
  203.                     $user $entityManager->getRepository(User::class)->findOneByEmail($data['actAsEmail']);
  204.                     
  205.                     if ($user) {
  206.                         $actAsType 'agent';
  207.                     } else {
  208.                         $json['error'] = $container->get('translator')->trans("Error ! actAsEmail is not valid");
  209.                         return new JsonResponse($jsonResponse::HTTP_BAD_REQUEST);
  210.                     }
  211.                 } else {
  212.                     $json['warning'] = $container->get('translator')->trans('Warning ! For Customer specify actAsType as customer and for Agent specify both parameter actASType  as agent and actAsEmail as agent email');
  213.                     $statusCode Response::HTTP_BAD_REQUEST;
  214.                     return new JsonResponse($json$statusCode);
  215.                 }
  216.                 
  217.                 // Create customer if account does not exists
  218.                 $customer $entityManager->getRepository(User::class)->findOneByEmail($data['from']);
  219.              
  220.                 if (empty($customer) || null == $customer->getCustomerInstance()) {
  221.                     $role $entityManager->getRepository(SupportRole::class)->findOneByCode('ROLE_CUSTOMER');
  222.                   
  223.                     // Create User Instance
  224.                     $customer $container->get('user.service')->createUserInstance($data['from'], $data['name'], $role, [
  225.                         'source' => 'api',
  226.                         'active' => true
  227.                     ]);
  228.                 }
  229.                 if ($actAsType == 'agent') {
  230.                     $data['user'] = isset($user) && $user $user $container->get('user.service')->getCurrentUser();
  231.                 } else {
  232.                     $data['user'] = $customer;
  233.                 }
  234.                 $attachments $request->files->get('attachments');
  235.                 if (!empty($attachments)) {
  236.                         $attachments is_array($attachments) ? $attachments : [$attachments];
  237.                 }
  238.                 
  239.                 $ticketData['user'] = $data['user'];
  240.                 $ticketData['subject'] = $data['subject'];
  241.                 $ticketData['message'] = $data['message'];
  242.                 $ticketData['customer'] = $customer;
  243.                 $ticketData['source'] = 'api';
  244.                 $ticketData['threadType'] = 'create';
  245.                 $ticketData['createdBy'] = $actAsType;
  246.                 $ticketData['attachments'] = $attachments;
  247.                 
  248.                 $extraKeys = ['tags''group''priority''status''agent''createdAt''updatedAt'];
  249.                 if (array_key_exists('type'$data)) {
  250.                     $ticketType $entityManager->getRepository(TicketType::class)->findOneByCode($data['type']);
  251.                     $ticketData['type'] = $ticketType;
  252.                 }
  253.                 
  254.                 $requestData $data;
  255.                 foreach ($extraKeys as $key) {
  256.                     if (isset($ticketData[$key])) {
  257.                         unset($ticketData[$key]);
  258.                     }
  259.                 }
  260.                 
  261.                 $thread $container->get('ticket.service')->createTicketBase($ticketData);
  262.                 // Trigger ticket created event
  263.                 try {
  264.                     $event = new CoreWorkflowEvents\Ticket\Create();
  265.                     $event
  266.                         ->setTicket($thread->getTicket())
  267.                     ;
  268.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  269.                     if (isset($data['agent_id']) && !empty($data['agent_id'])) {
  270.                     $UserID $data['agent_id'];
  271.                     $entityManager $this->getDoctrine()->getManager();
  272.                     $ticket $entityManager->getRepository(Ticket::class)->findOneById($thread->getTicket()->getId());
  273.                     $agent $entityManager->getRepository(User::class)->find($UserID);
  274.                         if ($agent) {
  275.                             $ticket->setAgent($agent);
  276.                             $entityManager->persist($ticket);
  277.                             $entityManager->flush();
  278.                         }
  279.                      }
  280.                 } catch (\Exception $e) {
  281.                     //
  282.                 }
  283.                 $json['message'] = $container->get('translator')->trans('Success ! Ticket has been created successfully.');
  284.                 $json['ticketId'] = $thread->getTicket()->getId();
  285.                 $statusCode Response::HTTP_OK;
  286.                 $file_notification =  $container->get('uvdesk.core.file_system.service');
  287.                 $file_notification->sendFembuddyNotification($thread->getTicket()->getId(),$thread->getId(),'create');
  288.             } else {
  289.                 $json['message'] = $container->get('translator')->trans('Warning ! Required parameters should not be blank');
  290.                 $statusCode Response::HTTP_BAD_REQUEST;
  291.             }
  292.         } else {
  293.             $json['error'] = $container->get('translator')->trans('invalid/empty size of Request');
  294.             $json['message'] = $container->get('translator')->trans('Warning ! Post size can not exceed 25MB');
  295.             $statusCode Response::HTTP_BAD_REQUEST;
  296.         }
  297.         return new JsonResponse($json$statusCode);
  298.     }
  299.     /**
  300.      * View support tickets.
  301.      *
  302.      * @param Request $request
  303.      * @return void
  304.      */
  305.     public function viewTicket($ticketIdRequest $requestContainerInterface $containerUVDeskService $uvdesk)
  306.     {
  307.         $entityManager $this->getDoctrine()->getManager();
  308.         $userRepository $entityManager->getRepository(User::class);
  309.         $ticketRepository $entityManager->getRepository(Ticket::class);
  310.         $ticket $ticketRepository->findOneById($ticketId);
  311.         if (empty($ticket)) {
  312.             throw new \Exception('Page not found');
  313.         }
  314.         $user $this->getUser();
  315.         $userInstance $user->getCurrentInstance();
  316.         $agent $ticket->getAgent();
  317.         $customer $ticket->getCustomer();
  318.         $defaultAgentProfileImagePath $this->getParameter('assets_default_agent_profile_image_path');
  319.         $defaultCustomerProfileImagePath $this->getParameter('assets_default_customer_profile_image_path');
  320.         $agentDetails = !empty($agent) ? $agent->getAgentInstance()->getPartialDetails() : null;
  321.         $customerDetails $customer->getCustomerInstance()->getPartialDetails();
  322.         if (!empty($agentDetails)) {
  323.             $agentDetails['thumbnail'] = $uvdesk->generateCompleteLocalResourcePathUri($agentDetails['thumbnail'] ?? $defaultAgentProfileImagePath);
  324.         }
  325.         if (!empty($agentDetails)) {
  326.             $customerDetails['thumbnail'] = $uvdesk->generateCompleteLocalResourcePathUri($customerDetails['thumbnail'] ?? $defaultCustomerProfileImagePath);
  327.         }
  328.         // Mark as viewed by agents
  329.         if (false == $ticket->getIsAgentViewed()) {
  330.             $ticket
  331.                 ->setIsAgentViewed(true)
  332.             ;
  333.             $entityManager->persist($ticket);
  334.             $entityManager->flush();
  335.         }
  336.         // Ticket status Collection
  337.         $status array_map(function ($statusCollection) {
  338.             return [
  339.                 'id' => $statusCollection->getId(),
  340.                 'code' => $statusCollection->getCode(),
  341.                 'colorCode' => $statusCollection->getColorCode(),
  342.                 'description' => $statusCollection->getDescription(),
  343.             ];
  344.         }, $entityManager->getRepository(TicketStatus::class)->findAll());
  345.         // Ticket Type Collection
  346.         $type array_map(function ($ticketTypeCollection) {
  347.             return [
  348.                 'id' => $ticketTypeCollection->getId(),
  349.                 'code' => $ticketTypeCollection->getCode(),
  350.                 'isActive' => $ticketTypeCollection->getIsActive(),
  351.                 'description' => $ticketTypeCollection->getDescription(),
  352.             ];
  353.         }, $entityManager->getRepository(TicketType::class)->findByIsActive(true));
  354.         // Priority Collection
  355.         $priority array_map(function ($ticketPriorityCollection) {
  356.             return [
  357.                 'id' => $ticketPriorityCollection->getId(),
  358.                 'code' => $ticketPriorityCollection->getCode(),
  359.                 'colorCode' => $ticketPriorityCollection->getColorCode(),
  360.                 'description' => $ticketPriorityCollection->getDescription(),
  361.             ];
  362.         }, $entityManager->getRepository(TicketPriority::class)->findAll());
  363.       
  364.         $userService $container->get('user.service');
  365.         $fileSystemService =  $container->get('uvdesk.core.file_system.service');
  366.         $supportGroup $ticket->getSupportGroup();
  367.         if (!empty($supportGroup)) {
  368.             $supportGroup = [
  369.                 'id' => $supportGroup->getId(), 
  370.                 'name' => $supportGroup->getName(), 
  371.             ];
  372.         }
  373.         $supportTeam $ticket->getSupportTeam();
  374.         if (!empty($supportTeam)) {
  375.             $supportTeam = [
  376.                 'id' => $supportTeam->getId(), 
  377.                 'name' => $supportTeam->getName(), 
  378.             ];
  379.         }
  380.         $ticketDetails = [
  381.             'id' => $ticket->getId(), 
  382.             'source' => $ticket->getSource(), 
  383.             'priority' => $ticket->getPriority()->getId(), 
  384.             'status' => $ticket->getStatus()->getId(), 
  385.             'subject' => $ticket->getSubject(), 
  386.             'isNew' => $ticket->getIsNew(), 
  387.             'isReplied' => $ticket->getIsReplied(), 
  388.             'isReplyEnabled' => $ticket->getIsReplyEnabled(), 
  389.             'isStarred' => $ticket->getIsStarred(), 
  390.             'isTrashed' => $ticket->getIsTrashed(), 
  391.             'isAgentViewed' => $ticket->getIsAgentViewed(), 
  392.             'isCustomerViewed' => $ticket->getIsCustomerViewed(), 
  393.             'createdAt' => $userService->getLocalizedFormattedTime($ticket->getCreatedAt(), $user), 
  394.             'updatedAt' => $userService->getLocalizedFormattedTime($ticket->getUpdatedAt(), $user), 
  395.             'group' => $supportGroup
  396.             'team' => $supportTeam
  397.         ];
  398.         $threads array_map(function ($thread) use ($uvdesk$userService$fileSystemService$defaultAgentProfileImagePath$defaultCustomerProfileImagePath) {
  399.             $user $thread->getUser();
  400.             $userInstance $thread->getCreatedBy() == 'agent' $user->getAgentInstance() : $user->getCustomerInstance();
  401.             $attachments array_map(function ($attachment) use ($fileSystemService) {
  402.                 return $fileSystemService->getFileTypeAssociations($attachment);
  403.             }, $thread->getAttachments()->getValues());
  404.             $thumbnail $uvdesk->generateCompleteLocalResourcePathUri($userInstance->getProfileImagePath() ?? ($thread->getCreatedBy() == 'agent' $defaultAgentProfileImagePath $defaultCustomerProfileImagePath));
  405.             return [
  406.                 'id' => $thread->getId(), 
  407.                 'source' => $thread->getSource(), 
  408.                 'threadType' => $thread->getThreadType(), 
  409.                 'createdBy' => $thread->getCreatedBy(), 
  410.                 'cc' => $thread->getCc(), 
  411.                 'bcc' => $thread->getBcc(), 
  412.                 'isLocked' => $thread->getIsLocked(), 
  413.                 'isBookmarked' => $thread->getIsBookmarked(), 
  414.                 'message' => $thread->getMessage(), 
  415.                 'source' => $thread->getSource(), 
  416.                 'createdAt' => $userService->getLocalizedFormattedTime($thread->getCreatedAt(), $user), 
  417.                 'updatedAt' => $userService->getLocalizedFormattedTime($thread->getUpdatedAt(), $user), 
  418.                 'user' => [
  419.                     'id' => $user->getId(), 
  420.                     'name' => $user->getFullName(), 
  421.                     'email' => $user->getEmail(), 
  422.                     'thumbnail' => $thumbnail
  423.                 ], 
  424.                 'attachments' => $attachments,
  425.             ];
  426.         }, $ticket->getThreads()->getValues());
  427.         $ticketDetails['threads'] = $threads;
  428.         $ticketDetails['agent'] = $agentDetails;
  429.         $ticketDetails['customer'] = $customerDetails;
  430.         $ticketDetails['totalThreads'] = count($threads);
  431.         
  432.         return new JsonResponse([
  433.             'ticket' => $ticketDetails,
  434.             'totalCustomerTickets' => ($ticketRepository->countCustomerTotalTickets($customer$container)),
  435.             'supportGroups' => $userRepository->getSupportGroups(),
  436.             'supportTeams' => $userRepository->getSupportTeams(),
  437.             'ticketStatuses' => $status,
  438.             'ticketPriorities' => $priority,
  439.             'ticketTypes' => $type
  440.         ]);
  441.     }
  442.     /**
  443.      * delete support tickets.
  444.      *
  445.      * @param Request $request
  446.      * @return void
  447.      */
  448.     public function deleteTicketForever(Request $requestContainerInterface $container)
  449.     {
  450.         $ticketId $request->attributes->get('ticketId');
  451.         $entityManager $this->getDoctrine()->getManager();
  452.         $ticket $entityManager->getRepository(Ticket::class)->find($ticketId);
  453.         
  454.         if (!$ticket) {
  455.             throw new NotFoundHttpException('Page Not Found');
  456.         }
  457.         if ($ticket->getIsTrashed()) {
  458.             $entityManager->remove($ticket);
  459.             $entityManager->flush();
  460.             $json['success'] = $container->get('translator')->trans('Success ! Ticket removed successfully.');
  461.             $statusCode Response::HTTP_OK;
  462.             // Trigger ticket delete event
  463.             $event = new CoreWorkflowEvents\Ticket\Delete();
  464.             $event
  465.                 ->setTicket($ticket)
  466.             ;
  467.             $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  468.         } else {
  469.             $json['error'] = $container->get('translator')->trans('Warning ! something went wrong.');
  470.             $statusCode Response::HTTP_BAD_REQUEST;
  471.         }
  472.         return new JsonResponse($json$statusCode);
  473.     }
  474.     /**
  475.      * Assign Ticket to a agent
  476.      *
  477.      * @param Request $request
  478.      * @return void
  479.     */
  480.     public function assignAgent(Request $requestContainerInterface $container)
  481.     {
  482.         $json = [];
  483.         $data $request->request->all() ? :json_decode($request->getContent(), true);
  484.         $ticketId $request->attributes->get('ticketId');
  485.         $entityManager $this->getDoctrine()->getManager();
  486.         $ticket $entityManager->getRepository(Ticket::class)->findOneBy(array('id' => $ticketId));
  487.     
  488.         if ($ticket) {
  489.             if (isset($data['id'])) {
  490.                 $agent $entityManager->getRepository(User::class)->find($data['id']);
  491.             } else {
  492.                 $json['error'] = $container->get('translator')->trans('missing fields');   
  493.                 $json['description'] = $container->get('translator')->trans('required: id ');     
  494.                 return new JsonResponse($jsonResponse::HTTP_BAD_REQUEST);   
  495.             }
  496.            
  497.             if ($agent) {
  498.                 if($ticket->getAgent() != $agent) {
  499.                     $ticket->setAgent($agent);
  500.                     $entityManager->persist($ticket);
  501.                     $entityManager->flush();
  502.                     $json['success'] = $container->get('translator')->trans('Success ! Ticket assigned to agent successfully.');
  503.                     $statusCode Response::HTTP_OK;
  504.         
  505.                     // Trigger ticket delete event
  506.                     $event = new CoreWorkflowEvents\Ticket\Agent();
  507.                     $event
  508.                         ->setTicket($ticket)
  509.                     ;
  510.         
  511.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  512.                     
  513.                 } else {
  514.                     $json['error'] = $container->get('translator')->trans('invalid resource');
  515.                     $json['description'] = $container->get('translator')->trans('Error ! Invalid agent or already assigned for this ticket');
  516.                     $statusCode Response::HTTP_NOT_FOUND;
  517.                 }
  518.             }
  519.         } else {
  520.             $json['error'] = $container->get('translator')->trans('invalid ticket');
  521.             $statusCode Response::HTTP_NOT_FOUND;
  522.         }
  523.         return new JsonResponse($json$statusCode);  
  524.     }
  525.     /**
  526.      * adding  or removing collaborator to a Ticket
  527.      *
  528.      * @param Request $request
  529.      * @return void
  530.     */
  531.     public function addRemoveTicketCollaborator(Request $requestContainerInterface $container
  532.     {
  533.         $json = [];
  534.         $statusCode Response::HTTP_OK;
  535.         $content $request->request->all()? : json_decode($request->getContent(), true);
  536.         $entityManager $this->getDoctrine()->getManager();
  537.         $ticket $entityManager->getRepository(Ticket::class)->find($request->attributes->get('ticketId'));
  538.         if(!$ticket) {
  539.             $json['error'] =  $container->get('translator')->trans('resource not found');
  540.             return new JsonResponse($jsonResponse::HTTP_NOT_FOUND);
  541.         }
  542.         if($request->getMethod() == "POST" && !(isset($content['id'])) ) { 
  543.             if(!isset($content['email']) || !filter_var($content['email'], FILTER_VALIDATE_EMAIL)) {
  544.                 $json['error'] = $container->get('translator')->trans('missing/invalid field');
  545.                 $json['message'] = $container->get('translator')->trans('required: email');
  546.                 return new JsonResponse($jsonResponse::HTTP_BAD_REQUEST);
  547.             }
  548.             if($content['email'] == $ticket->getCustomer()->getEmail()) {
  549.                 $json['error'] = $container->get('translator')->trans('Error ! Can not add customer as a collaborator.');
  550.                 $statusCode Response::HTTP_BAD_REQUEST;
  551.             } else {
  552.                 $data = array(
  553.                     'from' => $content['email'],
  554.                     'firstName' => ($firstName ucfirst(current(explode('@'$content['email'])))),
  555.                     'lastName' => ' ',
  556.                     'role' => 4,
  557.                 );
  558.                 
  559.                 $supportRole $entityManager->getRepository(SupportRole::class)->findOneByCode('ROLE_CUSTOMER');
  560.                 $collaborator $container->get('user.service')->createUserInstance($data['from'], $data['firstName'], $supportRole$extras = ["active" => true]);
  561.                 $checkTicket $entityManager->getRepository(Ticket::class)->isTicketCollaborator($ticket$content['email']);
  562.                 if (!$checkTicket) { 
  563.                     $ticket->addCollaborator($collaborator);
  564.                     $entityManager->persist($ticket);
  565.                     $entityManager->flush();
  566.                     $ticket->lastCollaborator $collaborator;
  567.                     if ($collaborator->getCustomerInstance()) {
  568.                         $json['collaborator'] = $collaborator->getCustomerInstance()->getPartialDetails();
  569.                     } else {
  570.                         $json['collaborator'] = $collaborator->getAgentInstance()->getPartialDetails();
  571.                     }
  572.                     $event = new CoreWorkflowEvents\Ticket\Collaborator();
  573.                     $event
  574.                         ->setTicket($ticket)
  575.                     ;
  576.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  577.                     $json['success'] =  $container->get('translator')->trans('Success ! Collaborator added successfully.');
  578.                     $statusCode Response::HTTP_OK;
  579.                 } else {
  580.                     $json['warning'] =  $container->get('translator')->trans('Collaborator is already added.');
  581.                     $statusCode Response::HTTP_BAD_REQUEST;
  582.                 }
  583.             }
  584.         } elseif($request->getMethod() == "POST"  &&  isset($content['id']) ) {
  585.             $collaborator $entityManager->getRepository(User::class)->findOneBy(array('id' => $content['id']));
  586.             
  587.             if($collaborator) {
  588.                 $ticket->removeCollaborator($collaborator);
  589.                 $entityManager->persist($ticket);
  590.                 $entityManager->flush();
  591.                 $json['success'] =  $container->get('translator')->trans('Success ! Collaborator removed successfully.');
  592.                 $statusCode Response::HTTP_OK;
  593.             } else {
  594.                 $json['error'] =  $container->get('translator')->trans('Error ! Invalid Collaborator.');
  595.                 $statusCode Response::HTTP_BAD_REQUEST;
  596.             }
  597.         }
  598.         return new JsonResponse($json$statusCode);  
  599.     }
  600.     
  601.     /**
  602.      * Download ticket attachment
  603.      *
  604.      * @param Request $request
  605.      * @return void
  606.     */
  607.     public function downloadAttachment(Request $requestContainerInterface $container
  608.     {
  609.         $attachmentId $request->attributes->get('attachmentId');
  610.         $attachmentRepository $this->getDoctrine()->getManager()->getRepository(Attachment::class);
  611.         $attachment $attachmentRepository->findOneById($attachmentId);
  612.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  613.         if (!$attachment) {
  614.             throw new NotFoundHttpException('Page Not Found');
  615.         }
  616.         $path $container->get('kernel')->getProjectDir() . "/public/"$attachment->getPath();
  617.         $response = new Response();
  618.         $response->setStatusCode(200);
  619.         $response->headers->set('Content-type'$attachment->getContentType());
  620.         $response->headers->set('Content-Disposition''attachment; filename='$attachment->getName());
  621.         $response->sendHeaders();
  622.         $response->setContent(readfile($path));
  623.         return $response
  624.     }
  625.     /**
  626.      * Download Zip attachment
  627.      *
  628.      * @param Request $request
  629.      * @return void
  630.     */
  631.     public function downloadZipAttachment(Request $request)
  632.     {
  633.         $threadId $request->attributes->get('threadId');
  634.         $attachmentRepository $this->getDoctrine()->getManager()->getRepository(Attachment::class);
  635.         $attachment $attachmentRepository->findByThread($threadId);
  636.         if (!$attachment) {
  637.             throw new NotFoundHttpException('Page Not Found');
  638.         }
  639.         $zipname 'attachments/' .$threadId.'.zip';
  640.         $zip = new \ZipArchive;
  641.         $zip->open($zipname\ZipArchive::CREATE);
  642.         if (count($attachment)) {
  643.             foreach ($attachment as $attach) {
  644.                 $zip->addFile(substr($attach->getPath(), 1));
  645.             }
  646.         }
  647.         $zip->close();
  648.         $response = new Response();
  649.         $response->setStatusCode(200);
  650.         $response->headers->set('Content-type''application/zip');
  651.         $response->headers->set('Content-Disposition''attachment; filename=' $threadId '.zip');
  652.         $response->sendHeaders();
  653.         $response->setContent(readfile($zipname));
  654.         return $response;
  655.     }
  656.     /**
  657.      * Edit Ticket properties
  658.      *
  659.      * @param Request $request
  660.      * @return void
  661.     */
  662.     public function editTicketProperties(Request $requestContainerInterface $container
  663.     {
  664.         $json = [];
  665.         $statusCode Response::HTTP_OK;
  666.         $entityManager $this->getDoctrine()->getManager();
  667.         $requestContent $request->request->all() ?: json_decode($request->getContent(), true);
  668.         $ticketId =  $request->attributes->get('ticketId');
  669.         $ticket $entityManager->getRepository(Ticket::class)->findOneById($ticketId);
  670.         // Validate request integrity
  671.         if (empty($ticket)) {
  672.             $json['error']  = 'invalid resource';
  673.             $json['description'] =  $container->get('translator')->trans('Unable to retrieve details for ticket #%ticketId%.', [
  674.                                         '%ticketId%' => $ticketId,
  675.                                     ]);
  676.             $statusCode Response::HTTP_NOT_FOUND;
  677.             return new JsonResponse($json$statusCode);  
  678.         } else if (!isset($requestContent['property'])) {
  679.             $json['error']  =  $container->get('translator')->trans('missing resource');
  680.             $json['description'] = $container->get('translator')->trans('Insufficient details provided.');
  681.             $statusCode Response::HTTP_BAD_REQUEST;
  682.             return new JsonResponse($json$statusCode); 
  683.         }
  684.         // Update property
  685.         switch ($requestContent['property']) {
  686.             case 'agent':
  687.                 $agent $entityManager->getRepository(User::class)->findOneById($requestContent['value']);
  688.                 if (empty($agent)) {
  689.                     // User does not exist
  690.                     $json['error']  = $container->get('translator')->trans('No such user exist');
  691.                     $json['description'] = $container->get('translator')->trans('Unable to retrieve agent details');
  692.                     $statusCode Response::HTTP_BAD_REQUEST;
  693.                     return new JsonResponse($json$statusCode);
  694.                 } else {
  695.                     // Check if an agent instance exists for the user
  696.                     $agentInstance $agent->getAgentInstance();
  697.                     if (empty($agentInstance)) {
  698.                         // Agent does not exist
  699.                         $json['error']  = $container->get('translator')->trans('No such user exist');
  700.                         $json['description'] = $container->get('translator')->trans('Unable to retrieve agent details');
  701.                         $statusCode Response::HTTP_BAD_REQUEST;
  702.                         return new JsonResponse($json$statusCode);
  703.                     }
  704.                 }
  705.                 $agentDetails $agentInstance->getPartialDetails();
  706.                 // Check if ticket is already assigned to the agent
  707.                 if ($ticket->getAgent() && $agent->getId() === $ticket->getAgent()->getId()) {
  708.                     $json['success']  = $container->get('translator')->trans('Already assigned');
  709.                     $json['description'] = $container->get('translator')->trans('Ticket already assigned to %agent%', [
  710.                         '%agent%' => $agentDetails['name']]);
  711.                     $statusCode Response::HTTP_OK;
  712.                     return new JsonResponse($json$statusCode);
  713.                 } else {
  714.                     $ticket->setAgent($agent);
  715.                     $entityManager->persist($ticket);
  716.                     $entityManager->flush();
  717.                     // Trigger Agent Assign event
  718.                     $event = new CoreWorkflowEvents\Ticket\Agent();
  719.                     $event
  720.                         ->setTicket($ticket)
  721.                     ;
  722.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  723.                     $json['success']  = $container->get('translator')->trans('Success');
  724.                     $json['description'] = $container->get('translator')->trans('Ticket successfully assigned to %agent%', [
  725.                         '%agent%' => $agentDetails['name'],
  726.                     ]);
  727.                     $statusCode Response::HTTP_OK;
  728.                     return new JsonResponse($json$statusCode);
  729.                 }
  730.                 break;
  731.             case 'status':
  732.                 $ticketStatus $entityManager->getRepository(TicketStatus::class)->findOneById((int) $requestContent['value']);
  733.                 if (empty($ticketStatus)) {
  734.                     // Selected ticket status does not exist
  735.                     $json['error']  = $container->get('translator')->trans('Error');
  736.                     $json['description'] = $container->get('translator')->trans('Unable to retrieve status details');
  737.                     $statusCode Response::HTTP_BAD_REQUEST;
  738.                     return new JsonResponse($json$statusCode);
  739.                 }
  740.                 if ($ticketStatus->getId() === $ticket->getStatus()->getId()) {
  741.                     $json['success']  = $container->get('translator')->trans('Success');
  742.                     $json['description'] = $container->get('translator')->trans('Ticket status already set to %status%', [
  743.                         '%status%' => $ticketStatus->getDescription()]);
  744.                     $statusCode Response::HTTP_OK;
  745.                     return new JsonResponse($json$statusCode);
  746.                 } else {
  747.                     $ticket->setStatus($ticketStatus);
  748.                     $entityManager->persist($ticket);
  749.                     $entityManager->flush();
  750.                     // Trigger ticket status event
  751.                     $event = new CoreWorkflowEvents\Ticket\Status();
  752.                     $event
  753.                         ->setTicket($ticket)
  754.                     ;
  755.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  756.                     $json['success']  =  $container->get('translator')->trans('Success');
  757.                     $json['description'] =  $container->get('translator')->trans('Ticket status update to %status%', [
  758.                         '%status%' => $ticketStatus->getDescription()]);
  759.                     $statusCode Response::HTTP_OK;
  760.                     return new JsonResponse($json$statusCode);
  761.                 }
  762.                 break;
  763.             case 'priority':
  764.                 // $container->isAuthorized('ROLE_AGENT_UPDATE_TICKET_PRIORITY');
  765.                 $ticketPriority $entityManager->getRepository(TicketPriority::class)->findOneById($requestContent['value']);
  766.                 if (empty($ticketPriority)) {
  767.                     // Selected ticket priority does not exist
  768.                     $json['error']  = $container->get('translator')->trans('Error');
  769.                     $json['description'] =  $container->get('translator')->trans('Unable to retrieve priority details');
  770.                     $statusCode Response::HTTP_BAD_REQUEST;
  771.                     return new JsonResponse($json$statusCode);
  772.                 }
  773.                 if ($ticketPriority->getId() === $ticket->getPriority()->getId()) {
  774.                     $json['success']  = $container->get('translator')->trans('Success');
  775.                     $json['description'] =  $container->get('translator')->trans('Ticket priority already set to %priority%', [
  776.                         '%priority%' => $ticketPriority->getDescription()
  777.                     ]);
  778.                     $statusCode Response::HTTP_OK;
  779.                     return new JsonResponse($json$statusCode);
  780.                 } else {
  781.                     $ticket->setPriority($ticketPriority);
  782.                     $entityManager->persist($ticket);
  783.                     $entityManager->flush();
  784.                     // Trigger ticket Priority event
  785.                     $event = new CoreWorkflowEvents\Ticket\Priority();
  786.                     $event
  787.                         ->setTicket($ticket)
  788.                     ;
  789.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  790.                     $json['success']  = $container->get('translator')->trans('Success');
  791.                     $json['description'] =  $container->get('translator')->trans('Ticket priority updated to %priority%', [
  792.                         '%priority%' => $ticketPriority->getDescription()
  793.                     ]);
  794.                     $statusCode Response::HTTP_OK;
  795.                     return new JsonResponse($json$statusCode);
  796.                 }
  797.                 break;
  798.             case 'group':
  799.                 $supportGroup $entityManager->getRepository(SupportGroup::class)->findOneById($requestContent['value']);
  800.                 if (empty($supportGroup)) {
  801.                     if ($requestContent['value'] == "") {
  802.                         if ($ticket->getSupportGroup() != null) {
  803.                             $ticket->setSupportGroup(null);
  804.                             $entityManager->persist($ticket);
  805.                             $entityManager->flush();
  806.                         }
  807.                         $json['success']  = $container->get('translator')->trans('Success');
  808.                         $json['description'] =   $container->get('translator')->trans('Ticket support group updated successfully');
  809.                         $statusCode Response::HTTP_OK;
  810.                     } else {
  811.                         $json['error']  = $container->get('translator')->trans('Error');
  812.                         $json['description'] = $container->get('translator')->trans('Unable to retrieve support group details');
  813.                         $statusCode Response::HTTP_BAD_REQUEST;
  814.                     }
  815.                     return new JsonResponse($json$statusCode);
  816.                 }
  817.                 if ($ticket->getSupportGroup() != null && $supportGroup->getId() === $ticket->getSupportGroup()->getId()) {
  818.                     $json['success']  = $container->get('translator')->trans('Success');
  819.                     $json['description'] = $container->get('translator')->trans('Ticket already assigned to support group');
  820.                     $statusCode Response::HTTP_OK;
  821.                     return new JsonResponse($json$statusCode);
  822.                 } else {
  823.                     $ticket->setSupportGroup($supportGroup);
  824.                     $entityManager->persist($ticket);
  825.                     $entityManager->flush();
  826.                     // Trigger Support group event
  827.                     $event = new CoreWorkflowEvents\Ticket\Group();
  828.                     $event
  829.                         ->setTicket($ticket)
  830.                     ;
  831.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  832.                     $json['success']  = $container->get('translator')->trans('Success');
  833.                     
  834.                     $json['description'] = $container->get('translator')->trans('Ticket assigned to support group successfully');
  835.                     $json['description'] = $container->get('translator')->trans('Ticket assigned to support group %group%', [
  836.                         '%group%' => $supportGroup->getDescription()
  837.                     ]);
  838.                     
  839.                     $statusCode Response::HTTP_OK;
  840.                     return new JsonResponse($json$statusCode);
  841.                 }
  842.                 break;
  843.             case 'team':
  844.                 $supportTeam $entityManager->getRepository(SupportTeam::class)->findOneById($requestContent['value']);
  845.                 if (empty($supportTeam)) {
  846.                     if ($requestContent['value'] == "") {
  847.                         if ($ticket->getSupportTeam() != null) {
  848.                             $ticket->setSupportTeam(null);
  849.                             $entityManager->persist($ticket);
  850.                             $entityManager->flush();
  851.                         }
  852.                         $json['success']  = $container->get('translator')->trans('Success');
  853.                         $json['description'] = $container->get('translator')->trans('Ticket support team updated successfully');
  854.                         $statusCode Response::HTTP_OK;
  855.                         return new JsonResponse($json$statusCode);
  856.                     } else {
  857.                         $json['error']  = $container->get('translator')->trans('Error');
  858.                         $json['description'] = $container->get('translator')->trans('Unable to retrieve support team details');
  859.                         $statusCode Response::HTTP_BAD_REQUEST;
  860.                         return new JsonResponse($json$statusCode);
  861.                     }
  862.                 }
  863.                 if ($ticket->getSupportTeam() != null && $supportTeam->getId() === $ticket->getSupportTeam()->getId()) {
  864.                         $json['success']  = $container->get('translator')->trans('Success');
  865.                         $json['description'] = $container->get('translator')->trans('Ticket already assigned to support team');
  866.                         $statusCode Response::HTTP_OK;
  867.                         return new JsonResponse($json$statusCode);
  868.                 } else {
  869.                     $ticket->setSupportTeam($supportTeam);
  870.                     $entityManager->persist($ticket);
  871.                     $entityManager->flush();
  872.                     // Trigger ticket delete event
  873.                     $event = new CoreWorkflowEvents\Ticket\Team();
  874.                     $event
  875.                         ->setTicket($ticket)
  876.                     ;
  877.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  878.                     $json['success']  = $container->get('translator')->trans('Success');
  879.                     $json['description'] = $container->get('translator')->trans('Ticket assigned to support team successfully');
  880.                     $json['description'] = $container->get('translator')->trans('Ticket assigned to support team %team%', [
  881.                         '%team%' => $supportTeam->getDescription()
  882.                     ]);
  883.                     $statusCode Response::HTTP_OK;
  884.                     return new JsonResponse($json$statusCode);
  885.                 }
  886.                 break;
  887.             case 'type':
  888.                 // $container->isAuthorized('ROLE_AGENT_UPDATE_TICKET_TYPE');
  889.                 $ticketType $entityManager->getRepository(TicketType::class)->findOneById($requestContent['value']);
  890.                 if (empty($ticketType)) {
  891.                     // Selected ticket priority does not exist
  892.                     $json['error']  = $container->get('translator')->trans('Error');
  893.                     $json['description'] = $container->get('translator')->trans('Unable to retrieve ticket type details');
  894.                     $statusCode Response::HTTP_BAD_REQUEST;
  895.                     return new JsonResponse($json$statusCode);
  896.                 }
  897.                 if (null != $ticket->getType() && $ticketType->getId() === $ticket->getType()->getId()) {
  898.                     $json['success']  = $container->get('translator')->trans('Success');
  899.                     $json['description'] = $container->get('translator')->trans('Ticket type already set to ' $ticketType->getDescription());
  900.                     $statusCode Response::HTTP_OK;
  901.                     return new JsonResponse($json$statusCode);
  902.                 } else {
  903.                     $ticket->setType($ticketType);
  904.                     $entityManager->persist($ticket);
  905.                     $entityManager->flush();
  906.                     // Trigger ticket delete event
  907.                     $event = new CoreWorkflowEvents\Ticket\Type();
  908.                     $event
  909.                         ->setTicket($ticket)
  910.                     ;
  911.                     $container->get('event_dispatcher')->dispatch($event'uvdesk.automation.workflow.execute');
  912.                     $json['success']  = $container->get('translator')->trans('Success');
  913.                     $json['description'] = $container->get('translator')->trans('Ticket type updated to ' $ticketType->getDescription());
  914.                     $statusCode Response::HTTP_OK;
  915.                     return new JsonResponse($json$statusCode);
  916.                 }
  917.                 break;
  918.             case 'label':
  919.                 $label $entityManager->getRepository(SupportLabel::class)->find($requestContent['value']);
  920.                 if ($label) {
  921.                     $ticket->removeSupportLabel($label);
  922.                     $entityManager->persist($ticket);
  923.                     $entityManager->flush();
  924.                     $json['success']  = $container->get('translator')->trans('Success');
  925.                     $json['description'] = $container->get('translator')->trans('Success ! Ticket to label removed successfully');
  926.                     $statusCode Response::HTTP_OK;
  927.                     return new JsonResponse($json$statusCode);
  928.                 } else {
  929.                     $json['error']  = $container->get('translator')->trans('Error');
  930.                     $json['description'] = $container->get('translator')->trans('No support level exist for this ticket with this id');
  931.                     $statusCode Response::HTTP_BAD_REQUEST;
  932.                     return new JsonResponse($json$statusCode);
  933.                 }
  934.                 break;
  935.             default:
  936.                 break;
  937.         }
  938.         return new JsonResponse($json$statusCode);  
  939.     }
  940.     /**
  941.      * objectSerializer This function convert Entity object into json contenxt
  942.      * @param Object $object Customer Entity object
  943.      * @return JSON  JSON context
  944.      */
  945.     public function objectSerializer($object) {
  946.         $object->formatedCreatedAt = new \Datetime;
  947.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  948.         $normalizer = new ObjectNormalizer();
  949.         $normalizers = array($normalizer);
  950.         
  951.         $serializer = new Serializer($normalizers$encoders);
  952.         $jsonContent $serializer->serialize($object'json', [
  953.             'circular_reference_handler' => function ($object) {
  954.                 return $object->getId();
  955.             }
  956.         ]);
  957.         return $jsonContent;
  958.     }
  959. }