src/project/OfficeBrain/CustomBundle/UserBundle/Controller/SignUpController.php line 118

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\OfficeBrain\Bundle\UserBundle\Controller\SignUpController as baseSignUpController;
  8. use App\OfficeBrain\Bundle\UserBundle\Entity\User;
  9. // use App\project\OfficeBrain\CustomBundle\UserBundle\Entity\User; // change project user entity
  10. use App\project\OfficeBrain\CustomBundle\UserBundle\Form\UserType;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
  14. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\SignUpService;
  15. use App\project\OfficeBrain\CustomBundle\UserBundle\Manager\Service\SignUpService as CustomSignUpService;
  16. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\LoginService;
  17. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
  18. use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueManager;
  19. use App\OfficeBrain\Bundle\CompanyBundle\Manager\Service\CompanyService;
  20. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  21. class SignUpController extends baseSignUpController
  22. {
  23.     /**
  24.      *
  25.      * @author Employee Id: 4273
  26.      * To set member variables default value
  27.      *
  28.      * @return NULL
  29.      */
  30.     public function __construct(Container $serviceContainerCoreService $coreServiceSignUpService $signUpServiceCustomSignUpService $customSignUpServiceLoginService $loginServiceUserService $userServiceQueueManager $queueApiManagerCompanyService $companyService)
  31.     {
  32.         parent::__construct($serviceContainer$coreService$signUpService$loginService$userService$queueApiManager);
  33.         $this->customSignUpManager $customSignUpService->getSignUpExtended();
  34.         $this->companyService $companyService->getCompanyExtended();
  35.         $this->userService $userService->getUserExtended();
  36.     }
  37.     
  38.     public function __destruct()
  39.     {
  40.         parent::__destruct();
  41.     }
  42.     
  43.     public function initAction(Request $request){
  44.         parent::initAction($request);
  45.         // $this->signUpManager = $this->serviceContainer->get('office_brain_user_sign_up_manager_custom');
  46.         $this->signUpManager $this->customSignUpManager;
  47.         // $this->companyManager = $this->serviceContainer->get('office_brain_company_manager');
  48.         $this->companyManager $this->companyService;
  49.         // $this->userManagerCore = $this->serviceContainer->get('office_brain_user_manager');
  50.         $this->userManagerCore $this->userService;
  51.     }
  52.      
  53.     /**
  54.      * @author Employee Id: 4203
  55.      * OB eCommerce Product - auto suggest company list
  56.      *
  57.      * @Route("/{_locale}/fetch-company",
  58.      *     name="office_brain_userbundle_sign_up_fetchCompany",
  59.      *  options={"expose"=true}
  60.      * )
  61.      * @Method({"GET"})
  62.      */ 
  63.     public function fetchCompanyAction(Request $request)
  64.     {
  65.         //$this->initAction($request);
  66.         $this->request null;
  67.         $this->responseArray null;
  68.         $this->request $request;
  69.         $this->companyManager $this->serviceContainer->get('office_brain_company_manager');
  70.         $this->userManagerCore $this->serviceContainer->get('office_brain_user_manager');
  71.         
  72.         $query $this->request->get('q',NULL); 
  73.         $company $this->request->get('companyName',NULL); 
  74.         $account_id $this->request->get('account_id',NULL);
  75.         if($query!=NULL){
  76.             $this->responseArray $this->companyManager->autoSearchCompany($query);
  77.             if(count($this->responseArray)>0){
  78.                 return new Response($_GET['callback'] . '('.json_encode($this->responseArray).')');    
  79.             }else{
  80.                 $this->responseArray = array();
  81.                 return new Response($_GET['callback'] . '('.json_encode($this->responseArray).')');    
  82.             }
  83.         }
  84.         if($company!=NULL && $account_id!=NULL){
  85.             $companies $this->companyManager->getCompanyByNameSearch($company);
  86.             if(count($companies)>0){
  87.                 $value $companies[0]->getId();
  88.             }else{
  89.                 $userObj $this->userManagerCore->getUserById(1); //1- admin user id 
  90.                 $cmpObject $this->companyManager->addNewCompanyData($userObj,$company,$account_id);
  91.                 $value $cmpObject->getId();
  92.             }
  93.             $this->responseArray = array();
  94.             $this->responseArray['value'] = $value;
  95.             $this->responseArray['label'] = $company;
  96.             $this->responseArray['account_id'] = $account_id;
  97.             return new Response($_GET['callback'] . '('.json_encode($this->responseArray).')');    
  98.         }
  99.     }
  100.     
  101.     
  102.     /**
  103.      * @author Employee Id: 4273
  104.      * OB eCommerce Product - SignUp
  105.      * Function created to show sign up form
  106.      *
  107.      * @Route("/{_locale}/distributor-registration",
  108.      *     name="office_brain_userbundle_sign_up_distributor_registration",
  109.      *  options={"expose"=true}
  110.      * )
  111.      * @Method({"GET"})
  112.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/SignUp/register.html.twig")
  113.      */
  114.     
  115.     public function distributorRegistrationAction(Request $request)
  116.     {
  117.         $this->initAction($request);
  118.         $data = array();    
  119.         
  120.         $userType 'distributor';
  121.         $signUpFormFields $this->signUpManager->getsignUpFormData($userType);
  122.         $user = new User();
  123.         // $userTypeObj = new UserType($this->coreManager, $signUpFormFields, 'main_register'); // symfony 4
  124.         // $form = $this->createForm($userTypeObj, $user); // symfony 4
  125.         $form $this->createForm(UserType::class, $user, [
  126.             'core_manager' => $this->coreManager,
  127.             'form_fields' => $signUpFormFields,
  128.             'form_type' => 'main_register',
  129.         ]);
  130.         $form->handleRequest($this->request);
  131.         $data['form_user'] = $form->createView();
  132.         $data['userType'] = $userType;
  133.         $data['form_fields'] = $signUpFormFields;
  134.         $data['states'] = $this->coreManager->getStateData();
  135.         $data['distributors'] = null;//$this->userManager->getDistributors();
  136.         return $data;
  137.     }
  138.     /**
  139.      * @author Employee Id: 4273
  140.      * OB eCommerce Product - SignUp
  141.      * Function created to validate sign up form
  142.      *
  143.      * @Route("/{_locale}/register",
  144.      *     name="office_brain_userbundle_sign_up_register_post",
  145.      *  options={"expose"=true}
  146.      * )
  147.      *
  148.      * @Method({"POST"})
  149.      * @Template("project/OfficeBrain/CustomBundle/UserBundle/SignUp/register.html.twig")
  150.      */
  151.     
  152.     public function registerPostAction(Request $request)
  153.     {
  154.         $this->initAction($request);
  155.         $data = array();
  156.         $format $this->request->get('_format''html') ;
  157.         $userType $this->request->get('userType''supplier');
  158.         $signUpFormFields $this->signUpManager->getsignUpFormData($userType);
  159.         $requestarray=$this->request->request->all();
  160.         if(isset($requestarray['ob_user']) && $requestarray['ob_user']['countryId']=='739')
  161.         {
  162.             unset($signUpFormFields['validations'][7]);
  163.             unset($signUpFormFields['validations'][8]);
  164.             unset($signUpFormFields['validations'][9]);
  165.             $data['othercountry']=1;
  166.         }
  167.         $user = new User();
  168.         //echo "<pre>";print_R();die;
  169.         // $userTypeObj = new UserType($this->coreManager, $signUpFormFields, 'main_register'); // symfony 4
  170.         // $form = $this->createForm($userTypeObj, $user); // symfony 4
  171.         
  172.         $form $this->createForm(UserType::class, $user, [
  173.             'core_manager' => $this->coreManager,
  174.             'form_fields' => $signUpFormFields,
  175.             'form_type' => 'main_register',
  176.         ]);
  177.     
  178.         $form->handleRequest($this->request);
  179.         $userStatus $this->signUpManager->registerUser($form);
  180.         // echo "<pre>";print_r($this->getErrorsAsArray($form));die;
  181.         if ($userStatus) { 
  182.             $user $userStatus;
  183.             $userObj $this->userManagerCore->getUserById($userStatus->getId());
  184.             // $companyObj = $this->companyManager->addNewCompanyData($userObj,$userStatus->getUserCompany()->getCompanyName(),$userStatus->getUserCompany()->getTioryCustomerAccountId()); // symfony 4
  185.             // $this->    ->updateUserCompany($userObj,$companyObj, $companyObj->getCompanyName()); // symfony 4
  186.             $erp_flag TRUE;
  187.             $user_type $userStatus->getUserType();
  188.             $is_individual $userStatus->getIsIndividual();
  189.             if (($user_type == 'end_user' && $this->projectSetting['instance_type'] == 'supplier') || ($is_individual == TRUE && $this->projectSetting['instance_type'] == 'supplier')) {
  190.                 $erp_flag FALSE;
  191.             }
  192.             $erpIntegration $this->projectSetting['configuration_rule']['erp_integration'];
  193.             if ($erpIntegration && $erpIntegration['userManagement'] == && !empty($this->queueApiManager) && $userStatus->getuserCompany() && ($userStatus->getStatus()=="active" || $userStatus->getStatus()=="inactive") && $erp_flag == TRUE) {
  194.                 $this->queueApiManager->mapQueue("create"$userStatus);
  195.             }
  196.     
  197.             //if ($this->request->get('billing_address')) {
  198.             //$billingArray['id'] = 1; $billingArray['default'] = $this->request->get('billing_address',null);
  199.             $billingAddressId 1;
  200.             $billingAddress $this->signUpManager->addAddress($user$billingAddressId);
  201.             if ($erpIntegration && $erpIntegration['userManagement'] == && !empty($this->queueApiManager) && $userStatus->getuserCompany() && ($userStatus->getStatus()=="active" || $userStatus->getStatus()=="inactive") && $erp_flag == TRUE) {
  202.                 $this->request->attributes->set('object''ContactBook');
  203.                 $this->queueApiManager->mapQueue("create"$billingAddress);
  204.             }
  205.             //}
  206.             //if ($this->request->get('shipping_address')) {
  207.             //$shippingArray['id'] = 2;$shippingArray['default'] = $this->request->get('shipping_address',null);
  208.                 $shippingAddressId 2;
  209.                 $shippingAddress $this->signUpManager->addAddress($user$shippingAddressId);
  210.                 if ($erpIntegration && $erpIntegration['userManagement'] == && !empty($this->queueApiManager) && ($userStatus->getStatus()=="active" || $userStatus->getStatus()=="inactive") && $userStatus->getuserCompany() && $erp_flag == TRUE) {
  211.                     $this->request->attributes->set('object''ContactBook');
  212.                     $this->queueApiManager->mapQueue("create"$shippingAddress);
  213.                 }
  214.                 //}
  215.     
  216.                 $this->signUpManager->sendEmail($form$this->translator->trans('user.register.mail.subject'));
  217.     
  218.                 if ($signUpFormFields['approval_configuration']['is_auto_approve']->option->approval_email==1) {
  219.                     $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.register.success'));
  220.                 } else {
  221.                     $this->get('session')->getFlashBag()->set('success_message'$this->translator->trans('user.register.success'));
  222.                 }
  223.                 if ($this->signUpConfigrations['option']['allow_login_after_signup']==1) {
  224.                     $this->loginManager->doLogin($form);
  225.     
  226.                     return $this->redirect($this->generateUrl($this->projectSetting['configuration_rule']['user']['login']['option']['after_login_url']));
  227.                 } else {
  228.     
  229.                     return $this->redirect($this->generateUrl('office_brain_page_homepage_view'));
  230.                 }
  231.             }
  232.     
  233.             $data['form_user'] = $form->createView();
  234.             $data['userType'] = $userType;
  235.             $data['form_fields'] = $signUpFormFields;
  236.             $data['states'] = $this->coreManager->getStateData();
  237.             $data['distributors'] = null;//$this->userManager->getDistributors();
  238.     
  239.             if ($this->request->isXmlHttpRequest()) {
  240.                 if ($this->request->get('call_type')=='country_code' || $this->request->get('call_type')=='state_code') {
  241.                     return $data;
  242.                 } else {
  243.                     $errors = array(
  244.                             'form_name' => $form->getName(),
  245.                             'form_status' => 'error',
  246.                             'form_errors' => $this->formErrorManager->prepareErrorArray($this->get('validator')->validate($form))
  247.                     );
  248.                     return new JsonResponse($errors);
  249.                 }
  250.             }
  251.     
  252.             return $data;
  253.         }
  254.     public function getErrorsAsArray($form)
  255.     {
  256.         $errors = array();
  257.         foreach ($form->getErrors() as $error) {
  258.             $errors[] = $error->getMessage();
  259.         }
  260.     
  261.         foreach ($form->all() as $key => $child) {
  262.             if ($err $this->getErrorsAsArray($child)) {
  263.                 $errors[$key] = $err;
  264.             }
  265.         }
  266.     
  267.         return $errors;
  268.     }
  269. }