<?php

namespace OfficeBrain\Bundle\SubShopBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use OfficeBrain\Bundle\SubShopBundle\Entity\SubShop;
use OfficeBrain\Bundle\SubShopBundle\Form\SubShopType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\FormError;

/**
 * @author OfficeBrain 4494 <info@officebrain.com>
 *
 * Description : Sub shop Admin class.
 *
 * @Route("/admin/{_locale}/sub-shop")
 **/
class SubShopAdminController extends Controller
{
    protected $translator;

    protected $request;

    protected $projectSetting;

    protected $responseArray;

    protected $recordsPerPage;

    protected $session;

    protected $subShopManager;

    protected $subshopThemeManager;

    protected $commonLibraryManager;

    protected $form;

    public function __construct()
    {
        $this->translator = null;
        $this->request = null;
        $this->projectSetting = array();
        $this->responseArray = array();
        $this->recordsPerPage = null;
        $this->session = null;
        $this->subShopManager = null;
        $this->subshopThemeManager = null;
        $this->form = null;
    }

    public function __destruct()
    {
        unset($this->translator);
        unset($this->request);
        unset($this->projectSetting);
        unset($this->responseArray);
        unset($this->recordsPerPage);
        unset($this->session);
        unset($this->subShopManager);
        unset($this->subshopThemeManager);
        unset($this->form);
    }

    public function initAction()
    {
        $this->translator = $this->get('translator');
        $this->request = $this->getRequest();
        $this->projectSetting = $this->request->get('project_setting');
        $this->recordsPerPage = $this->projectSetting['configuration_rule']['site_management']['option']['sub_shop']['option']['sub_shop_record_per_page']['status'];
        $this->session = $this->get('session');
        $this->subShopManager = $this->get('office_brain_subshop_manager');
        $this->commonLibraryManager = $this->get('office_brain_common_library');
        $this->subshopThemeManager = $this->get('office_brain_subshop_theme_manager');
        $this->responseArray = array();
    }

