vendor/uvdesk/support-center-bundle/Controller/KnowledgebaseXHR.php line 11

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\SupportCenterBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. class KnowledgebaseXHR extends Controller
  7. {
  8.     public function listFoldersXHR(Request $request)
  9.     {
  10.         if (!$this->get('user.service')->isAccessAuthorized('ROLE_AGENT_MANAGE_KNOWLEDGEBASE')) {
  11.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  12.         }
  13.         $response = new Response();
  14.         $folderCollection $this->getDoctrine()->getRepository('UVDeskSupportCenterBundle:Solutions')->getAllSolutions($request->query$this->container);
  15.         $response->setContent(json_encode($folderCollection));
  16.         $response->headers->set('Content-Type''application/json');
  17.         return $response;
  18.     }
  19.     public function updateFolderXHR(Request $request)
  20.     {
  21.         if (!$this->get('user.service')->isAccessAuthorized('ROLE_AGENT_MANAGE_KNOWLEDGEBASE')) {
  22.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  23.         }
  24.         $json = array();
  25.         $entityManager $this->getDoctrine()->getManager();
  26.         switch($request->getMethod())
  27.         {
  28.             case "PATCH":
  29.                 $content json_decode($request->getContent(), true);
  30.                 $solutionId $content['id'];
  31.                 $solution $entityManager->getRepository('UVDeskSupportCenterBundle:Solutions')->find($solutionId);
  32.                 if($solution) {
  33.                     switch($content['editType']){
  34.                         case 'status':
  35.                             $solution->setVisibility($content['value']);
  36.                             $entityManager->persist($solution);
  37.                             $entityManager->flush();
  38.                             $json['alertClass'] = 'success';
  39.                             $json['alertMessage'] = $this->get('translator')->trans('Success ! Folder status updated successfully.');
  40.                             break;
  41.                         default:
  42.                             break;
  43.                     }
  44.                 } else {
  45.                     $json['alertClass'] = 'danger';
  46.                     $json['alertMessage'] = $this->get('translator')->trans('Error ! Folder is not exist.');
  47.                 }
  48.                 break;
  49.             case "PUT":
  50.                 $content json_decode($request->getContent(), true);
  51.                 $solutionId $content['id'];
  52.                 $solution $entityManager->getRepository('UVDeskSupportCenterBundle:Solutions')->find($solutionId);
  53.                 if($solution) {
  54.                     $solution->setName($content['name']);
  55.                     $solution->setDescription($content['description']);
  56.                     $entityManager->persist($solution);
  57.                     $entityManager->flush();
  58.                     $json['alertClass'] = 'success';
  59.                     $json['alertMessage'] ='Success ! Folder updated successfully.';
  60.                 } else {
  61.                     $json['alertClass'] = 'danger';
  62.                     $json['alertMessage'] = $this->get('translator')->trans('Error ! Folder does not exist.');
  63.                 }
  64.                 break;
  65.             case "DELETE":
  66.                 $solutionId $request->attributes->get('folderId');
  67.                 $solutionBase $entityManager->getRepository('UVDeskSupportCenterBundle:Solutions')->find($solutionId);
  68.                 if($solutionBase){
  69.                     $entityManager->getRepository('UVDeskSupportCenterBundle:Solutions')->removeEntryBySolution($solutionId);
  70.                     $entityManager->remove($solutionBase);
  71.                     $entityManager->flush();
  72.                     $json['alertClass'] = 'success';
  73.                     $json['alertMessage'] = $this->get('translator')->trans('Success ! Folder deleted successfully.');
  74.                 }else{
  75.                     $json['alertClass'] = 'error';
  76.                     $json['alertMessage'] = "Warning ! Folder doesn't exists!";
  77.                 }
  78.                 break;
  79.             default:
  80.                 $json['alertClass'] = 'error';
  81.                 $json['alertMessage'] = "Warning ! Bad request !";
  82.                 break;
  83.         }
  84.         $response = new Response(json_encode($json));
  85.         $response->headers->set('Content-Type''application/json');
  86.         return $response;
  87.     }
  88. }