<?php
namespace App\OfficeBrain\Bundle\RequestInfoBundle\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 App\OfficeBrain\Bundle\RequestInfoBundle\Form\RequestInfoType;
use App\OfficeBrain\Bundle\RequestInfoBundle\Form\CommentRequestInfoType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\OfficeBrain\Bundle\RequestInfoBundle\Entity\GuestUser;
use App\OfficeBrain\Bundle\RequestInfoBundle\Entity\RequestInfo;
use App\OfficeBrain\Bundle\RequestInfoBundle\Entity\CommentRequestInfo;
use App\OfficeBrain\Bundle\RequestInfoBundle\Form\GuestUserType;
use App\OfficeBrain\Bundle\RequestInfoBundle\Manager\Service\RequestInfoService;
use App\OfficeBrain\Bundle\CoreBundle\Service\OBCommon;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
/**
*
* @author Employee Id: 4203
*
* OB eCommerce Product - Request Info
*
* - Do inquiry of Product
*
*/
class RequestInfoController extends AbstractController
{
protected $user;
protected $form;
protected $request;
protected $formData;
protected $responseArray;
protected $erpIntegration;
protected $queueApiManager;
protected $commonLibraryManager;
/**
*
* @author Employee Id: 4203
*
* Desciption: Define member variables with thier default value
*
* @param NULL
*
* @return NULL
*
* @throws NULL
*
*/
public function __construct(RequestInfoService $requestInfoService, RequestStack $requestStack, RouterInterface $router, ValidatorInterface $validator, CoreService $coreService, UserService $userService, QueueApiManager $queueApiManager)
{
$commonLibraryManager = new OBCommon($router, $validator, $requestStack);
$this->user = null;
$this->form = null;
$this->request = null;
$this->formData = null;
$this->erpIntegration = null;
$this->responseArray = array();
$this->queueApiManager = $queueApiManager->getQueueInstance();
$this->commonLibraryManager = $commonLibraryManager;
$this->requestInfoService = $requestInfoService->getRequestInfoManager();
$this->coreService = $coreService->getCoreExtended();
$this->locale = null;
$this->productId = null;
$this->productSlug = null;
$this->userManager = $userService->getUserExtended();
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Unset member variables
*
* @param NULL
*
* @return NULL
*
* @throws NULL
*
*/
public function __destruct()
{
unset($this->user);
unset($this->form);
unset($this->request);
unset($this->formData);
unset($this->erpIntegration);
unset($this->queueApiManager);
unset($this->commonLibraryManager);
unset($this->productId);
unset($this->productSlug);
unset($this->locale);
unset($this->productId);
unset($this->productSlug);
unset($this->locale);
unset($this->userManager);
unset($this->coreService);
unset($this->requestInfoService);
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Create and initialize various required object and member variables
*
* @param NULL
*
* @return NULL
*
* @throws NULL
*
*/
public function initAction(Request $request)
{
$this->request = $request;
$this->projectSetting = $this->request->get('project_setting');
$this->userId = $this->projectSetting['user_id'];
$this->productId = $this->request->get('product_id',null);
$this->productSlug = $this->request->get('product_slug',null);
$this->cultureId = $this->projectSetting['culture_id'];
$this->locale = $this->projectSetting['culture_code'];
$this->responseArray = array();
$this->configurationRule = $this->projectSetting['configuration_rule']['transaction']['request_info'];
// $this->requestInfoManager = $this->get('office_brain_request_info_manager');
$this->requestInfoManager = $this->requestInfoService;
// $this->commonLibraryManager = $this->get('office_brain_common_library');
$this->commonLibraryManager = $this->commonLibraryManager;
// $this->coreManager = $this->get('office_brain_core_manager');
$this->coreManager = $this->coreService;
$this->erpIntegration = $this->projectSetting['configuration_rule']['erp_integration'];
if ($this->queueApiManager) {
$this->request->attributes->set('object', 'RequestInfo');
$this->queueApiManager = $this->queueApiManager;
}
// $this->userManager = $this->get('office_brain_user_manager');
$this->userManager = $this->userManager;
}
/**
* @author Employee Id: 4203
*
* Description : Use to render request info section.
*
* @param 1 : No paramater
*
* @return type : Form view.
*
* @throws Exception: Null
*
* @Route("/{_locale}/request-info/{product_slug}",
* name="office_brain_requestinfobundle_requestinfo_productdetailrequestinfo",
* options={"expose"=true}
* )
* @Template()
* @Method({"GET"})
*/
public function productDetailRequestInfoAction(Request $request)
{
$this->initAction($request);
return $this->requestInfoManager->getProductDetailBySlug($this->productSlug, $this->locale);
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to render request info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-request-info/{product_id}",
* name="office_brain_requestinfobundle_requestinfo_addrequestinfo"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/addRequestInfo.html.twig")
*
* @Method({"GET"})
*
*/
public function addRequestInfoAction(Request $request)
{
$this->initAction($request);
// $this->form = $this->createForm(new RequestInfoType($this->configurationRule, $this->coreManager), new RequestInfo());
$this->form = $this->createForm(RequestInfoType::class, new RequestInfo(), [
'configurationRule' => $this->configurationRule,
'coreManager' => $this->coreManager,
]);
$this->responseArray['form'] = $this->form->createView();
$this->responseArray['product_id'] = $this->productId;
return $this->responseArray;
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to submit request info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-request-info",
* name="office_brain_requestinfobundle_requestinfo_processrequestinfosubmit"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/addRequestInfo.html.twig")
*
* @Method({"POST"})
*
*/
public function addRequestInfoSubmitAction(Request $request)
{
$option = null;
$this->initAction($request);
$stateId = $this->request->get('state');
$option['distributor'] = $this->getStateWiseDistributors(array('state_id'=>$stateId));
// $this->form = $this->createForm(new RequestInfoType($this->configurationRule, $this->coreManager, $option), new RequestInfo());
$this->form = $this->createForm(RequestInfoType::class, new RequestInfo(), [
'configurationRule' => $this->configurationRule,
'coreManager' => $this->coreManager,
'options' => $option,
]);
$this->form->handleRequest($this->request);
$productId = $this->form->getData()->product_id;
if ($this->form->isSubmitted() && $this->form->isValid()) {
$result = $this->requestInfoManager->setRequestInfo($this->form->getData());
switch ($result['status']) {
case 'ADD_SUCCESS_IN_SESSION':
$this->responseArray['status'] = 'success';
break;
case 'ALLREADY_IN_SESSION':
$this->responseArray['status'] = 'error';
break;
case 'ADD_SUCCESS_SINGLE_GUEST':
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'success';
$this->responseArray['popup_url'] = $this->generateUrl('office_brain_userbundle_login_login_popup',array('refer_url'=>'office_brain_requestinfobundle_requestinfo_addgguestuser'));
}
break;
case 'ADD_RECORD_SUCCESSFULLY':
if ($this->request->isXmlHttpRequest()) {
$requestInfoObj = $result['data'];
if (is_array($this->erpIntegration) && $this->erpIntegration['orderManagement'] == 1 && !empty($this->queueApiManager)) {
if ($requestInfoObj->getGuestId() == 0) {
$this->queueApiManager->mapQueue("create", $requestInfoObj);
}
}
$this->requestInfoManager->sendRequestInfoEmail($requestInfoObj);
$this->responseArray['status'] = 'success';
$this->responseArray['goto_url'] = $this->generateUrl('office_brain_requestinfobundle_requestinfo_thankupage');
unset($requestInfoObj);
}
break;
}
unset($result);
unset($requestInfo);
return new JsonResponse($this->responseArray);
} elseif ($this->request->isXmlHttpRequest()) {
return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form));
}
return array('form' => $this->form->createView(), 'product_id'=>$productId);
}
private function getStateWiseDistributors($stateId){
$returnDistributors = array();
$tempDistributors = $this->userManager->getDistributors(array('state_id'=>$stateId));
foreach ($tempDistributors as $dist){
$returnDistributors[$dist['id']] = $dist['firstName'].' '.$dist['lastName'];
}
return $returnDistributors;
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to submit request info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-guest-user",
* name="office_brain_requestinfobundle_requestinfo_addgguestuser"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/addGuestUser.html.twig")
*
* @Method({"GET"})
*
*/
public function addGuestUserAction(Request $request)
{
$this->initAction($request);
// $this->form = $this->createForm(new GuestUserType(), new GuestUser());
$this->form = $this->createForm(GuestUserType::class, new GuestUser());
return array('form'=>$this->form->createView());
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-guest-user",
* name="office_brain_requestinfobundle_requestinfo_processaddgguestusersubmit"
* )
*
* @Template()
*
* @Method({"POST"})
*
*/
public function processAddGuestUserAction(Request $request)
{
$this->initAction($request);
// $this->form = $this->createForm(new GuestUserType(), new GuestUser());
$this->form = $this->createForm(GuestUserType::class, new GuestUser());
$this->form->handleRequest($this->request);
if ($this->form->isValid()){
$result = $this->requestInfoManager->setGuestInfo($this->form->getData());
$requestInfoObj = $result['data'];
switch ($result['status']) {
case 'ADD_RECORD_SUCCESSFULLY':
/*if(is_array($this->erpIntegration) && $this->erpIntegration['orderManagement'] == 1 && !empty($this->queueApiManager)) {
$this->queueApiManager->mapQueue("create", $requestInfoObj);
}*/
$this->requestInfoManager->sendRequestInfoEmail($requestInfoObj);
$this->responseArray['status'] = 'success';
$this->responseArray['goto_url'] = $this->generateUrl('office_brain_requestinfobundle_requestinfo_thankupage');
return new JsonResponse($this->responseArray);
}
}
else if ($this->request->isXmlHttpRequest ()) {
return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form));
}
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/list-request-info",
* name="office_brain_requestinfobundle_requestinfo_listrequestinfo"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/listRequestInfo.html.twig")
*
* @Method({"GET"})
*
*/
public function listRequestInfoAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'error';
$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'));
}
}
$this->responseArray['data'] = $this->requestInfoManager->getRequestInfoList();
return $this->responseArray;
}
/**
*
* @author Employee Id: 4248
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/my-inquiries-list",
* name="office_brain_requestinfobundle_requestinfo_myinquirylist"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/myInquiryList.html.twig")
*
* @Method({"GET"})
*
*/
public function myInquiryListAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'error';
$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'));
}
}
$this->responseArray['data'] = $this->requestInfoManager->getRequestInfoList();
return $this->responseArray;
}
/**
*
* @author Employee Id: 4248
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/detail-request-info/{request_info_id}",
* name="office_brain_requestinfobundle_requestinfo_detailrequestinfo"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/detailRequestInfo.html.twig")
*
* @Method({"GET"})
*
*/
public function detailRequestInfoAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'error';
$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'));
}
}
$this->responseArray['data'] = $this->requestInfoManager->getRequestInfoDetailById();
return $this->responseArray;
}
/**
*
* @author Employee Id: 4248
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-comment-request-info/{request_id}/{user_id}",
* name="office_brain_requestinfobundle_requestinfo_addcommentrequestinfo"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/addCommentRequestInfo.html.twig")
* @Method({"GET"})
*/
public function addCommentRequestInfoAction(Request $request)
{
$this->initAction($request);
$userDetail = $this->requestInfoManager->getUserDetail($this->request->get('user_id'),'user');
// $this->form=$this->createForm(new CommentRequestInfoType(), new CommentRequestInfo() );
$this->form=$this->createForm(CommentRequestInfoType::class, new CommentRequestInfo() );
$this->responseArray['form']=$this->form->createView ();
$this->responseArray['request_id'] = $this->request->get('request_id');
$this->responseArray['user_name'] = $userDetail->getFirstName().' '.$userDetail->getLastName();
return $this->responseArray;
}
/**
*
* @author Employee Id: 4248
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/add-comment-request-info",
* name="office_brain_requestinfobundle_requestinfo_processcommnentrequestinfosubmit"
* )
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/addCommentRequestInfo.html.twig")
*
* @Method({"POST"})
*
*/
public function addCommentRequestInfoSubmitAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'error';
$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'));
}
}
$this->form = $this->createForm(new CommentRequestInfoType(), new CommentRequestInfo());
$this->form->handleRequest($this->request);
$requestId = $this->form->getData ()->requestInfoId;
if ($this->form->isValid()){
$result=$this->requestInfoManager->setCommentRequestInfo($this->form->getData());
switch ($result['status']) {
case 'COMMENT_ADDED_SUCESSFULLY':
if ($this->request->isXmlHttpRequest ()) {
$this->responseArray['status'] = 'success';
$this->responseArray['success_message'] = $this->get('translator')->trans('request_info.comment_added_successfully');
$this->responseArray['url'] = $this->generateUrl('office_brain_requestinfobundle_requestinfo_listcommentrequestinfo',array('request_info_id'=>$requestId));
return new JsonResponse ( $this->responseArray );
}
break;
}
}
else if ($this->request->isXmlHttpRequest ()) {
return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError($this->form) );
}
return array (
'form' => $this->form->createView (),
'request_id'=>$requestId
);
}
/**
*
* @author Employee Id: 4248
*
* Desciption: Use to submit guest user info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/list-comment-request-info/{request_info_id}",
* name="office_brain_requestinfobundle_requestinfo_listcommentrequestinfo"
* )
*
* @Method({"GET"})
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/listCommentRequestInfo.html.twig")
*
*/
public function listCommentRequestInfoAction(Request $request)
{
$this->initAction($request);
$this->responseArray['data'] = $this->requestInfoManager->getCommentRequestInfoList();
return $this->responseArray;
}
/**
*
* @author Employee Id: 4248
*
* Desciption: product thank you page
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/request-info-thank-you",
* name="office_brain_requestinfobundle_requestinfo_thankupage"
* )
*
* @Method({"GET"})
*
* @Template()
*
*/
public function thankYouRequestInfoAction(Request $request)
{
$this->initAction($request);
$this->requestInfoManager->setContinueProdDetailURL($this->commonLibraryManager->getRefererRouteName(), $this->commonLibraryManager->getRefererUrl());
return array();
}
/**
*
* @author Employee Id: 4074
*
* Desciption: This function allow user go back to page from where he/she came to Request Info.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/continue-request-info-from-product-detail",
* name="office_brain_requestinfobundle_continue_request_info"
* )
*
* @Method({"GET"})
*
*/
public function continueRequestInfoAction(Request $request)
{
/* $this->initAction($request);
return $this->redirect($this->requestInfoManager->getContinueProdDetailURL()); */
return $this->redirect($this->generateUrl('office_brain_searchbundle_search_continueshopping'));
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to dalete a record
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/delete-request-info/{request_info_id}",
* name="office_brain_requestinfobundle_requestinfo_deleterequestinfo"
* )
*
* @Method({"GET"})
*
* @Template()
*
*/
public function deleteRequestInfoAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'error';
$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'));
}
}
$requestInfoDetail = $this->requestInfoManager->deleteRequestInfoDetailById();
switch ($requestInfoDetail['status']) {
case 'ERROR_NOT_FOUND':
$this->responseArray['error_message'] = $this->get('translator')->trans('request_info.no_record');
break;
case 'SUCCESS':
$this->responseArray['status'] = 'success';
$this->responseArray['inquiry_list'] = 'inquiry';
$this->responseArray['success_message'] = $this->get('translator')->trans('request_info.remove_success_message');
break;
}
if ($this->request->isXmlHttpRequest()) {
return new JsonResponse($this->responseArray);
}
}
/**
*
* @author Employee Id: 4203
*
* Desciption: Use to submit Commemt Request Info form.
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/customer-detail/{user_id}/{user_type}",
* name="office_brain_requestinfobundle_requestinfo_customerdetailinfo"
* )
*
* @Method({"GET"})
*
* @Template("OfficeBrain/Bundle/RequestInfoBundle/RequestInfo/customerDetailInfo.html.twig")
*
*/
public function customerDetailInfoAction(Request $request)
{
$this->initAction($request);
$this->responseArray['user_detail'] = $this->requestInfoManager->getUserDetail($this->request->get('user_id'), $this->request->get('user_type'));
return $this->responseArray;
}
/**
*
* @author Employee Id: 410175
*
* Desciption: get All state wise distributors
*
* @param NULL
*
* @return Html Response
*
* @throws NULL
*
* @Route("/{_locale}/select-distributors",
* name="office_brain_requestinfobundle_requestinfo_selectdistributors",
* options={"expose"=true}
* )
*
* @Method({"POST"})
*
* @Template()
*
*/
public function selectDistributorsAction(Request $request)
{
$this->initAction($request);
$filter['stateId'] = $this->request->get('stateId');
$data['distributors'] = $this->userManager->getDistributors($filter);
if ($this->request->isXmlHttpRequest()) {
return new JsonResponse($data);
}
return $data;
}
}