<?php
namespace App\OfficeBrain\Bundle\UserBundle\Controller;
// use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use App\OfficeBrain\Bundle\CoreBundle\CustomeHandler as FormErrorManager;
use App\OfficeBrain\Bundle\UserBundle\Entity\User;
use App\OfficeBrain\Bundle\UserBundle\Form\UserType;
use App\OfficeBrain\Bundle\UserBundle\Form\UserPhotoType;
use App\OfficeBrain\Bundle\UserBundle\Form\LocateDistributorType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\SignUpService;
use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
use App\OfficeBrain\Bundle\SubShopBundle\Manager\Service\SubShopService;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\BiosService;
use App\OfficeBrain\Bundle\OrderBundle\Manager\Service\OrderService;
use App\OfficeBrain\Bundle\WishListBundle\Manager\Service\WishListService;
use App\OfficeBrain\Bundle\RequestQuoteBundle\Manager\Service\RequestQuoteService;
use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
class UserController extends AbstractController
{
/**
* @author Employee Id: 4834
* set default value
* @return NULL
*/
public function __construct(ContainerInterface $container, UserService $userService, SignUpService $signUpService, CoreService $coreService, SubShopService $subShopService, BiosService $biosService, OrderService $orderService, WishListService $wishlistService, RequestQuoteService $requestQuoteService, QueueApiManager $queueApiManager)
{
$this->queueApiManager = $queueApiManager->getQueueInstance();
$this->userManager = $userService->getUserExtended();
$this->signUpManager = $signUpService->getSignUpExtended();
$this->coreManager = $coreService->getCoreExtended();
$this->subShopManager = $subShopService->getSubShopExtended();
$this->biosManager = $biosService->getUserBiosExtended();
$this->orderManager = $orderService->getOrderManagerExtended();
$this->wishListManager = $wishlistService->getWishlistManagerExtended();
$this->requestQuoteManager = $requestQuoteService->getRequestQuoteManager();
$this->searchParameterArray = array();
$this->searchKeyWordsArray = array();
$this->serviceContainer = $container;
}
/**
* @author Employee Id: 4834
* unset default value
* @return NULL
*/
public function __destruct()
{
unset($this->queueApiManager);
unset($this->biosManager);
unset($this->searchParameterArray);
unset($this->searchKeyWordsArray);
unset($this->serviceContainer);
}
/**
*
* @author Employee Id: 4273
*
* Create various objects required action in this class
*
* @return NULL
*/
public function initAction(Request $request)
{
$this->request = $request;
$this->translator = $this->serviceContainer->get('translator');
$this->session = $this->request->getSession();
$this->projectSetting = $this->request->get('project_setting');
$this->projectUserSetting = $this->request->get('project_user_setting');
$this->userConfigrations = $this->projectSetting['configuration_rule']['user']['user'];
$this->findDistributorConfigrations = $this->projectSetting['configuration_rule']['user']['find_distributor'];
$this->distributorRecordsPerPage = $this->projectSetting['configuration_rule']['user']['find_distributor']['option']['no_of_record_per_page'];
$this->page = $this->request->get('page',1);
$this->userId = $this->projectSetting['user_id'];
$this->user = $this->projectUserSetting['user_data'];
$this->companyId = $this->serviceContainer->getParameter('company_id');
// $this->userManager = $this->serviceContainer->get('office_brain_user_manager');
$this->userManager = $this->userManager;
// $this->signUpManager = $this->serviceContainer->get('office_brain_user_sign_up_manager');
$this->signUpManager = $this->signUpManager;
// $this->coreManager = $this->serviceContainer->get('office_brain_core_manager');
$this->coreManager = $this->coreManager;
// $this->subShopManager = $this->serviceContainer->get('office_brain_subshop_manager');
$this->subShopManager = $this->subShopManager;
// $this->biosManager = $this->serviceContainer->get('office_brain_bios_manager');
$this->biosManager = $this->biosManager;
// $this->orderManager = $this->serviceContainer->get('office_brain_order_manager');
$this->orderManager = $this->orderManager;
// $this->requestQuoteManager = $this->serviceContainer->get('office_brain_request_quote_manager');
$this->requestQuoteManager = $this->requestQuoteManager;
$userId = $this->projectSetting['user_id'];
// if ($userId > 0) {
// $this->wishListManager = $this->container->get('office_brain_wish_list_registered_extended');
// } else {
// $this->wishListManager = $this->container->get('office_brain_wish_list_guest_extended');
// }
// $this->wishListManager = $this->serviceContainer->get('office_brain_wish_list_manager'); // symfony 4
$this->wishListManager = $this->wishListManager;
$this->formErrorManager = new FormErrorManager\JsonError();
if ($this->queueApiManager) {
$this->request->attributes->set('object', 'User');
$this->queueApiManager = $this->queueApiManager;
}
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - Login
* Function created to view my account Info
*
* @Route("/{_locale}/my-account/info",
* name="office_brain_userbundle_user_my_account_info",
* options={"expose"=true}, methods={"GET"}
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/myAccountInfo.html.twig")
*/
public function myAccountInfoAction(Request $request)
{
$this->initAction($request);
$data = array();
$user = $this->projectUserSetting['user_data'];
$data['wish_list_count'] = $this->wishListManager->getTotalCount();
$data['request_quote_list_count'] =($this->userId==0) ? 0 :count($this->requestQuoteManager->getRequestQuoteList());
$this->prepareSearchParameterArray();
$data['order_list_count'] = ($this->userId==0) ? 0 :count($this->orderManager->getOrderList($this->searchParameterArray,$this->searchKeyWordsArray));
$refererUrl=$this->request->headers->get('referer');
if(!empty($refererUrl)){
$this->session->set('current_redirect_url', $refererUrl);
}
return $data;
}
/**
* @author Employee Id: 4217
* OB eCommerce Product - preapre search parameter
*/
private function prepareSearchParameterArray()
{
$this->option = $this->request->get('option', null);
$this->keywords = $this->request->get('keyword', null);
$this->searchKeyWordsArray[$this->option]=trim($this->keywords);
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - Login
* Function created to show edit info form
*
* @Route("/{_locale}/my-account/edit-info",
* name="office_brain_userbundle_user_my_account_edit",
* options={"expose"=true}, methods={"GET"}
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/myAccountEdit.html.twig")
*/
public function myAccountEditAction(Request $request)
{
$this->initAction($request);
$data = array();
$user = $this->projectUserSetting['user_data'];
$userType = $user->getUserType();
$signUpFormFields = $this->signUpManager->getsignUpFormData($userType);
$userTypeObj = new UserType($this->coreManager, $signUpFormFields, 'main_edit');
$form = $this->createForm($userTypeObj, $user);
$form_photo = $this->createForm(new UserPhotoType(), $user);
$data['form_user'] = $form->createView();
$data['form_fields'] = $signUpFormFields;
$data['form_photo'] = $form_photo->createView();
$data['states'] = $this->coreManager->getStateData($user->getCountryId());
$data['distributors'] = $this->userManager->getDistributors();
return $data;
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - Login
* Function created to save edit info
*
* @Route("/{_locale}/my-account/edit-info",
* name="office_brain_userbundle_user_my_account_edit_post",
* options={"expose"=true}, methods={"POST"}
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/myAccountEdit.html.twig")
*/
public function myAccountEditPostAction(Request $request)
{
$this->initAction($request);
$data = array();
$errors = '';
$user = $this->projectUserSetting['user_data'];
$userType = $user->getUserType();
$signUpFormFields = $this->signUpManager->getsignUpFormData($userType);
$userTypeObj = new UserType($this->coreManager, $signUpFormFields, 'main_edit');
$isIndividual = $user->getIsIndividual();
$form = $this->createForm($userTypeObj, $user);
$form->handleRequest($this->request);
$form_photo = $this->createForm(new UserPhotoType(), $user);
$form->getData()->setIsIndividual($isIndividual); // for admin issue
$userStatus = $this->userManager->editUser($form);
if ($userStatus) {
$erpIntegration = $this->projectSetting['configuration_rule']['erp_integration'];
$is_individual = $userStatus->getIsIndividual();
$erp_flag = TRUE;
$user_type = $userStatus->getUserType();
if (($user_type == 'end_user' && $this->projectSetting['instance_type'] == 'supplier') || ($is_individual == TRUE && $this->projectSetting['instance_type'] == 'supplier')) {
$erp_flag = FALSE;
}
if ($erpIntegration && $erpIntegration['userManagement'] == 1 && !empty($this->queueApiManager) && $userStatus->getErpId()>0 && $erp_flag == TRUE ) {
$this->queueApiManager->mapQueue("update", $userStatus);
}
$this->get('session')->getFlashBag()->set('success_message', $this->translator->trans('user.my_account_edit.success_msg'));
return $this->redirect($this->generateUrl('office_brain_userbundle_user_my_account_info'));
}
$data['form_user'] = $form->createView();
$data['form_fields'] = $signUpFormFields;
$data['form_photo'] = $form_photo->createView();
$data['states'] = $this->coreManager->getStateData($user->getCountryId());
$data['distributors'] = $this->userManager->getDistributors();
if ($this->request->isXmlHttpRequest()) {
if ($this->request->get('call_type')=='country_code' || $this->request->get('call_type')=='state_code') {
return $data;
} else {
$errors = array(
'form_name' => $form->getName(),
'form_status' => 'error',
'form_errors' => $this->formErrorManager->prepareErrorArray($this->get('validator')->validate($form))
);
return new JsonResponse($errors);
}
}
return $data;
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - Login
* Function created to save edit info
*
* @Route("/{_locale}/my-account/edit-photo",
* name="office_brain_userbundle_user_my_account_edit_photo",
* options={"expose"=true}, methods={"POST"}
* )
* @Template()
*/
public function myAccountEditPhotoAction(Request $request)
{
$this->initAction($request);
$data = array();
$errors = '';
$user = $this->projectUserSetting['user_data'];
$form_photo = $this->createForm(UserPhotoType::class, $user);
$form_photo->handleRequest($this->request);
if ($form_photo->isValid()) {
$this->coreService=$this->get("office_brain_core_manager");
// $this->location=$this->get('kernel')->getRootDir().'/../web/images/uploads/'; // symfony 4 Image path change
$this->location=$this->get('kernel')->getRootDir().'/../public/images/uploads/';
$this->coreService->setLocationPath($this->location);
$this->parameter = $this->userConfigrations['user_photo_upload_parameter'];
$code=$this->coreService->uploadImage($this->parameter, $form_photo->getData()->getPhoto(), 'user_photo');
switch ($code) {
case 'SUCCESS':
$data['success'] = $this->get('translator')->trans('user.my_account_edit.upload_error.success');
break;
case 'FAIL':
$data['error'] = $this->translator->trans('user.my_account_edit.upload_error.fail');
break;
case 'TYPE':
$data['error'] = $this->translator->trans('user.my_account_edit.upload_error.type');
break;
case 'SIZE':
$data['error'] = $this->translator->trans('user.my_account_edit.upload_error.size', array('%img_size%' => $this->parameter['size'] ));
break;
case 'HEIGHT':
$data['error'] = $this->translator->trans('user.my_account_edit.upload_error.widthheight', array('%img_width%' => $this->parameter['width'],'%img_height%' => $this->parameter['height'] ));
break;
case 'WIDTH':
$data['error'] = $this->translator->trans('user.my_account_edit.upload_error.widthheight', array('%img_width%' => $this->parameter['width'],'%img_height%' => $this->parameter['height'] ));
break;
}
if ($code=='SUCCESS') {
$userPhoto=$this->userManager->editUserPhoto($form_photo->getData());
$data['userPhoto'] = 'uploads/user_photo/'.$userPhoto;
}
} else {
$data['error'] = $this->translator->trans('user.my_account_edit.upload_error.fail');
}
if ($this->request->isXmlHttpRequest()) {
return new JsonResponse($data);
}
return $data;
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - Locate Distributor
* Function created to show locate distributor form
*
* @Route("/{_locale}/my-account/locate-distributor",
* name="office_brain_userbundle_user_my_account_locate_distributor",
* options={"expose"=true}, methods={"GET"}
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/myAccountLocateDistributor.html.twig")
*/
public function myAccountLocateDistributorAction(Request $request)
{
$this->initAction($request);
$data = array();
$locateConfig = $this->userConfigrations = $this->projectSetting['configuration_rule']['user']['locate_distributor'];
$form = $this->createForm(new LocateDistributorType($this->coreManager->getLocateDistributorStateData(), $locateConfig),$this->user);
$data['form'] = $form->createView();
$data['distributors'] = $this->userManager->getDistributors();
$data['locatedDistributorId'] = $this->user->getLocatedDistributorId();
return $data;
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - Locate Distributor
* Function created to show locate distributor form
*
* @Route("/{_locale}/my-account/locate-distributor",
* name="office_brain_userbundle_user_my_account_locate_distributor_post",
* options={"expose"=true}, methods={"POST"}
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/myAccountLocateDistributor.html.twig")
*/
public function myAccountLocateDistributorPostAction(Request $request)
{
$this->initAction($request);
$data = array();
$locateConfig = $this->userConfigrations = $this->projectSetting['configuration_rule']['user']['locate_distributor'];
$form = $this->createForm(new LocateDistributorType($this->coreManager->getLocateDistributorStateData(), $locateConfig),$this->user);
$form->handleRequest($this->request);
if ($form->isValid()) {
$locateDistributor = $this->userManager->editLocateDistributor($this->user);
if($locateDistributor){
$this->get('session')->getFlashBag()->set('success_message', $this->translator->trans('user.locate_distributor.success_msg'));
}
return $this->redirect($this->generateUrl('office_brain_userbundle_user_my_account_locate_distributor'));
}
$errors = array(
'form_name' => $form->getName(),
'form_status' => 'error',
'form_errors' => $this->formErrorManager->prepareErrorArray($this->get('validator')->validate($form))
);
if ($this->request->isXmlHttpRequest()) {
return new JsonResponse($errors);
}
$data['errors'] = $errors;
$data['form'] = $form->createView();
$filter['zipcode'] = $this->request->get('zipcode');
$filter['stateId'] = $this->request->get('stateId');
$data['distributors'] = $this->userManager->getDistributors($filter);
return $data;
}
/**
* @author Employee Id: 4273
* OB eCommerce Product - User
* Function created to change distributor dropdown
*
* @Route("/{_locale}/change-distributor",
* name="office_brain_userbundle_user_change_distributor",
* options={"expose"=true}, methods={"POST"}
* )
* @Template()
*/
public function changeDistributorAction(Request $request)
{
$this->initAction($request);
$data = array();
$errors = '';
$filter['zipcode'] = $this->request->get('zipcode');
$filter['stateId'] = $this->request->get('stateId');
$data['distributors'] = $this->userManager->getDistributors($filter);
if ($this->request->isXmlHttpRequest()) {
return new JsonResponse($data);
}
return $data;
}
/**
* @author Employee Id: 4493
* OB eCommerce Product - User
* Function created to find distributor
*
* @Route("/{_locale}/find-distributor",
* name="office_brain_userbundle_user_find_distributor",
* options={"expose"=true}, methods={"GET"}
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/findDistributorSite.html.twig")
*/
public function findDistributorSiteAction(Request $request)
{
$this->initAction($request);
$zipcode = $this->request->get('zipcode');
//$this->responseArray['distributor'] = $this->userManager->getStateWiseDistributors($this->page,$this->distributorRecordsPerPage);
$this->responseArray['distributor'] = $this->subShopManager->getStateWiseDistributorsSite($this->page,$this->distributorRecordsPerPage,$zipcode);
return $this->responseArray;
}
/**
* @author Employee Id: 5051
* Function created for Employee Information
*
* @Route("/{_locale}/bios",
* name="office_brain_userbundle_user_getemployeeinfo"
* )
* @Template("OfficeBrain/Bundle/UserBundle/User/bios.html.twig")
*/
public function getEmployeeInfoAction(Request $request)
{
$this->initAction($request);
$data = array();
if($this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['error_type'] = 'loginError';
$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
return new JsonResponse($this->responseArray);
}else{
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
}else{
//echo $this->companyId; die;
$data['employeeInfo']=$this->biosManager->getEmployeeDetails($this->companyId);
}
return $data;
}
/**
* @author Employee Id: 4074
*
* Function to get welcome user top menu section
*
* @Route("/{_locale}/get-welcome-user-top-menu-section",
* name="office_brain_userbundle_user_getwelcomeusertopmenusection",
* options={"expose"=true}
* )
*
* @Template("OfficeBrain/Bundle/UserBundle/User/getWelcomeUserTopMenuSection.html.twig")
*
*/
public function getWelcomeUserTopMenuSectionAction(Request $request)
{
return array();
}
}