function checkout($itemId)
 {
     global $user;
     if (!$user) {
         return array('result' => false, 'message' => 'You must be logged in to checkout a title');
     } else {
         require_once ROOT_DIR . '/sys/eContent/EContentCheckout.php';
         $eContentCheckout = new EContentCheckout();
         $eContentCheckout->userId = $user->id;
         $eContentCheckout->recordId = $this->getUniqueID();
         $eContentCheckout->itemId = $itemId;
         $eContentCheckout->protectionType = 'free';
         if ($eContentCheckout->find(true) && $eContentCheckout->status == 'out') {
             return array('result' => true, 'message' => 'This title is already checked out to you');
         } else {
             global $configArray;
             $eContentCheckout->dateCheckedOut = time();
             $loanTerm = $configArray['EContent']['loanTerm'];
             $eContentCheckout->dateDue = time() + $loanTerm * 24 * 60 * 60;
             //Allow titles to be checked our for 3 weeks
             $eContentCheckout->status = 'out';
             if ($eContentCheckout->insert()) {
                 return array('result' => true, 'message' => 'The title was checked out to you successfully.  You may read it from Checked Out page within your account.');
             } else {
                 return array('result' => false, 'message' => 'Unexpected error checking out the title.');
             }
         }
     }
 }
示例#2
0
 public function checkoutRecord($id, $user)
 {
     global $configArray;
     $return = array();
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     $eContentRecord->find(true);
     $return['title'] = $eContentRecord->title;
     //Check to see if the user already has the record checked out
     $checkouts = new EContentCheckout();
     $checkouts->userId = $user->id;
     $checkouts->status = 'out';
     $checkouts->recordId = $id;
     $checkouts->find();
     if ($checkouts->N > 0) {
         $return['result'] = false;
         $return['message'] = "That record is already checked out to you, unable to check it out again.";
     } else {
         //Check to see if the record is on hold for the current user
         $holds = new EContentHold();
         $holds->userId = $user->id;
         $holds->recordId = $id;
         $holds->whereAdd("status != 'filled' AND status != 'cancelled' AND status != 'abandoned'");
         $checkoutRecord = true;
         if ($holds->find(true)) {
             if ($holds->status == 'available') {
                 $checkoutRecord = true;
                 $holds->status = 'filled';
                 $holds->dateUpdated = time();
                 $ret = $holds->update();
                 $checkoutRecord = $ret == 1;
             } else {
                 $checkoutRecord = false;
                 $return['result'] = false;
                 $return['message'] = "This title is already on hold for you.";
             }
         } else {
             //Check to see if there are any available copies
             $holdings = $this->getHolding($id);
             $statusSummary = $this->getStatusSummary($id, $holdings);
             if ($statusSummary['availableCopies'] == 0) {
                 $return['result'] = false;
                 $return['message'] = "There are no available copies of this title, please place a hold instead.";
             } else {
                 $checkoutRecord = true;
             }
         }
         if ($checkoutRecord) {
             //Checkout the record to the user
             $checkout = new EContentCheckout();
             $checkout->userId = $user->id;
             $checkout->recordId = $id;
             $checkout->status = 'out';
             $checkout->dateCheckedOut = time();
             $loanTerm = $configArray['EContent']['loanTerm'];
             $checkout->dateDue = time() + $loanTerm * 24 * 60 * 60;
             //Allow titles to be checked our for 3 weeks
             if ($checkout->insert()) {
                 $return['result'] = true;
                 $return['message'] = "The title was checked out to you successfully.  You may read it from Checked Out eBooks and eAudio page within your account.";
                 //Record that the record was checked out
                 $this->recordEContentAction($id, "Checked Out", $eContentRecord->accessType);
                 //Add the records to the reading history for the user
                 if ($user->trackReadingHistory == 1) {
                     $this->addRecordToReadingHistory($eContentRecord, $user);
                 }
                 //If there are no more records available, reindex
                 //Don't force a reindex to improve speed and deal with non xml characters
                 //$eContentRecord->saveToSolr();
             }
         }
     }
     return $return;
 }
 function checkout($itemId)
 {
     global $user;
     if (!$user) {
         return array('result' => false, 'message' => 'You must be logged in to checkout a title');
     } else {
         //TODO: count the existing checkouts to determine if there are items available
         $items = $this->getItems();
         $userHasAccess = false;
         foreach ($items as $item) {
             if ($item['itemId'] == $itemId) {
                 $userHasAccess = true;
             }
         }
         if (!$userHasAccess) {
             return array('result' => false, 'message' => "Sorry, you don't have access to this title.");
         } else {
             require_once ROOT_DIR . '/sys/eContent/EContentCheckout.php';
             $eContentCheckout = new EContentCheckout();
             $eContentCheckout->userId = $user->id;
             $eContentCheckout->recordId = $this->getUniqueID();
             $eContentCheckout->itemId = $itemId;
             $eContentCheckout->protectionType = 'acs';
             if ($eContentCheckout->find(true) && $eContentCheckout->status == 'out') {
                 return array('result' => true, 'message' => 'This title is already checked out to you');
             } else {
                 global $configArray;
                 $eContentCheckout->dateCheckedOut = time();
                 $loanTerm = $configArray['EContent']['loanTerm'];
                 $eContentCheckout->dateDue = time() + $loanTerm * 24 * 60 * 60;
                 //Allow titles to be checked our for 3 weeks
                 $eContentCheckout->status = 'out';
                 $eContentCheckout->title = $this->getTitle();
                 $eContentCheckout->author = $this->getAuthor();
                 if ($eContentCheckout->insert()) {
                     return array('result' => true, 'message' => 'The title was checked out to you successfully.  You may read it from Checked Out page within your account.');
                 } else {
                     return array('result' => false, 'message' => 'Unexpected error checking out the title.');
                 }
             }
         }
     }
 }