src/project/OfficeBrain/CustomBundle/UserBundle/Controller/ContactBookController.php line 183

Open in your IDE?
  1. <?php
  2. namespace App\project\OfficeBrain\CustomBundle\UserBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  7. use App\project\OfficeBrain\CustomBundle\UserBundle\Entity\ContactBook;
  8. use App\OfficeBrain\Bundle\CoreBundle\CustomeHandler as FormErrorManager;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use App\project\OfficeBrain\CustomBundle\UserBundle\Form\ContactBookType;
  11. use App\OfficeBrain\Bundle\UserBundle\Controller\ContactBookController as baseContactBookController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\ContactBookService;
  15. use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
  16. use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
  17. use App\project\OfficeBrain\CustomBundle\UserBundle\Manager\Service\ContactBookService as CustomContactBookService;
  18. class ContactBookController extends baseContactBookController
  19. {
  20.     /**
  21.      *
  22.      * @author Employee Id: 4493
  23.      *    set default value
  24.      *
  25.      * @return NULL
  26.      */
  27.     public function __construct(ContainerInterface $containerContactBookService $contactBookServiceQueueApiManager $queueApiManagerCustomContactBookService $customContactBookServiceCoreService $coreService)
  28.     {
  29.         parent::__construct($container$contactBookService$queueApiManager$coreService);
  30.         $this->serviceContainer $container;
  31.         $this->customContactBookService $customContactBookService->getContactBookExtended();
  32.     }
  33.     /**
  34.      *
  35.      * @author Employee Id: 4493
  36.      *         To unset value
  37.      *
  38.      * @return NULL
  39.      */
  40.     public function __destruct()
  41.     {
  42.         parent::__destruct();
  43.     }
  44.     private function prepareFormJsonError()
  45.     {
  46.         return array(
  47.                 'form_name' => $this->form->getName(),
  48.                 'form_status' => 'error',
  49.                 'form_errors' => $this->formErrorManager->prepareErrorArray($this->get('validator')->validate($this->form))
  50.         );
  51.     }
  52.     /**
  53.      *
  54.      * @author Employee Id: 4493
  55.      *        Create objects which use this class
  56.      *
  57.      * @return NULL
  58.      */
  59.     public function initAction(Request $request)
  60.     {
  61.         parent::initAction($request);
  62.         // $this->contactbookmanager = $this->serviceContainer->get('office_brain_user_contact_book_manager_custom'); // symfony 4
  63.         $this->contactbookmanager $this->customContactBookService// symfony 4
  64.         // $this->contactbookmanager = $this->container->get('office_brain_custom_user_contact_book_manager'); // commented for symfony 5
  65.     }
  66.     /**
  67.      * @author Employee Id: 4493
  68.      * OB eCommerce Product -  contact book form
  69.      *
  70.      * @Route("{_locale}/my-account/address-book/add",
  71.      *     name="office_brain_userbundle_contactbook_addcontactbook",
  72.      *  options={"expose"=true}, methods={"GET"}
  73.      * )
  74.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/ContactBook/addContactBook.html.twig")
  75.      */
  76.     public function addContactBookAction(Request $request)
  77.     {
  78.         $this->initAction($request);
  79.         // $this->form = $this->createForm(new ContactBookType($this->container), new ContactBook());
  80.         $this->form $this->createForm(ContactBookType::class, new ContactBook(), [
  81.             'container' => $this->serviceContainer,
  82.             'contactBookService' => $this->contactBookService,
  83.             'coreService' => $this->coreService,
  84.         ]);
  85.         $this->form->handleRequest($this->request);
  86.         $this->responseArray['contactBookForm'] = $this->form->createView();
  87.         return  $this->responseArray;
  88.     }
  89.     /**
  90.      * @author Employee Id: 4493
  91.      * OB eCommerce Product -  contact book form submit
  92.      *
  93.      * @Route("{_locale}/my-account/address-book/add",
  94.      *     name="office_brain_userbundle_contactbook_addcontactbookpost",
  95.      *  options={"expose"=true}, methods={"POST"}
  96.      * )
  97.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/ContactBook/addContactBook.html.twig")
  98.      */
  99.     public function addContactBookPostAction(Request $request)
  100.     {
  101.         $this->initAction($request);
  102.         $requestarray=$this->request->request->all();
  103.         if($requestarray['contact_book']['countryId']=='739')
  104.         {
  105.             $this->responseArray['othercountry']=1;
  106.         }
  107.         // $this->form = $this->createForm(new ContactBookType($this->container,'request-quote-add-address'), new ContactBook()); // symfony 4
  108.         
  109.         $this->form $this->createForm(ContactBookType::class, new ContactBook(), [
  110.             'container' => $this->serviceContainer,
  111.             'contactBookService' => $this->contactBookService,
  112.             'coreService' => $this->coreService,
  113.             'side' => 'request-quote-add-address'
  114.         ]);
  115.         $this->form ->handleRequest($this->request);
  116.         if ($this->form->isValid()) {
  117.             $contactBookData $this->form->getData();
  118.             $add=$this->contactbookmanager->addContactBook($contactBookData''1);
  119.             switch ($add['status']) {
  120.                 case  'SUCCESS' :
  121.                     if ($this->erpIntegration && $this->erpIntegration['userManagement'] == && !empty($this->queueApiManager)) {
  122.                         $this->queueApiManager->mapQueue("create"$add['data']);
  123.                     }
  124.                     $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.contact_book.add_message.address_success'));
  125.                     break;
  126.                 case  'FAIL':
  127.                     $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.contact_book.add_message.address_fail'));
  128.                     break;
  129.             }
  130.             if($this->request->isXmlHttpRequest ()){
  131.                 $this->responseArray['status'] = 'success';
  132.                 $this->responseArray['call_ajax_url_checkout'] = $this->generateUrl("office_brain_requestquotebundle_requestquote_getshippingaddressbyid") ; //'office_brain_requestquotebundle_requestquote_getshippingaddressbyid';
  133.                 $this->responseArray['contact_book_id'] = $contactBookData->getId();
  134.                 $this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('request_quote.shipping_type.address_added_successfully');
  135.                 $counter $this->request->get('counter',null); // Used for request Quote Add Address
  136.                 if($counter!=null){
  137.                     $this->responseArray['counter'] = $counter;
  138.                 }
  139.                 return new JsonResponse($this->responseArray);
  140.             }
  141.             return $this->redirect($this->generateUrl("office_brain_userbundle_contactbook_viewcontactbook"));
  142.         }
  143.         $this->responseArray['contactBookForm'] = $this->form->createView();
  144.         if($this->request->isXmlHttpRequest ()){
  145.             if ($this->request->get('call_type')=='country_code' || $this->request->get('call_type')=='state_code') {
  146.                 return $this->responseArray;
  147.             } else { 
  148.                   return new JsonResponse $this->prepareFormJsonError ($this->form) );
  149.             }
  150.         }
  151.         return $this->responseArray;
  152.     }
  153.     /**
  154.      * @author Employee Id: 4493
  155.      * OB eCommerce Product -  contact book form
  156.      *
  157.      * @Route("{_locale}/my-account/address-book/edit/{contactBookId}",
  158.      *     name="office_brain_userbundle_contactbook_editcontactbook",
  159.      *  options={"expose"=true}, methods={"GET"}
  160.      * )
  161.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/ContactBook/editContactBook.html.twig")
  162.      */
  163.     public function editContactBookAction(Request $request)
  164.     {
  165.         $this->initAction($request);
  166.         $contactBookId $this->request->get('contactBookId');
  167.         $contactBookArray $this->contactbookmanager->getSingleContactBook($contactBookId);
  168.         $contactBookForm $this->createForm(ContactBookType::class, $contactBookArray, [
  169.             'container' => $this->serviceContainer,
  170.             'contactBookService' => $this->contactBookService,
  171.             'coreService' => $this->coreService,
  172.             'side' => null,
  173.         ]);
  174.         if($contactBookArray->getCountryId()=='739')
  175.         {
  176.             $othercountry=1;
  177.             return array('contactBookForm'=> $contactBookForm->createView(),'contactBookId'=>$contactBookId,'othercountry'=>$othercountry);
  178.         }
  179.         
  180.            return array('contactBookForm'=> $contactBookForm->createView(),'contactBookId'=>$contactBookId);
  181.     }
  182.     /**
  183.      * @author Employee Id: 4493
  184.      * OB eCommerce Product -  contact book form submit
  185.      *
  186.      * @Route("{_locale}/my-account/address-book/edit/{contactBookId}",
  187.      *     name="office_brain_userbundle_contactbook_editcontactbookpost",
  188.      *  options={"expose"=true}, methods={"POST"}
  189.      * )
  190.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/ContactBook/editContactBook.html.twig")
  191.      */
  192.     public function editContactBookPostAction(Request $request)
  193.     {
  194.         $this->initAction($request);
  195.         $contactBookId $this->request->get('contactBookId');
  196.         $contactBookObject $this->contactbookmanager->getSingleContactBook($contactBookId);
  197.         $previousAddressType=$contactBookObject->getAdressType()->getId();
  198.         // $this->form  = $this->createForm(new ContactBookType($this->container,'request-quote-add-address'), $contactBookObject);
  199.         $this->form $this->createForm(ContactBookType::class, $contactBookObject, [
  200.             'container' => $this->serviceContainer,
  201.             'contactBookService' => $this->contactBookService,
  202.             'coreService' => $this->coreService,
  203.             'side' => 'request-quote-add-address',
  204.         ]);
  205.         $this->form ->handleRequest($this->request);
  206.         $requestarray=$this->request->request->all();
  207.        if ($this->form->isValid()) {
  208.             $contactBookData $this->form->getData();
  209.             if($previousAddressType!=$contactBookData->getAdressType()->getId()) {
  210.                 $this->changeAddressTypeFlag=1;
  211.             }
  212.             $edit=$this->contactbookmanager->editContactBook($contactBookData,$this->changeAddressTypeFlag);
  213.             switch ($edit['status']) {
  214.                 case  'SUCCESS' :
  215.                     if ($this->erpIntegration && $this->erpIntegration['userManagement'] == && !empty($this->queueApiManager) ) {
  216.                         if($edit['data']->getErpId()){
  217.                             $this->queueApiManager->mapQueue("update"$edit['data']);
  218.                         }else{
  219.                             $this->queueApiManager->mapQueue("create"$edit['data']);
  220.                         }
  221.                     }
  222.                     $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.contact_book.edit_message.address_success'));
  223.                     break;
  224.                 case  'FAIL':
  225.                     $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.contact_book.edit_message.address_fail'));
  226.                     break;
  227.             }
  228.             if($this->request->isXmlHttpRequest()){
  229.                 $this->responseArray['status'] = 'success';
  230.                 // if(count($this->request->get('is_edit_from_payment'))>0 && $this->request->get('is_edit_from_payment')==1)
  231.                 if($this->request->get('is_edit_from_payment') > && $this->request->get('is_edit_from_payment')==1)
  232.                 {
  233.                     $this->responseArray['call_ajax_url'] = $this->generateUrl("office_brain_orderbundle_order_getcheckoutshippingaddressbyid");
  234.                 }
  235.                 else
  236.                 {
  237.                     $this->responseArray['call_ajax_url'] = $this->generateUrl("office_brain_requestquotebundle_requestquote_getshippingaddressbyid");
  238.                 }
  239.                 $this->responseArray['contact_book_id'] = $contactBookId;
  240.                 $this->responseArray['success_message'] = $this->serviceContainer->get('translator')->trans('request_quote.shipping_type.edit_address_added_successfully');
  241.                 $counter $this->request->get('counter',null); // Used for request Quote Edit Address
  242.                 if($counter!=null){
  243.                     $this->responseArray['counter'] = $counter;
  244.                 }
  245.                 return new JsonResponse($this->responseArray);
  246.             }
  247.             return $this->redirect($this->generateUrl("office_brain_userbundle_contactbook_viewcontactbook"));
  248.         }
  249.         if($this->request->isXmlHttpRequest ()){
  250.             if ($this->request->get('call_type')=='country_code' || $this->request->get('call_type')=='state_code') {
  251.                 return $this->responseArray;
  252.             } else {
  253.                 return new JsonResponse $this->prepareFormJsonError ($this->form) );
  254.             }
  255.         }
  256.         if($requestarray['contact_book']['countryId']=='739')
  257.         {
  258.             $othercountry=1;
  259.             return array('contactBookForm'=>$this->form->createView(),'contactBookId'=>$contactBookId,'othercountry'=>$othercountry);
  260.         }
  261.         return array('contactBookForm'=> $this->form->createView(),'contactBookId'=>$contactBookId);
  262.     }
  263.     /**
  264.      * @author Employee Id: 4493
  265.      * OB eCommerce Product -  contact book View
  266.      *
  267.      * @Route("{_locale}/my-account/address-book/view",
  268.      *     name="office_brain_userbundle_contactbook_viewcontactbook",
  269.      *  options={"expose"=true}, methods={"GET"}
  270.      * )
  271.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/ContactBook/viewContactBook.html.twig")
  272.      */
  273.     public function viewContactBookAction(Request $request)
  274.     {
  275.         $this->initAction($request);
  276.         $this->responseArray['record_set'] = $this->contactbookmanager->getContactBook($this->userId$this->addressBookFlag,$this->page,$this->recordsPerPage);
  277.         return $this->responseArray;
  278.     }
  279.     /**
  280.      * @author Employee Id: 4493
  281.      * OB eCommerce Product -  contact book Delete
  282.      *
  283.      * @Route("{_locale}/my-account/address-book/delete",
  284.      *     name="office_brain_userbundle_contactbook_deletecontactbook",
  285.      *  options={"expose"=true}
  286.      * )
  287.      * @Template()
  288.      */
  289.     public function deleteContactBookAction(Request $request)
  290.     {
  291.         $this->initAction($request);
  292.         $contactBook $this->contactbookmanager->deleteContactBook($this->contactBookId);
  293.         switch ($contactBook['status']) {
  294.             case  'SUCCESS' :
  295.                 if ($this->erpIntegration && $this->erpIntegration['userManagement'] == && !empty($this->queueApiManager)) {
  296.                     $this->queueApiManager->mapQueue("remove", array('id' => $this->contactBookId));
  297.                 }
  298.                 $this->responseArray['status'] = 'success';
  299.                 //$this->responseArray['status_message'] = $this->get('translator')->trans('user.contact_book.remove_message.address_success');
  300.                 $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_contactbook_viewcontactbook');
  301.                 break;
  302.             case  'FAIL':
  303.                 $this->responseArray['error_message'] = $this->translator->trans('user.contact_book.remove_message.address_fail');
  304.                 break;
  305.         }
  306.         return new JsonResponse($this->responseArray);
  307.     }
  308.     /**
  309.      * @author Employee Id: 4493
  310.      * OB eCommerce Product -  Is Default Update
  311.      *
  312.      * @Route("{_locale}/my-account/address-book/is-default",
  313.      *     name="office_brain_userbundle_contactbook_isdefault",
  314.      *  options={"expose"=true}
  315.      * )
  316.      * @Template()
  317.      */
  318.     public function isDefaultAction(Request $request)
  319.     {
  320.         $this->initAction($request);
  321.         $data = array();
  322.         $contactBookId $this->request->get('id');
  323.         $isDefault $this->contactbookmanager->updateIsDefault($contactBookId);
  324.         switch ($isDefault['status']) {
  325.             case  'SUCCESS' :
  326.                 $this->responseArray['status'] = 'success';
  327.                 $this->responseArray['addressType'] = $isDefault['data']->getAdressType()->getId();
  328.                 $this->responseArray['status_message'] = $this->translator->trans('user.contact_book.update_default.address_success');
  329.                 break;
  330.             case  'FAIL':
  331.                 $this->responseArray['error_message'] = $this->translator->trans('user.contact_book.update_default.address_fail');
  332.                 break;
  333.         }
  334.         return new JsonResponse($this->responseArray);
  335.     }
  336. }