Example #1
0
 public function __invoke()
 {
     $this->_oServiceLocator = $this->getServiceLocator();
     $oUserSessionContainer = new UserSessionContainer();
     if ($oUserSessionContainer->getIsInit()) {
         $nUserId = $oUserSessionContainer->getUserId();
         if ($nUserId) {
             $oCart = $this->getCartTable()->getRow(array('user_id' => $nUserId));
             if ($oCart) {
                 $sPaymentDescription = '';
                 $oAllCartItems = $this->getCartItemTable()->getAll(array('cart_id' => $oCart->id));
                 if ($oAllCartItems) {
                     foreach ($oAllCartItems as $oItem) {
                         $sPaymentDescription .= $this->getItemTable()->getRow(array('id' => $oItem->item_id))->name;
                         if (count($oAllCartItems) > 1) {
                             $sPaymentDescription .= '; ';
                         }
                     }
                     $sPaymentDescription = trim($sPaymentDescription);
                 }
                 return array('cart' => $this->getCartItemTable()->getCartSum(array('cart_id' => $oCart->id)), 'description' => $sPaymentDescription);
             }
         }
     }
     return null;
 }
 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));
 }
 public function pregetfineAction()
 {
     $oUserSessionContainer = new UserSessionContainer();
     $oRequest = new \Zend\Http\PhpEnvironment\Request();
     //$sReferer = $oRequest->getServer('HTTP_REFERER'); //TODO: ustawić odpowiedni parametr
     //$sBorrowerId = $this->checkCookie();
     $sBorrowerId = 1;
     if ($sBorrowerId) {
         $oUserSessionContainer->setIsBorrower(1);
         $oUserSessionContainer->setBorrowerId($sBorrowerId);
         $this->redirect()->toRoute('aleph_index/aleph_index_process', array('action' => 'getfine'), array());
         $this->stopPropagation();
     } else {
         header("Location: https://aleph.wat.edu.pl/pds?func=load-login&calling_system=libsmart&url=https://wplaty.bg.wat.edu.pl/wat/bor_id");
         exit;
     }
     /*
     $sBorrowerId = $this->params()->fromRoute('bor_id');
     if ($sBorrowerId) {
       $oUserSessionContainer->setIsBorrower(1);
       $oUserSessionContainer->setBorrowerId($sBorrowerId);
       $this->redirect()->toRoute('aleph_index/aleph_index_process', array('action' => 'getfine'), array());
       $this->stopPropagation();
     } else {
     }
     */
     return new ViewModel(array('success' => true));
 }
 public function refreshcartajaxAction()
 {
     $oResponse = $this->getResponse();
     $bSuccess = false;
     if ($this->getRequest()->isPost()) {
         $oResponse = $this->getResponse();
         $oUserSessionContainer = new UserSessionContainer();
         if ($oUserSessionContainer->getUserId()) {
             $nUser = $oUserSessionContainer->getUserId();
             $oCart = $this->getCartTable()->getRow(array('user_id' => $nUser));
             if ($oCart) {
                 $bSuccess = $this->getCartItemTable()->getCartSum(array('cart_id' => $oCart->id));
             }
         }
     }
     $oResponse->setContent(\Zend\Json\Json::encode($bSuccess));
     return $oResponse;
 }
 public function getCartSum(array $aData = null)
 {
     $oUserSessionContainer = new UserSessionContainer();
     if ($oUserSessionContainer->getIsInit()) {
         $aData['cart.user_id'] = $oUserSessionContainer->getUserId();
         $oThat = $this;
         $oResultSet = $this->select(function (Select $oSelect) use($aData, $oThat) {
             $oSelect->columns(array('cart_items_count' => new Expression('SUM(count)'), 'cart_sum_price_net' => new Expression('SUM(count * (price_net)) / 100'), 'cart_sum_price_gross' => new Expression('SUM(count * (price_gross) / 100)')));
             $oSelect->join('cart', 'cart.id = cart_item.cart_id', array('user_id'));
             $oSelect->join('item', 'item.id = cart_item.item_id', array(), $oSelect::JOIN_INNER);
             $oSelect->join('user_param', 'user_param.user_id = cart.user_id', array('credit'), $oSelect::JOIN_INNER);
             if ($aData) {
                 foreach ($aData as $sKey => $mValue) {
                     $oSelect->where(array($sKey => $mValue));
                 }
             }
             $oSelect->limit(1);
         });
         $aResult = $this->getEntities($oResultSet);
         if (count($aResult) === 1) {
             return $aResult[0];
         }
     }
     return null;
 }