vendor/uvdesk/core-framework/Controller/CustomerXHR.php line 15

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Controller;
  3. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\EventDispatcher\GenericEvent;
  7. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
  9. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  10. class CustomerXHR extends Controller
  11. {
  12.     public function listCustomersXHR(Request $request
  13.     {
  14.         if (!$this->get('user.service')->isAccessAuthorized('ROLE_AGENT_MANAGE_CUSTOMER')) {          
  15.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  16.         }
  17.         
  18.         $json = array();
  19.         
  20.         if($request->isXmlHttpRequest()) {
  21.             $repository $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User');
  22.             $json =  $repository->getAllCustomer($request->query$this->container);
  23.         }
  24.         $response = new Response(json_encode($json));
  25.         $response->headers->set('Content-Type''application/json');
  26.         
  27.         return $response;
  28.     }
  29.     public function removeCustomerXHR(Request $request
  30.     {
  31.         if (!$this->get('user.service')->isAccessAuthorized('ROLE_AGENT_MANAGE_CUSTOMER')) {          
  32.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  33.         }
  34.         
  35.         $json = array();
  36.         if($request->getMethod() == "DELETE") {
  37.             $em $this->getDoctrine()->getManager();
  38.             $id $request->attributes->get('customerId');
  39.             $user $em->getRepository('UVDeskCoreFrameworkBundle:User')->findOneBy(['id' => $id]);
  40.             if($user) {
  41.                 $this->get('user.service')->removeCustomer($user);
  42.                 // Trigger customer created event
  43.                 $event = new GenericEvent(CoreWorkflowEvents\Customer\Delete::getId(), [
  44.                     'entity' => $user,
  45.                 ]);
  46.                 $this->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute'$event);
  47.                 $json['alertClass'] = 'success';
  48.                 $json['alertMessage'] = ('Success ! Customer removed successfully.');
  49.             } else {
  50.                 $json['alertClass'] =  'danger';
  51.                 $json['alertMessage'] = ('Error ! Invalid customer id.');
  52.                 $json['statusCode'] = Response::HTTP_NOT_FOUND;
  53.             }
  54.         }
  55.         $response = new Response(json_encode($json));
  56.         $response->headers->set('Content-Type''application/json');
  57.         return $response;
  58.     }
  59. }