public function edititemajaxAction()
 {
     $oResponse = $this->getResponse();
     $bSuccess = false;
     if ($this->getRequest()->isPost()) {
         $oEditItemForm = $this->getServiceLocator()->get('EditItemFormService');
         $oEditItemForm->setData($this->getRequest()->getPost());
         if ($oEditItemForm->isValid()) {
             $oItemEntity = new ItemEntity();
             $oData = new \ArrayObject($oEditItemForm->getData());
             $this->getItemTable()->editRow($oItemEntity->setOptions($oData));
             $bSuccess = true;
         }
     }
     $oResponse->setContent(\Zend\Json\Json::encode($bSuccess));
     return $oResponse;
 }
 public function getfineAction()
 {
     $oUserSessionContainer = new UserSessionContainer();
     $oBorrowerForm = $this->getServiceLocator()->get('BorrowerFormService');
     $aExpirationItem = null;
     $aBorrowerFine = null;
     $bSuccess = false;
     $sIsBorrower = $oUserSessionContainer->getIsBorrower();
     $sBorrowerId = $oUserSessionContainer->getBorrowerId();
     if ($sIsBorrower === 1 && $sBorrowerId) {
         if ($this->getRequest()->isPost()) {
             $oBorrowerForm->setData($this->getRequest()->getPost());
             if ($oBorrowerForm->isValid()) {
                 try {
                     $this->getUserTable()->beginTransaction();
                     $oUserEntity = new UserEntity();
                     $oUserParamEntity = new UserParamEntity();
                     $oCartEntity = new CartEntity();
                     $oCartItemEntity = new CartItemEntity();
                     $oItemEntity = new ItemEntity();
                     $aValidatedData = $oBorrowerForm->getData();
                     \Zend\Debug\Debug::dump($oUserSessionContainer->getPreIsInit() === $aValidatedData['key']);
                     if ($oUserSessionContainer->getPreIsInit() === $aValidatedData['key']) {
                         $oTempUserData = new \ArrayObject($oUserSessionContainer->getArrayCopy());
                         $oTempUserData->offsetSet('user_category_id', $this->getUserCategoryTable()->findRow(array('name' => 'borrower')));
                         $oTempUserData->offsetSet('active', 0);
                         $oTempUserData->offsetSet('user_id', $this->getUserTable()->addRow($oUserEntity->setOptions($oTempUserData)));
                         if ($oTempUserData->offsetGet('user_id')) {
                             $oTempUserData->offsetSet('user_param_id', $this->getUserParamTable()->addRow($oUserParamEntity->setOptions($oTempUserData)));
                         }
                         if ($oTempUserData->offsetGet('user_id') && $oTempUserData->offsetGet('user_param_id')) {
                             $oUserSessionContainer->setUserId($oTempUserData->offsetGet('user_id'));
                         } else {
                             throw new \Exception();
                         }
                         $nUserId = $oUserSessionContainer->getUserId();
                         $nCartId = $this->getCartTable()->findRow(array('user_id' => $nUserId));
                         if (!$nCartId) {
                             $nCartId = $this->getCartTable()->addRow($oCartEntity->setOptions(new \ArrayObject(array('user_id' => $nUserId))));
                         }
                         if ($oUserSessionContainer->getExpirationItemSum()) {
                             $sName = 'expiration_item';
                             foreach ($oUserSessionContainer->getExpirationItem() as $nKey => $aItem) {
                                 if (is_numeric($nKey)) {
                                     $oItemData = new \ArrayObject(array('name' => $sName, 'fine_id' => $aItem['loan_id'], 'fine_sequence' => '-- brak danych --', 'item_sequence' => '-- brak danych --', 'doc_number' => '-- brak danych --', 'call_no' => '-- brak danych --', 'item_barcode' => $aItem['barcode'], 'title' => $aItem['title'], 'price_net' => $aItem['loan_fine'], 'price_gross' => $aItem['loan_fine'], 'due_date' => $aItem['due_date']));
                                     $nItemId = $this->getItemTable()->addRow($oItemEntity->setOptions($oItemData));
                                     $oCartItemData = new \ArrayObject(array('cart_id' => $nCartId, 'item_id' => $nItemId, 'user_id' => $nUserId));
                                     $this->getCartItemTable()->addRow($oCartItemEntity->setOptions($oCartItemData));
                                 }
                             }
                         }
                         if ($oUserSessionContainer->getBorrowerFineSum()) {
                             $sName = 'borrower_fine';
                             foreach ($oUserSessionContainer->getBorrowerFine() as $nKey => $aFine) {
                                 if (is_numeric($nKey)) {
                                     $oItemData = new \ArrayObject(array('name' => $sName, 'fine_id' => $aFine['fee_id'], 'fine_sequence' => '-- brak danych --', 'item_sequence' => '-- brak danych --', 'doc_number' => '-- brak danych --', 'call_no' => '-- brak danych --', 'item_barcode' => $aFine['barcode'], 'title' => $aFine['comment'], 'price_net' => $aFine['balance'], 'price_gross' => $aFine['balance'], 'due_date' => null));
                                     $nItemId = $this->getItemTable()->addRow($oItemEntity->setOptions($oItemData));
                                     $oCartItemData = new \ArrayObject(array('cart_id' => $nCartId, 'item_id' => $nItemId, 'user_id' => $nUserId));
                                     $this->getCartItemTable()->addRow($oCartItemEntity->setOptions($oCartItemData));
                                 }
                             }
                         }
                         $this->getUserTable()->commit();
                         $this->redirect()->toRoute('shop_cart/shop_cart_process', array('action' => 'items'), array());
                     }
                 } catch (\Exception $e) {
                     $this->getUserTable()->rollBack();
                     \Zend\Debug\Debug::dump($e->getMessage());
                     exit;
                 }
             }
         } else {
             $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();
                 $aBorrowerFine = $oUserSessionContainer->getBorrowerFine();
                 $nCredit = $oUserSessionContainer->getCredit();
                 $bSuccess = true;
             } else {
                 $sErrorMessage = 'getfine - XServer response: ' . $aBorrowerData['error'];
             }
         }
     } else {
         $sErrorMessage = 'getfine - podaj identyfikator czytelnika';
         $oUserSessionContainer->clear();
     }
     return new ViewModel(array('form' => $oBorrowerForm, 'expiration_item' => $aExpirationItem, 'borrower_fine' => $aBorrowerFine, 'credit' => $nCredit, 'success' => $bSuccess, 'error_message' => $sErrorMessage));
 }