Your IP : 216.73.216.220


Current Path : /var/www/html/app/code/FlipsDigital/HappyMind/Controller/Order/
Upload File :
Current File : /var/www/html/app/code/FlipsDigital/HappyMind/Controller/Order/Form.php

<?php
namespace FlipsDigital\HappyMind\Controller\Order;

class Form extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\UrlInterface $urlInterface,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
        \Magento\Customer\Model\Session $customerSession,
        \FlipsDigital\EducationInstitution\Model\EducationInstitutionFactory $educationInstitutionFactory,
        \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookListFactory $customerTextbookListFactory,
        \FlipsDigital\TextbookList\Model\TextbookListFactory $textbookListFactory,
        \FlipsDigital\TextbookListBook\Model\TextbookListBookFactory $textbookListBookFactory
    )
    {
        $this->_url = $urlInterface;
        $this->_pageFactory = $pageFactory;
        $this->resultForwardFactory = $resultForwardFactory;
		$this->_eiFactory = $educationInstitutionFactory;
		$this->_ctlFactory = $customerTextbookListFactory;
		$this->_tlFactory = $textbookListFactory;
		$this->_tlbFactory = $textbookListBookFactory;
        $this->customerSession = $customerSession;
        parent::__construct($context);
    }
    public function execute()
    {
        $params = $this->getRequest()->getParams();
        $objEI = $this->_eiFactory->create();
        $objTL = $this->_tlFactory->create();
        $objTLB = $this->_tlbFactory->create();
        $objCTL = $this->_ctlFactory->create();
        $redirectNoRoute = false;
        if (
            empty($params['id']) || 
            empty($params['textbook'])
        ){
            $redirectNoRoute = true;
        }
        if (!empty($params['id'])){
            $objCustomerTextbookList = $objCTL->load($params['id']);
        }
        if (!isset($objCustomerTextbookList)){
            $redirectNoRoute = true;
        }
        if (!empty($params['textbook'])){
            $childrenIdentifier = base64_decode($params['textbook']);
        }
        
        if (
            !isset($childrenIdentifier) || 
            (
                isset($childrenIdentifier) && 
                (
                    $objCustomerTextbookList->getIdentifier() != $childrenIdentifier || 
                    $objCustomerTextbookList->getOrderId()
                )
            )
        ){
            $redirectNoRoute = true;
        }
        if (!empty($params['tid'])){
            $objTextbookList = $objTL->load($params['tid']);
            if ($objTextbookList){
                $redirectNoRoute = false;
            }
        }
        if ($redirectNoRoute){
            $resultForward = $this->resultForwardFactory->create();
            return $resultForward->forward('noroute');
        }
        if (!isset($objTextbookList)){
            if (!$this->customerSession->isLoggedIn()){
                return $this->resultRedirectFactory->create()->setUrl($this->_url->getUrl('customer/account/index'));
            }
            $objTextbookList = $objTL->load($objCustomerTextbookList->getData('booklist_id'));
            $objEducationInstitution = $objEI->load($objCustomerTextbookList->getData('education_institution_id'));
        }else{
            $objEducationInstitution = $objEI->load($objTextbookList->getData('education_institution_id'));
        }
        $strTitle = '';
        if ($objEducationInstitution->getName()){
            $strTitle .= $objEducationInstitution->getName();
        }
        if (
            $objEducationInstitution->getChineseName() && 
            $objEducationInstitution->getName() != $objEducationInstitution->getChineseName()            
        ){
            $strTitle .= ($objEducationInstitution->getName()?" ":"").$objEducationInstitution->getChineseName();
        }
        if ($objTextbookList->getClassName()){
            if ($strTitle){
                $strTitle .= " - ";
            }
            $strTitle .= $objTextbookList->getClassName();
        }
        if ($objTextbookList->getGroupName()){
            if ($strTitle){
                $strTitle .= " - ";
            }
            $strTitle .= $objTextbookList->getGroupName();
        }
        $pageFactory = $this->_pageFactory->create();
        $pageFactory->getConfig()->getTitle()->set($strTitle);
        return $pageFactory;
    }
}