src/OfficeBrain/Bundle/UserBundle/Controller/UserController.php line 140

Open in your IDE?
  1. <?php
  2. namespace App\OfficeBrain\Bundle\UserBundle\Controller;
  3. // use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Security\Core\SecurityContext;
  11. use Symfony\Component\Translation\Translator;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  14. use App\OfficeBrain\Bundle\CoreBundle\CustomeHandler as FormErrorManager;
  15. use App\OfficeBrain\Bundle\UserBundle\Entity\User;
  16. use App\OfficeBrain\Bundle\UserBundle\Form\UserType;
  17. use App\OfficeBrain\Bundle\UserBundle\Form\UserPhotoType;
  18. use App\OfficeBrain\Bundle\UserBundle\Form\LocateDistributorType;
  19. use Symfony\Component\DependencyInjection\ContainerInterface;
  20. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
  21. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\SignUpService;
  22. use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
  23. use App\OfficeBrain\Bundle\SubShopBundle\Manager\Service\SubShopService;
  24. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\BiosService;
  25. use App\OfficeBrain\Bundle\OrderBundle\Manager\Service\OrderService;
  26. use App\OfficeBrain\Bundle\WishListBundle\Manager\Service\WishListService;
  27. use App\OfficeBrain\Bundle\RequestQuoteBundle\Manager\Service\RequestQuoteService;
  28. use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
  29. class UserController extends AbstractController
  30. {
  31.     /**
  32.      * @author Employee Id: 4834
  33.      * set default value
  34.      * @return NULL
  35.      */
  36.     public function __construct(ContainerInterface $containerUserService $userServiceSignUpService $signUpServiceCoreService $coreServiceSubShopService $subShopServiceBiosService $biosServiceOrderService $orderServiceWishListService $wishlistServiceRequestQuoteService $requestQuoteServiceQueueApiManager $queueApiManager)
  37.     {
  38.         $this->queueApiManager $queueApiManager->getQueueInstance();
  39.         $this->userManager $userService->getUserExtended();
  40.         $this->signUpManager $signUpService->getSignUpExtended();
  41.         $this->coreManager $coreService->getCoreExtended();
  42.         $this->subShopManager $subShopService->getSubShopExtended();
  43.         $this->biosManager $biosService->getUserBiosExtended();
  44.         $this->orderManager $orderService->getOrderManagerExtended();
  45.         $this->wishListManager $wishlistService->getWishlistManagerExtended();
  46.         $this->requestQuoteManager $requestQuoteService->getRequestQuoteManager();
  47.         $this->searchParameterArray = array();
  48.         $this->searchKeyWordsArray = array();
  49.         $this->serviceContainer $container;
  50.     }
  51.     /**
  52.      * @author Employee Id: 4834
  53.      * unset default value
  54.      * @return NULL
  55.      */
  56.     public function __destruct()
  57.     {
  58.         unset($this->queueApiManager);
  59.         unset($this->biosManager);
  60.         unset($this->searchParameterArray);
  61.         unset($this->searchKeyWordsArray);
  62.         unset($this->serviceContainer);
  63.     }
  64.     /**
  65.      *
  66.      * @author Employee Id: 4273
  67.      *
  68.      *         Create various objects required action in this class
  69.      *
  70.      * @return NULL
  71.      */
  72.     public function initAction(Request $request)
  73.     {
  74.         $this->request $request;
  75.         $this->translator $this->serviceContainer->get('translator');
  76.         $this->session $this->request->getSession();
  77.         $this->projectSetting $this->request->get('project_setting');
  78.         $this->projectUserSetting $this->request->get('project_user_setting');
  79.         $this->userConfigrations $this->projectSetting['configuration_rule']['user']['user'];
  80.         $this->findDistributorConfigrations $this->projectSetting['configuration_rule']['user']['find_distributor'];     
  81.         $this->distributorRecordsPerPage $this->projectSetting['configuration_rule']['user']['find_distributor']['option']['no_of_record_per_page'];
  82.         $this->page $this->request->get('page',1); 
  83.         $this->userId $this->projectSetting['user_id'];
  84.         $this->user $this->projectUserSetting['user_data'];
  85.         $this->companyId $this->serviceContainer->getParameter('company_id');
  86.         // $this->userManager = $this->serviceContainer->get('office_brain_user_manager');
  87.         $this->userManager $this->userManager;
  88.         // $this->signUpManager = $this->serviceContainer->get('office_brain_user_sign_up_manager');
  89.         $this->signUpManager $this->signUpManager;
  90.         // $this->coreManager = $this->serviceContainer->get('office_brain_core_manager');
  91.         $this->coreManager $this->coreManager;
  92.         // $this->subShopManager = $this->serviceContainer->get('office_brain_subshop_manager');        
  93.         $this->subShopManager $this->subShopManager;
  94.         // $this->biosManager = $this->serviceContainer->get('office_brain_bios_manager');
  95.         $this->biosManager $this->biosManager;
  96.         
  97.         // $this->orderManager = $this->serviceContainer->get('office_brain_order_manager');
  98.         $this->orderManager $this->orderManager;
  99.         // $this->requestQuoteManager = $this->serviceContainer->get('office_brain_request_quote_manager');
  100.         $this->requestQuoteManager $this->requestQuoteManager;
  101.         $userId $this->projectSetting['user_id'];
  102.         
  103.         // if ($userId > 0) {
  104.         //     $this->wishListManager = $this->container->get('office_brain_wish_list_registered_extended');
  105.         // } else {
  106.         //     $this->wishListManager = $this->container->get('office_brain_wish_list_guest_extended');
  107.         // }
  108.         // $this->wishListManager = $this->serviceContainer->get('office_brain_wish_list_manager'); // symfony 4
  109.         $this->wishListManager $this->wishListManager;
  110.         
  111.         
  112.         $this->formErrorManager = new FormErrorManager\JsonError();
  113.         if ($this->queueApiManager) {
  114.             $this->request->attributes->set('object''User');
  115.             $this->queueApiManager $this->queueApiManager;
  116.         }
  117.     }
  118.     /**
  119.      * @author Employee Id: 4273
  120.      * OB eCommerce Product - Login
  121.      * Function created to view my account Info
  122.      *
  123.      * @Route("/{_locale}/my-account/info",
  124.      *     name="office_brain_userbundle_user_my_account_info",
  125.      *  options={"expose"=true}, methods={"GET"}
  126.      * )
  127.      * @Template("OfficeBrain/Bundle/UserBundle/User/myAccountInfo.html.twig")
  128.      */
  129.     public function myAccountInfoAction(Request $request)
  130.     {
  131.         $this->initAction($request);
  132.         $data = array();
  133.         $user $this->projectUserSetting['user_data'];
  134.         $data['wish_list_count'] = $this->wishListManager->getTotalCount();
  135.         $data['request_quote_list_count'] =($this->userId==0) ? :count($this->requestQuoteManager->getRequestQuoteList());
  136.         $this->prepareSearchParameterArray();
  137.         $data['order_list_count'] = ($this->userId==0) ? :count($this->orderManager->getOrderList($this->searchParameterArray,$this->searchKeyWordsArray));
  138.         
  139.         $refererUrl=$this->request->headers->get('referer');
  140.         if(!empty($refererUrl)){
  141.             $this->session->set('current_redirect_url'$refererUrl);
  142.         }
  143.         return $data;
  144.     }
  145.     /**
  146.      * @author Employee Id: 4217
  147.      * OB eCommerce Product - preapre  search parameter
  148.      */
  149.     private function prepareSearchParameterArray()
  150.     {
  151.         $this->option $this->request->get('option'null);
  152.         $this->keywords $this->request->get('keyword'null);
  153.         $this->searchKeyWordsArray[$this->option]=trim($this->keywords);
  154.             
  155.     }
  156.     /**
  157.      * @author Employee Id: 4273
  158.      * OB eCommerce Product - Login
  159.      * Function created to show edit info form
  160.      *
  161.      * @Route("/{_locale}/my-account/edit-info",
  162.      *     name="office_brain_userbundle_user_my_account_edit",
  163.      *  options={"expose"=true}, methods={"GET"}
  164.      * )
  165.      * @Template("OfficeBrain/Bundle/UserBundle/User/myAccountEdit.html.twig")
  166.      */
  167.     public function myAccountEditAction(Request $request)
  168.     {
  169.         $this->initAction($request);
  170.         $data = array();
  171.         $user $this->projectUserSetting['user_data'];
  172.         $userType $user->getUserType();
  173.         $signUpFormFields $this->signUpManager->getsignUpFormData($userType);
  174.         $userTypeObj = new UserType($this->coreManager$signUpFormFields'main_edit');
  175.         $form $this->createForm($userTypeObj$user);
  176.         $form_photo $this->createForm(new UserPhotoType(), $user);
  177.         $data['form_user'] = $form->createView();
  178.         $data['form_fields'] = $signUpFormFields;
  179.         $data['form_photo'] = $form_photo->createView();
  180.         $data['states'] = $this->coreManager->getStateData($user->getCountryId());
  181.         $data['distributors'] = $this->userManager->getDistributors();        
  182.         return $data;
  183.     }
  184.     /**
  185.      * @author Employee Id: 4273
  186.      * OB eCommerce Product - Login
  187.      * Function created to save edit info
  188.      *
  189.      * @Route("/{_locale}/my-account/edit-info",
  190.      *     name="office_brain_userbundle_user_my_account_edit_post",
  191.      *  options={"expose"=true}, methods={"POST"}
  192.      * )
  193.      * @Template("OfficeBrain/Bundle/UserBundle/User/myAccountEdit.html.twig")
  194.      */
  195.     public function myAccountEditPostAction(Request $request)
  196.     {
  197.         $this->initAction($request);
  198.         $data = array();
  199.         $errors '';
  200.         $user $this->projectUserSetting['user_data'];
  201.         $userType $user->getUserType();
  202.         $signUpFormFields $this->signUpManager->getsignUpFormData($userType);
  203.         $userTypeObj = new UserType($this->coreManager$signUpFormFields'main_edit');
  204.         $isIndividual $user->getIsIndividual(); 
  205.         $form $this->createForm($userTypeObj$user);
  206.         $form->handleRequest($this->request);
  207.         $form_photo $this->createForm(new UserPhotoType(), $user);
  208.         $form->getData()->setIsIndividual($isIndividual); // for admin issue
  209.         $userStatus $this->userManager->editUser($form);
  210.         
  211.         if ($userStatus) {
  212.             $erpIntegration $this->projectSetting['configuration_rule']['erp_integration'];
  213.             $is_individual $userStatus->getIsIndividual();
  214.             $erp_flag TRUE;
  215.             $user_type $userStatus->getUserType();
  216.             if (($user_type == 'end_user' && $this->projectSetting['instance_type'] == 'supplier') || ($is_individual == TRUE && $this->projectSetting['instance_type'] == 'supplier')) {
  217.                 $erp_flag FALSE;
  218.             }
  219.             if ($erpIntegration && $erpIntegration['userManagement'] == && !empty($this->queueApiManager) && $userStatus->getErpId()>&& $erp_flag == TRUE ) {
  220.                 $this->queueApiManager->mapQueue("update"$userStatus);
  221.             }
  222.             $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.my_account_edit.success_msg'));
  223.             return $this->redirect($this->generateUrl('office_brain_userbundle_user_my_account_info'));
  224.         }
  225.         $data['form_user'] = $form->createView();
  226.         $data['form_fields'] = $signUpFormFields;
  227.         $data['form_photo'] = $form_photo->createView();
  228.         $data['states'] = $this->coreManager->getStateData($user->getCountryId());
  229.         $data['distributors'] = $this->userManager->getDistributors();        
  230.         if ($this->request->isXmlHttpRequest()) {
  231.             if ($this->request->get('call_type')=='country_code' || $this->request->get('call_type')=='state_code') {
  232.                 return $data;
  233.             } else {
  234.                 $errors = array(
  235.                         'form_name' => $form->getName(),
  236.                         'form_status' => 'error',
  237.                         'form_errors' => $this->formErrorManager->prepareErrorArray($this->get('validator')->validate($form))
  238.                 );
  239.                 return new JsonResponse($errors);
  240.             }
  241.         }
  242.         return $data;
  243.     }
  244.     /**
  245.      * @author Employee Id: 4273
  246.      * OB eCommerce Product - Login
  247.      * Function created to save edit info
  248.      *
  249.      * @Route("/{_locale}/my-account/edit-photo",
  250.      *     name="office_brain_userbundle_user_my_account_edit_photo",
  251.      *  options={"expose"=true}, methods={"POST"}
  252.      * )
  253.      * @Template()
  254.      */
  255.     public function myAccountEditPhotoAction(Request $request)
  256.     {
  257.         $this->initAction($request);
  258.         $data = array();
  259.         $errors '';
  260.         $user $this->projectUserSetting['user_data'];
  261.         $form_photo $this->createForm(UserPhotoType::class, $user);
  262.         $form_photo->handleRequest($this->request);
  263.         if ($form_photo->isValid()) {
  264.             $this->coreService=$this->get("office_brain_core_manager");
  265.             // $this->location=$this->get('kernel')->getRootDir().'/../web/images/uploads/'; // symfony 4 Image path change
  266.             $this->location=$this->get('kernel')->getRootDir().'/../public/images/uploads/';
  267.             $this->coreService->setLocationPath($this->location);
  268.             $this->parameter $this->userConfigrations['user_photo_upload_parameter'];
  269.             $code=$this->coreService->uploadImage($this->parameter$form_photo->getData()->getPhoto(), 'user_photo');
  270.             switch ($code) {
  271.                         case 'SUCCESS':
  272.                             $data['success'] = $this->get('translator')->trans('user.my_account_edit.upload_error.success');
  273.                             break;
  274.                         case 'FAIL':
  275.                             $data['error'] = $this->translator->trans('user.my_account_edit.upload_error.fail');
  276.                             break;
  277.                         case 'TYPE':
  278.                             $data['error'] = $this->translator->trans('user.my_account_edit.upload_error.type');
  279.                             break;
  280.                         case 'SIZE':
  281.                             $data['error'] = $this->translator->trans('user.my_account_edit.upload_error.size', array('%img_size%' => $this->parameter['size'] ));
  282.                             break;
  283.                         case 'HEIGHT':
  284.                             $data['error'] = $this->translator->trans('user.my_account_edit.upload_error.widthheight', array('%img_width%' => $this->parameter['width'],'%img_height%' => $this->parameter['height'] ));
  285.                             break;
  286.                         case 'WIDTH':
  287.                             $data['error'] = $this->translator->trans('user.my_account_edit.upload_error.widthheight', array('%img_width%' => $this->parameter['width'],'%img_height%' => $this->parameter['height'] ));
  288.                             break;
  289.                     }
  290.             if ($code=='SUCCESS') {
  291.                 $userPhoto=$this->userManager->editUserPhoto($form_photo->getData());
  292.                 $data['userPhoto'] = 'uploads/user_photo/'.$userPhoto;
  293.             }
  294.         } else {
  295.             $data['error'] = $this->translator->trans('user.my_account_edit.upload_error.fail');
  296.         }
  297.         if ($this->request->isXmlHttpRequest()) {
  298.             return new JsonResponse($data);
  299.         }
  300.         return $data;
  301.     }
  302.     /**
  303.      * @author Employee Id: 4273
  304.      * OB eCommerce Product - Locate Distributor
  305.      * Function created to show locate distributor form
  306.      *
  307.      * @Route("/{_locale}/my-account/locate-distributor",
  308.      *     name="office_brain_userbundle_user_my_account_locate_distributor",
  309.      *  options={"expose"=true}, methods={"GET"}
  310.      * )
  311.      * @Template("OfficeBrain/Bundle/UserBundle/User/myAccountLocateDistributor.html.twig")
  312.      */
  313.     public function myAccountLocateDistributorAction(Request $request)
  314.     {
  315.         $this->initAction($request);
  316.         $data = array();
  317.         
  318.         $locateConfig $this->userConfigrations $this->projectSetting['configuration_rule']['user']['locate_distributor'];
  319.         $form $this->createForm(new LocateDistributorType($this->coreManager->getLocateDistributorStateData(), $locateConfig),$this->user);
  320.         $data['form'] = $form->createView();
  321.         $data['distributors'] = $this->userManager->getDistributors();
  322.         $data['locatedDistributorId'] = $this->user->getLocatedDistributorId();        
  323.         return $data;
  324.     }
  325.     /**
  326.      * @author Employee Id: 4273
  327.      * OB eCommerce Product - Locate Distributor
  328.      * Function created to show locate distributor form
  329.      *
  330.      * @Route("/{_locale}/my-account/locate-distributor",
  331.      *     name="office_brain_userbundle_user_my_account_locate_distributor_post",
  332.      *  options={"expose"=true}, methods={"POST"}
  333.      * )
  334.      * @Template("OfficeBrain/Bundle/UserBundle/User/myAccountLocateDistributor.html.twig")
  335.      */
  336.     public function myAccountLocateDistributorPostAction(Request $request)
  337.     {
  338.         $this->initAction($request);
  339.         $data = array();
  340.         $locateConfig $this->userConfigrations $this->projectSetting['configuration_rule']['user']['locate_distributor'];
  341.         $form $this->createForm(new LocateDistributorType($this->coreManager->getLocateDistributorStateData(), $locateConfig),$this->user);
  342.         $form->handleRequest($this->request);
  343.         if ($form->isValid()) {
  344.             $locateDistributor $this->userManager->editLocateDistributor($this->user);
  345.             if($locateDistributor){
  346.                 $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.locate_distributor.success_msg'));
  347.             }
  348.             return $this->redirect($this->generateUrl('office_brain_userbundle_user_my_account_locate_distributor'));
  349.         }
  350.         $errors = array(
  351.                 'form_name' => $form->getName(),
  352.                 'form_status' => 'error',
  353.                 'form_errors' => $this->formErrorManager->prepareErrorArray($this->get('validator')->validate($form))
  354.         );
  355.         if ($this->request->isXmlHttpRequest()) {
  356.             return new JsonResponse($errors);
  357.         }
  358.         $data['errors'] = $errors;
  359.         $data['form'] = $form->createView();
  360.         $filter['zipcode'] = $this->request->get('zipcode');
  361.         $filter['stateId'] = $this->request->get('stateId');
  362.         $data['distributors'] = $this->userManager->getDistributors($filter);
  363.         return $data;
  364.     }
  365.     /**
  366.      * @author Employee Id: 4273
  367.      * OB eCommerce Product - User
  368.      * Function created to change distributor dropdown
  369.      *
  370.      * @Route("/{_locale}/change-distributor",
  371.      *     name="office_brain_userbundle_user_change_distributor",
  372.      *  options={"expose"=true}, methods={"POST"}
  373.      * )
  374.      * @Template()
  375.      */
  376.     public function changeDistributorAction(Request $request)
  377.     {
  378.         $this->initAction($request);
  379.         $data = array();
  380.         $errors '';
  381.         $filter['zipcode'] = $this->request->get('zipcode');
  382.         $filter['stateId'] = $this->request->get('stateId');
  383.         $data['distributors'] = $this->userManager->getDistributors($filter);
  384.         if ($this->request->isXmlHttpRequest()) {
  385.             return new JsonResponse($data);
  386.         }
  387.         return $data;
  388.     }
  389.     
  390.     
  391.     
  392.     /**
  393.      * @author Employee Id: 4493
  394.      * OB eCommerce Product - User
  395.      * Function created to find distributor
  396.      *
  397.      * @Route("/{_locale}/find-distributor",
  398.      *     name="office_brain_userbundle_user_find_distributor",
  399.      *  options={"expose"=true}, methods={"GET"}
  400.      * )
  401.      * @Template("OfficeBrain/Bundle/UserBundle/User/findDistributorSite.html.twig")
  402.      */
  403.     public function findDistributorSiteAction(Request $request)
  404.     {
  405.         $this->initAction($request);
  406.         $zipcode $this->request->get('zipcode');         
  407.         //$this->responseArray['distributor'] = $this->userManager->getStateWiseDistributors($this->page,$this->distributorRecordsPerPage);
  408.         $this->responseArray['distributor'] = $this->subShopManager->getStateWiseDistributorsSite($this->page,$this->distributorRecordsPerPage,$zipcode);
  409.                 
  410.         return $this->responseArray;        
  411.     }
  412.     
  413.     /**
  414.      * @author Employee Id: 5051
  415.      * Function created for Employee Information
  416.      *
  417.      * @Route("/{_locale}/bios",
  418.      *     name="office_brain_userbundle_user_getemployeeinfo"
  419.      * )
  420.      * @Template("OfficeBrain/Bundle/UserBundle/User/bios.html.twig")
  421.      */
  422.     
  423.     public function getEmployeeInfoAction(Request $request)
  424.     {
  425.         $this->initAction($request);
  426.         $data = array();
  427.         if($this->userId==0){
  428.          if ($this->request->isXmlHttpRequest()) {
  429.                 $this->responseArray['error_type'] = 'loginError';
  430.                 $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
  431.                 return new JsonResponse($this->responseArray);
  432.             }else{
  433.                 return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
  434.             }
  435.         }else{    
  436.                 //echo $this->companyId; die;
  437.                 $data['employeeInfo']=$this->biosManager->getEmployeeDetails($this->companyId);
  438.         }
  439.          return $data;
  440.     }
  441.     /**
  442.      * @author Employee Id: 4074
  443.      * 
  444.      * Function to get welcome user top menu section
  445.      *
  446.      * @Route("/{_locale}/get-welcome-user-top-menu-section",
  447.      *     name="office_brain_userbundle_user_getwelcomeusertopmenusection",
  448.      *  options={"expose"=true}
  449.      * )
  450.      * 
  451.      * @Template("OfficeBrain/Bundle/UserBundle/User/getWelcomeUserTopMenuSection.html.twig")
  452.      * 
  453.      */
  454.     public function getWelcomeUserTopMenuSectionAction(Request $request)
  455.     {
  456.         return array();
  457.     }
  458. }