Ejemplo n.º 1
0
 public function onBootstrap(MvcEvent $e)
 {
     $oApplication = $e->getApplication();
     $oServiceLocator = $oApplication->getServiceManager();
     $oSharedManager = $oApplication->getEventManager()->getSharedManager();
     $oEventManager = $oApplication->getEventManager();
     $oModuleRouteListener = new ModuleRouteListener();
     $oModuleRouteListener->attach($oEventManager);
     $oRouter = $oServiceLocator->get('router');
     $oRequest = $oServiceLocator->get('request');
     $oMatchedRoute = $oRouter->match($oRequest);
     if (null !== $oMatchedRoute) {
         $oSharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) use($oServiceLocator) {
             if ($oServiceLocator->get('ControllerPluginManager')->has('LogsPlugin')) {
                 //$oServiceLocator->get('ControllerPluginManager')->get('LogsPlugin')->init($e);
             }
         }, 2);
     }
     $oSharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) use($oServiceLocator) {
         $oController = $e->getTarget();
         $sControllerClassName = get_class($oController);
         $sModuleName = substr($sControllerClassName, 0, strpos($sControllerClassName, '\\'));
         $aConfig = $oServiceLocator->get('config');
         if (isset($aConfig['module_layouts'][$sModuleName])) {
             //$oController->layout($aConfig['module_layouts'][$sModuleName]);
         }
     }, 100);
     $oSharedManager->attach('User\\Controller\\Plugin\\AuthPlugin', 'auth', function ($e) use($oServiceLocator) {
         $oParam = $e->getParams();
         $oMail = new \Application\Mail($oServiceLocator);
         $oMail->fillMessage('sendLoginMessage', $oParam);
     }, -10);
     $oTranslator = $oServiceLocator->get('translator');
     \Zend\Validator\AbstractValidator::setDefaultTranslator($oTranslator);
     //$oEventManager->attach('dispatch.error', new \Application\Listener\DispatchErrorHandlerListener(), 100);
     //$oEventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $oEvent) {
     //$oViewModel = $oEvent->getViewModel();
     //$oViewModel->setTemplate('layout/layout_404');
     //}, -200);
 }
 public function successAction()
 {
     $oMail = new \Application\Mail($this->getServiceLocator());
     $oUserSessionContainer = new UserSessionContainer();
     $nUserId = $oUserSessionContainer->getUserId();
     if ($nUserId) {
         $nCartId = $this->getCartTable()->findRow(array('user_id' => $nUserId));
         if ($nCartId) {
             $this->getCartItemTable()->deleteRow(array('cart_id' => $nCartId));
         }
         $oUserSessionContainer->clear();
     }
     $sOrderId = $this->params()->fromQuery('id');
     $sSessionId = $this->params()->fromQuery('session');
     if (isset($sOrderId) && isset($sSessionId)) {
         $oOrderPayment = $this->getOrderPaymentTable()->getRow(array('session_id' => $sSessionId, 'order_id' => $sOrderId));
         $nUserId = $oOrderPayment->user_id;
         if ($oOrderPayment && $nUserId) {
             $oUserStd = new \stdClass();
             $oUserParam = $this->getUserParamTable()->getRow(array('user_id' => $nUserId));
             foreach ($oUserParam as $sKey => $mValue) {
                 if (in_array($sKey, array('user_id'))) {
                     continue;
                 }
                 if (in_array($sKey, array('id'))) {
                     $sKey = 'user_param_id';
                 }
                 $oUserStd->{$sKey} = $mValue;
             }
             foreach ($oOrderPayment as $sKey => $mValue) {
                 if (in_array($sKey, array('user_id', 'first_name', 'last_name', 'e-mail address'))) {
                     continue;
                 }
                 if (in_array($sKey, array('id'))) {
                     $sKey = 'order_payment_id';
                 }
                 if (in_array($sKey, array('amount'))) {
                     $sKey = 'user_amount';
                     $mValue = (int) $mValue / 100;
                 }
                 $oUserStd->{$sKey} = $mValue;
             }
             $oUserStd->issue_user_date = $oOrderPayment->last_update_payment_status_date;
             $nPaymentStatus = 1;
             if ($oOrderPayment->payment_status) {
                 $nPaymentStatus = $oOrderPayment->payment_status;
             }
             $sMessage = $oMail->getMessage('sendPayUReport' . $nPaymentStatus, $oUserStd);
             $oBorrowerForm = $this->getServiceLocator()->get('BorrowerFormService');
             $aAllFine = array();
             $aAllowLocations = array();
             $oUserSessionContainer = new UserSessionContainer();
             $sBorrowerId = $oUserParam->borrower_hash;
             $oUserSessionContainer->setIsBorrower(1);
             $oUserSessionContainer->setBorrowerId($sBorrowerId);
             $oXServer = new XServer($sBorrowerId);
             $aBorrowerData = $oXServer->getBorrowerData();
             if (!isset($aBorrowerData['error'])) {
                 $aBorrower['key'] = $oUserSessionContainer->getPreIsInit();
                 $aBorrower['email_address'] = $oUserSessionContainer->getEmailAddress();
                 $aBorrower['is_borrower'] = 1;
                 $oBorrowerForm->setData($aBorrower);
                 $aExpirationItem = $oUserSessionContainer->getExpirationItem();
                 $aExpirationItemByLocation = $oUserSessionContainer->getExpirationItemByLocation();
                 $aBorrowerFine = $oUserSessionContainer->getBorrowerFine();
                 $aBorrowerFineByLocation = $oUserSessionContainer->getBorrowerFineByLocation();
                 $nCredit = $oUserSessionContainer->getCredit();
                 foreach ($aExpirationItemByLocation as $sLocationKey => $aFine) {
                     $aAllowLocations[$sLocationKey] = $this->translateLocation($sLocationKey);
                     if ($sLocationKey !== 'sum') {
                         $nSum = $aFine['sum'];
                         unset($aFine['sum']);
                         unset($aFine['translate_location']);
                         $aAllFine[$sLocationKey]['sum'] += $nSum;
                         $aAllFine[$sLocationKey]['expiration_item'] = $aFine;
                     }
                 }
                 foreach ($aBorrowerFineByLocation as $sLocationKey => $aFine) {
                     $aAllowLocations[$sLocationKey] = $this->translateLocation($sLocationKey);
                     if ($sLocationKey !== 'sum') {
                         $nSum = $aFine['sum'];
                         unset($aFine['sum']);
                         unset($aFine['translate_location']);
                         $aAllFine[$sLocationKey]['sum'] += $nSum;
                         $aAllFine[$sLocationKey]['borrower_fine'] = $aFine;
                     }
                 }
                 $bSuccess = true;
                 //$oUserSessionContainer->clear();
             } else {
                 $sErrorMessage = 'getfine - XServer response: ' . $aBorrowerData['error'];
             }
         }
     }
     return new ViewModel(array('message' => $sMessage, 'form' => $oBorrowerForm, 'expiration_item' => $aExpirationItem, 'expiration_item_by_location' => $aExpirationItemByLocation, 'borrower_fine' => $aBorrowerFine, 'borrower_fine_by_location' => $aBorrowerFineByLocation, 'all_fine' => $aAllFine, 'allow_locations' => $aAllowLocations, 'credit' => $nCredit, 'success' => $bSuccess, 'error_message' => $sErrorMessage));
 }