<?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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

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

    private $request;

    private $projectSetting;

    private $responseArray;

    private $recordsPerPage;

    private $session;

    private $subShopInquiryManager;

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

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

    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_inquiry_record_per_page']['status'];
        $this->session = $this->get('session');
        $this->subShopInquiryManager = $this->get('office_brain_subshop_inquiry_manager');
        $this->responseArray = array();
    }

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

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

        return $this->responseArray;
    }

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

        $this->responseArray['pagination'] = $this->subShopInquiryManager->searchByStatusSubShopInquiry();

        return $this->responseArray;
    }

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

        $this->subShopInquiryManager->deleteSubShopInquiry();

        $this->session->getFlashBag()->set('success_message', $this->translator->trans('subshop_inquiry.action.subshop_inquiry_delete_success'));

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

    /**
     * @author Employee Id: 4494
     * Description : On-hold inquiry by id
     *
     * @param 1 : Inquiry id
     *
     * @return type : Redirect to inquiry list action.
     *
     * @throws Exception: Null
     *
     * @Route("/onhold/{id}", name="office_brain_subshopbundle_subshopinquiryadmin_inquiryonhold")
     *
     * @Method("GET")
     */
    public function inquiryOnHoldAction()
    {
        $this->initAction();

        $this->subShopInquiryManager->onHoldSubShopInquiry();

        $this->session->getFlashBag()->set('success_message', $this->translator->trans('subshop_inquiry.action.subshop_inquiry_onhold_success'));

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

    /**
     * @author Employee Id: 4494
     * Description : Reject inquiry by id.
     *
     * @param 1 : Inquiry id
     *
     * @return type : Redirect to inquiry list action.
     *
     * @throws Exception: Null
     *
     * @Route("/reject/{id}", name="office_brain_subshopbundle_subshopinquiryadmin_inquiryreject")
     *
     * @Method("POST")
     */
    public function inquiryRejectAction()
    {
        $this->initAction();

        $inquiry = $this->subShopInquiryManager->sendRejectAcknowledgement();

        $this->session->getFlashBag()->set('success_message', $this->translator->trans('subshop_inquiry.action.subshop_inquiry_rejected_success'));

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

    /**
     * @author Employee Id: 4494
     * Description : Approve inquiry by id
     *
     * @param 1 : Inquiry id
     *
     * @return type : Redirect to inquiry list action.
     *
     * @throws Exception: Null
     *
     * @Route("/approve/{id}", name="office_brain_subshopbundle_subshopinquiryadmin_inquiryapprove")
     *
     * @Method("GET")
     */
    public function inquiryApproveAction()
    {
        $this->initAction();

        $this->subShopInquiryManager->approveSubShopInquiry();
    }

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

        $this->responseArray['pagination'] = $this->subShopInquiryManager->searchByStatusSubShopInquiry();

        return $this->responseArray;
    }

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

        $this->responseArray['pagination'] = $this->subShopInquiryManager->getSubShopInquiryList();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4494
     * Description : View inquiry by id
     *
     * @param 1 : Inquiry id
     *
     * @return type : Inquiry data.
     *
     * @throws Exception: Null
     *
     * @Route("/view/{id}",
     * name="office_brain_subshopbundle_subshopinquiryadmin_inquiryview")
     *
     * @Method("GET")
     * @Template("OfficeBrainSubShopBundle:SubShopInquiryAdmin:view.html.twig")
     */
    public function inquiryViewAction()
    {
        $this->initAction();

        $this->responseArray['inquiry'] = $this->subShopInquiryManager->getSubShopInquiry($this->request->get('id'));

        return $this->responseArray;
    }

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

        $this->responseArray['inquiry'] = $this->subShopInquiryManager->searchByDeleteSubShopInquiry();

        return $this->responseArray;
    }

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

        $this->responseArray['pagination'] = $this->subShopInquiryManager->searchSubShopInquiry();

        return $this->responseArray;
    }
}