    /**
     * @author Employee Id: 4494
     * Description : Display subshop list.
     *
     * @param 1 : Record per page
     * @param 2 : Page number
     *
     * @return type : Data.
     *
     * @throws Exception: Null
     *
     * @Route("/list/{records_per_page}/{page}",
     * name="office_brain_subshopbundle_subshopadmin_subshoplist",
     * requirements={"records_per_page"="2|4|8|16|996", "page"="\d+"},
     * defaults={"records_per_page"=2,"page"=1})
     * )
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:subshop.html.twig")
     */
    public function subshopListAction()
    {
        $this->initAction();

        $this->responseArray['records_per_page'] = $this->recordsPerPage;
        $this->responseArray['page'] = $this->request->get('page');

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Ajax base get subshop list by status
     *
     * @param 1 : Record per page
     * @param 2 : page number
     *
     * @return type : Sub shop data.
     *
     * @throws Exception: Null
     *
     * @Route("/list/{records_per_page}/{page}",
     * name="office_brain_subshopbundle_subshopadmin_subshoplistajax",
     * requirements={"records_per_page"="2|4|8|16|996", "page"="\d+"},
     * defaults={"records_per_page"=2, "page"=1})
     * )
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:list.html.twig")
     */
    public function subshopListAjaxAction()
    {
        $this->initAction();

        $this->responseArray['pagination'] = $this->subShopManager->searchByStatusSubShop();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 5058
     * Description : Add subshop from Inquiry.
     *
     * @param 1 : Inquiry Id
     *
     * @return type : Form view.
     *
     * @throws Exception: Null
     *
     * @Route("/add-from-inquiry/{inquiry_id}", name="office_brain_subshopbundle_subshopadmin_subshopaddfrominquiry")
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:add.html.twig")
     */
    public function subshopAddFromInquiryAction()
    {
        $this->initAction();

        $inquiryManager = $this->get('office_brain_subshop_inquiry_manager');
        $subShop = $inquiryManager->setSubShopFromInquiry();

        if (!is_object($subShop) && isset($subShop['error']) && $subShop['error'] == 'ERROR_INQUIRY_ALREADY_APPROVED') {
            $this->session->getFlashBag()->set('error_message', $this->translator->trans('subshop_inquiry.action.subshop_inquiry_already_created'));

            return $this->redirect($this->generateUrl('office_brain_subshopbundle_subshopinquiryadmin_inquiry'));
        }

        $form = $this->createForm(new SubShopType($this->getDoctrine()->getManager(),$this->request), $subShop, array('action' => $this->generateUrl('office_brain_subshopbundle_subshopadmin_processsubshopadd')));
        $form->get('inquiryId')->setData($this->request->get('inquiry_id'));

        $this->responseArray['form'] = $form->createView();

        unset($inquiryManager);
        unset($form);

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Display subshop form.
     *
     * @param 1 : No paramater
     *
     * @return type : Form view.
     *
     * @throws Exception: Null
     *
     * @Route("/add", name="office_brain_subshopbundle_subshopadmin_subshopadd")
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:add.html.twig")
     */
    public function subshopAddAction()
    {
    	
        $this->initAction();
        $this->responseArray['subshop_step_access_config_allow'] = $this->subShopManager->allowStepAccessConfiguration();
        $this->responseArray['form'] = $this->createForm(new SubShopType($this->getDoctrine()->getManager(),$this->request), null, array('action' => $this->generateUrl('office_brain_subshopbundle_subshopadmin_processsubshopadd')))->createView();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Submi subshop form
     *
     * @param 1 : No paramater
     *
     * @return type : Form view and data.
     *
     * @throws Exception: Null
     *
     * @Route("/add", name="office_brain_subshopbundle_subshopadmin_processsubshopadd")
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:add.html.twig")
     */
    public function processSubshopAddAction()
    {
        $this->initAction();

        $this->form = $this->createForm(new SubShopType($this->getDoctrine()->getManager(),$this->request), new SubShop());

        $this->form->handleRequest($this->request);

        if ($this->form->isValid()) {
            $subShop = $this->subShopManager->setSubShop($this->form->getData(), true, (isset($this->form['inquiryId']) && $this->form['inquiryId']->getData() > 0) ? $this->form['inquiryId']->getData() : 0);

            $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
            $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.action.subshop_add_success');
            $this->responseArray['subshop_id'] = $subShop->getId();

            unset($subShopId);
        } else {
            $this->responseArray = $this->commonLibraryManager->prepareFormJsonError($this->form);
        }

        return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/{id}", name="office_brain_subshopbundle_subshopadmin_subshopedit")
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:edit.html.twig")
     */
    public function subshopEditAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->getSubShop();

        $this->responseArray['subshop_step'] = $this->subShopManager->getSubShopStep($subShop->getParentId());
        $this->responseArray['subshop_step_access_config_allow'] = $this->subShopManager->allowStepAccessConfiguration($subShop);

        if (!$subShop) {
            throw $this->createNotFoundException($this->translator->trans('subshop_content.admin.action.no_record_found').' '.$this->request->get('id'));
        } else {
            $this->form = $this->createForm(new SubShopType($this->getDoctrine()->getManager(),$this->request), $subShop, array(
                                'action' => $this->generateUrl('office_brain_subshopbundle_subshopadmin_processsubshopedit', array('id' => $this->request->get('id'))),
                            ));
        }

        $this->responseArray['form'] = $this->form->createView();
        if(!empty($subShop->getShopThemeId())){
        	$this->responseArray['themeType'] = $this->subshopThemeManager->getSubShopTheme($subShop->getShopThemeId())->getThemeType();
        }
        unset($subShop);

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Submi edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/{id}", name="office_brain_subshopbundle_subshopadmin_processsubshopedit")
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:edit.html.twig")
     */
    public function processSubshopEditAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->getSubShop();

        if (!$subShop) {
            throw $this->createNotFoundException($this->translator->trans('subshop_content.admin.action.no_record_found').' '.$this->request->get('id'));
        } else {
            
            $this->form = $this->createForm(new SubShopType($this->getDoctrine()->getManager(),$this->request), $subShop);
            
            $this->form->handleRequest($this->request);
            
            $validShopDomain = $this->subShopManager->checkDuplicateShopDomain($this->form->getData());
            if(!$validShopDomain){
                $error = new FormError($this->translator->trans('subshop_content.admin.action.duplicate_domain'));
                $this->form->get('shopDomain')->addError($error);
            }
            

            if ($this->form->isValid()) {
                $this->subShopManager->setSubShop($this->form->getData());

                $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
                $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.action.subshop_update_success');
                $this->responseArray['subshop_id'] = $subShop->getId();
            } else {
                $this->responseArray = $this->commonLibraryManager->prepareFormJsonError($this->form);
            }

            return new JsonResponse($this->responseArray);
        }

        unset($subShop);

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Delete subshop by id
     *
     * @param 1 : Subshop id
     *
     * @return type : Redirect to subshop list action.
     *
     * @throws Exception: Null
     *
     * @Route("/delete/{id}", name="office_brain_subshopbundle_subshopadmin_subshopdelete")
     *
     * @Method("GET")
     */
    public function subshopDeleteAction()
    {
        $this->initAction();

        $this->subShopManager->deleteSubShop();

        $this->session->getFlashBag()->set('success_message', $this->translator->trans('subshop_content.admin.action.subshop_delete_success'));

        return $this->redirect($this->generateUrl('office_brain_subshopbundle_subshopadmin_subshoplist'));
    }

    /**
     * @author Employee Id: 4494
     * Description : Revert subshop by id
     *
     * @param 1 : Subshop id
     *
     * @return type : Redirect to subshop list action.
     *
     * @throws Exception: Null
     *
     * @Route("/revert/{id}", name="office_brain_subshopbundle_subshopadmin_subshoprevert")
     *
     * @Method("GET")
     */
    public function subshopRevertAction()
    {
        $this->initAction();

        $this->subShopManager->revertSubShop();

        $this->session->getFlashBag()->set('success_message', $this->translator->trans('subshop_content.admin.action.subshop_active_success'));

        return $this->redirect($this->generateUrl('office_brain_subshopbundle_subshopadmin_subshoplist'));
    }

    /**
     * @author Employee Id: 4494
     * Description : Search Subshop by status
     *
     * @param 1 : Status id
     * @param 2 : Record per page
     * @param 3 : page number
     *
     * @return type : Subshop list data.
     *
     * @throws Exception: Null
     *
     * @Route("/search/status/{status_id}/{records_per_page}/{page}",
     * name="office_brain_subshopbundle_subshopadmin_subshopsearchbystatus",
     * requirements={"records_per_page"="2|4|8|16|996", "page"="\d+"},
     * defaults={"records_per_page"=2, "page"=1})
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:list.html.twig")
     */
    public function subshopSearchByStatusAction()
    {
        $this->initAction();

        $this->responseArray['pagination'] = $this->subShopManager->searchByStatusSubShop();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Deleted subshop by status
     *
     * @param 1 : Status id
     * @param 2 : Record per page
     * @param 3 : page number
     *
     * @return type : Subshop list data.
     *
     * @throws Exception: Null
     *
     * @Route("/search/delete/{records_per_page}/{page}",
     * name="office_brain_subshopbundle_subshopadmin_subshopsearchbydelete",
     * requirements={"records_per_page"="2|4|8|16|996", "page"="\d+"},
     * defaults={"records_per_page"=2,"page"=1})
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:list.html.twig")
     */
    public function subshopSearchByDeleteAction()
    {
        $this->initAction();

        $this->responseArray['pagination'] = $this->subShopManager->searchByDeleteSubShop();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Search SubShop list
     *
     * @param 1 : keyword
     *
     * @return type : SubShop list data.
     *
     * @throws Exception: Null
     *
     * @Route("/search/{records_per_page}/{page}",
     * name="office_brain_subshopbundle_subshopadmin_subshopsearchajax",
     * requirements={"records_per_page"="2|4|8|16|996", "page"="\d+"},
     * defaults={"records_per_page"=2,"page"=1})
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:list.html.twig")
     */
    public function subShopSearchAjaxAction()
    {
        $this->initAction();

        $this->responseArray['pagination'] = $this->subShopManager->searchSubShop();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Send User Acknowledge mail for subshop
     *
     * @param 1 : Subshop id
     *
     * @return type : SubShop list data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/user-acknowledge/{id}", name="office_brain_subshopbundle_subshopadmin_subshopuserackowledge")
     *
     * @Method("GET")
     */
    public function subshopUserAckowledgeAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->getSubShop();

        if (!$subShop) {
            throw $this->createNotFoundException($this->translator->trans('subshop_content.admin.action.no_record_found').' '.$this->request->get('id'));
        } else {
            if ($subShop->getIsMailSent() == 0) {
                $this->subShopManager->sendApprovedAcknowledgement($subShop);

                $this->session->getFlashBag()->set('success_message', $this->translator->trans('subshop_content.admin.action.subshop_approve_success'));
            }
        }

        unset($form);
        unset($subShop);

        return $this->redirect($this->generateUrl('office_brain_subshopbundle_subshopadmin_subshoplist'));
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/profile/{id}", name="office_brain_subshopbundle_subshopadmin_subshopprofileeditajax", options={"expose"=true})
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:profile.html.twig")
     */
    public function subshopProfileEditajaxAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->getSubShop();

        if (!$subShop) {
            throw $this->createNotFoundException($this->translator->trans('subshop_content.admin.action.no_record_found').' '.$this->request->get('id'));
        } else {
            $this->form = $this->createForm(new SubShopType($this->getDoctrine()->getManager(),$this->request), $subShop, array(
                    'action' => $this->generateUrl('office_brain_subshopbundle_subshopadmin_processsubshopedit', array('id' => $this->request->get('id'))),
            ));
        }

        $this->responseArray['form'] = $this->form->createView();

        unset($subShop);

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/list/design-store/{id}/{type}/{page}", name="office_brain_subshopbundle_subshopadmin_subshopdesignstorelistajax",
     * options={"expose"=true},
     * requirements={"page"="\d+"},
     * defaults={"page"=1,"type"="all"}
     * )
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:designStoreList.html.twig")
     */
    public function subshopDesignStoreListAjaxAction()
    {
        $this->initAction();

        $this->responseArray['subShop'] = $this->subShopManager->getSubShop();

        $subShopThemeId = 0;
        if ($this->responseArray['subShop']->getShopThemeId() > 0) {
            $subShopThemeId = $this->responseArray['subShop']->getShopThemeId();
        }

        $this->responseArray['pagination'] = $this->subshopThemeManager->searchByTypeSubShopTheme($subShopThemeId);

        $this->responseArray['media_location'] = $this->subshopThemeManager->mediaLocation();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/save/design-store/{id}", name="office_brain_subshopbundle_subshopadmin_subshopdesignstoresaveajax",
     * options={"expose"=true},
     * requirements={"page"="\d+"},
     * defaults={"page"=1,"type"="ECommerce"}
     * )
     *
     * @Method("POST")
     */
    public function subshopDesignStoreSaveAjaxAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->setSubShopDesignTheme();

        if ($subShop) {
            $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
            $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.action.subshop_theme_select_success');
            $this->responseArray['parent_id'] = $subShop->getParentId();
        } else {
            $this->responseArray['status'] = $this->translator->trans('subshop_content.admin.action.error');
            $this->responseArray['error_message'] = $this->translator->trans('subshop_content.admin.action.technical_issue');
        }

        unset($subShop);

        return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/site-access/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsiteaccessajax", options={"expose"=true})
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:siteAccess.html.twig")
     */
    public function subshopSiteAccessAjaxAction()
    {
        $this->initAction();

        $subSiteAccessManager = $this->get('office_brain_access_management_sub_site_access_manager');

        if ($this->request->get('access-submit') > 0) {
            if ($subSiteAccessManager->saveAccessData($this->request)) {
                $this->subShopManager->updateSubShopStep('site_configuration', '1');
                $this->responseArray['step'] = 'site_configuration';
                $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
                $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.action.subshop_access_success');
            } else {
                $this->responseArray['status'] = $this->translator->trans('subshop_content.admin.action.error');
                $this->responseArray['error_message'] = $this->translator->trans('subshop_content.admin.action.technical_issue');
            }

            return new JsonResponse($this->responseArray);
        } else {
        	//$subSiteAccessManager->setSubSiteAccessRules($this->request->get('id'));
            $this->responseArray = $subSiteAccessManager->createForm();
        }

        $this->responseArray['route_name'] = 'office_brain_subshopbundle_subshopadmin_subshopsiteaccessajax';

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/site-product/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsiteproductajax", options={"expose"=true})
     *
     * @Method({"POST"})
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:siteProduct.html.twig")
     */
    public function subshopSiteProductAjaxAction()
    {
        $this->initAction();
        $this->responseArray['product'] = $this->subShopManager->getSubShopCriteria();
        $this->responseArray['id'] = $this->request->get('id');
        
        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4045
     * Description : get subshop product configuration solr status
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/site-product-solr-status/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsiteproductsolrstatusajax", options={"expose"=true})
     *
     * @Method({"POST"})
     * 
     */
    public function subshopSiteProductSolrStatusAjaxAction()
    {
    	$this->initAction();
    	$this->responseArray['product_solr_status'] = $this->subShopManager->getSubShopProductSolrStatus();

    	return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 4045
     * Description : Save subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/save/site-product/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsiteproductsaveajax", options={"expose"=true})
     *
     * @Method({"POST"})
     */
    public function subshopSiteProductSaveAjaxAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->updateSubShopCriteria($this->container->getParameter('kernel.environment'));

        if ($subShop != 'SUBSHOP_NOT_FOUND') {
            $this->subShopManager->updateSubShopStep('product_configuration', '1');
            $this->responseArray['step'] = 'product_configuration';
            $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
            $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.action.subshop_product_success');
        } else {
            $this->responseArray['status'] = $this->translator->trans('subshop_content.admin.action.error');
            $this->responseArray['error_message'] = $this->translator->trans('subshop_content.admin.action.technical_issue');
        }

        return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/save/site-design/{token}", name="office_brain_subshopbundle_subshopadmin_subshopsitedesignsaveajax", options={"expose"=true})
     *
     * @Method("POST")
     */
    public function subshopSiteDesignSaveAjaxAction()
    {
        $this->initAction();

        $subShopDesign = $this->subShopManager->updateSubShopDesign();

        if ($subShopDesign) {
            $this->subShopManager->updateSubShopStep('theme_configuration', '1');
            $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
            $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.design.action.subshop_theme_updated_success');
        } else {
            $this->responseArray['status'] = $this->translator->trans('subshop_content.admin.action.error');
            $this->responseArray['error_message'] = $this->translator->trans('subshop_content.admin.action.technical_issue');
        }

        unset($subShopDesign);

        return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/publish/site-design/{token}", name="office_brain_subshopbundle_subshopadmin_subshoppublishsitedesignsaveajax", options={"expose"=true})
     *
     * @Method("POST")
     */
    public function subshopPublishSiteDesignSaveAjaxAction()
    {
        $this->initAction();

        $subShop = $this->subShopManager->publishSubShopDesign();

        if ($subShop) {
            $this->responseArray['status'] = strtolower($this->translator->trans('subshop_content.admin.action.success'));
            $this->responseArray['success_message'] = $this->translator->trans('subshop_content.admin.design.action.subshop_theme_publish_success');
            $this->responseArray['publish_url'] = $this->request->getScheme().'://'.$subShop->getShopDomain();
        } else {
            $this->responseArray['status'] = $this->translator->trans('subshop_content.admin.action.error');
            $this->responseArray['error_message'] = $this->translator->trans('subshop_content.admin.action.technical_issue');
        }

        unset($subShop);

        return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/site-design/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsitedesignajax", options={"expose"=true})
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:siteThemeDesign.html.twig")
     */
    public function subshopSiteDesignAjaxAction()
    {
        $this->initAction();

        $this->responseArray['subShop'] = $this->subShopManager->getSubShop();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/site-cms/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsitecmsajax", options={"expose"=true})
     *
     * @Method("POST")
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:siteCms.html.twig")
     */
    public function subshopSiteCmsAjaxAction()
    {
        $this->initAction();

        $this->responseArray = $this->subShopManager->getSubShopCms();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : Edit subshop form
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/edit/site-product-sync/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsiteproductsync")
     *
     * @Method("GET")
     */
    public function subshopSiteProductSyncAction()
    {
        $this->initAction();

        $this->responseArray = $this->subShopManager->updateSubShopSolrProducts();

        return new JsonResponse($this->responseArray);
    }
    
    /**
     * @author Employee Id: 4465
     * Description : Get all Products in CMS
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/list/subshop-promotional-products/{type}/{id}", name="office_brain_subshopbundle_subshopadmin_subshopsitepromotionalproducts")
     *
     * @Method("GET")
     * 
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:listSubShopPromotionalProducts.html.twig")
     */
    public function subShopSitePromotionalProductsAction()
    {
    	$this->initAction();
    
    	$this->responseArray = $this->subShopManager->getSubShopPromotionalProductsList();
    
    	return $this->responseArray;
    }
    
    /**
     * @author Employee Id: 4465
     * Description : Get all Products in CMS
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/list/subshop-promotional-products-list-ajax/{country}/{id}/{type}", name="office_brain_subshopbundle_subshopadmin_subshopsitepromotionalproductslistajax")
     *
     * @Method({"GET", "POST"})
     *
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:listSubShopPromotionalProductsAjax.html.twig")
     */
    public function subShopSitePromotionalProductsAjaxAction()
    {
    	$this->initAction();
    
    	$this->responseArray = $this->subShopManager->getSubShopPromotionalProductsListAjax();
    
    	return $this->responseArray;
    }
    
    /**
     * @author Employee Id: 4465
     * Description : Update Promotional products for CMS
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/subshop-promotional-products-update", name="office_brain_subshopbundle_subshopadmin_subshopsitepromotionalproductsupdate", options={"expose"=true})
     *
     * @Method("POST")
     */
    public function subShopSitePromotionalProductsUpdateAction()
    {
    	$this->initAction();
    
    	$this->responseArray = $this->subShopManager->updateSubShopPromotionalProducts();
    
    	return new JsonResponse($this->responseArray);
    }
    
    /**
     * @author Employee Id:4465
     *
     * Description: Display Listing of Brands
     *
     * @Route("/brandlist/{id}/{language}", name="office_brain_subshopbundle_subshopadmin_subshopbrands", requirements={"records_per_page"="12|24|48|96|996"}, defaults={"language"="en"})
     * 
     * @Method({"GET", "POST"})
     * 
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:listSubShopBrands.html.twig")
     */
    
    public function listSubShopBrandAction()
    {
    	$this->initAction();
    	
    	$this->responseArray = $this->subShopManager->getSubShopBrands();
    	
    	return $this->responseArray;
    	
    }
    
    /**
     * @author Employee Id:4465
     *
     * Description: Display Listing of Brands
     *
     * @Route("/brandlistajax/{id}/{language}", name="office_brain_subshopbundle_subshopadmin_subshopbrandsajax", requirements={"records_per_page"="12|24|48|96|996"}, defaults={"language"="en"})
     *
     * @Method({"GET", "POST"})
     *
     * @Template("OfficeBrainSubShopBundle:SubShopAdmin:listSubShopBrandsAjax.html.twig")
     */
    
    public function listSubShopBrandAjaxAction()
    {
    	$this->initAction();
    	
    	$this->responseArray = $this->subShopManager->getSubShopBrandsAjax($this->get("officebrain_brand_api_manager"),$this->get('knp_paginator'));
    	 
    	return $this->responseArray;
    	
    }
    
    /**
     * @author Employee Id: 4465
     * Description : Update Brands for CMS
     *
     * @param 1 : Subshop id
     *
     * @return type : Form view and data.
     *
     * @throws Exception: No Subshop found
     *
     * @Route("/subshop-brands-update", name="office_brain_subshopbundle_subshopadmin_subshopbrandsupdate", options={"expose"=true})
     *
     * @Method("POST")
     */
    public function subShopSiteBrandsUpdateAction()
    {
    	$this->initAction();
    
    	$this->responseArray = $this->subShopManager->updateSubShopBrands();
    
    	return new JsonResponse($this->responseArray);
    }
    
}
