Ejemplo n.º 1
0
 public function placeHold($id, $user)
 {
     $id = str_ireplace("econtentrecord", "", $id);
     $return = array();
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     if (!$eContentRecord->find(true)) {
         $return['result'] = false;
         $return['message'] = "Could not find a record with an id of {$id}";
     } else {
         $return['title'] = $eContentRecord->title;
         //If the source is overdrive, process it as an overdrive title
         if (strcasecmp($eContentRecord->source, 'OverDrive') == 0) {
             require_once ROOT_DIR . '/Drivers/OverDriveDriverFactory.php';
             $overDriveDriver = OverDriveDriverFactory::getDriver();
             $overDriveResult = $overDriveDriver->placeOverDriveHold($eContentRecord->externalId, '', $user);
             $return['result'] = $overDriveResult['result'];
             $return['message'] = $overDriveResult['message'];
         } else {
             //Check to see if the user already has a hold placed
             $holds = new EContentHold();
             $holds->userId = $user->id;
             $holds->recordId = $id;
             $holds->whereAdd("(status = 'active' or status = 'suspended' or status ='available')");
             $holds->find();
             if ($holds->N > 0) {
                 $return['result'] = false;
                 $return['message'] = "That record is already on hold for you, unable to place a second hold.";
             } else {
                 //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 place a hold.";
                 } else {
                     //Check to see if there are any available copies and then checkout the record rather than placing a hold
                     $holdings = $this->getHolding($id);
                     $holdingsSummary = $this->getStatusSummary($id, $holdings);
                     if ($holdingsSummary['availableCopies'] > 0 || $eContentRecord->accessType == 'free') {
                         //The record can be checked out directly
                         $ret = $this->checkoutRecord($id, $user);
                         return $ret;
                     } else {
                         //Place the hold for the user
                         $hold = new EContentHold();
                         $hold->userId = $user->id;
                         $hold->recordId = $id;
                         $hold->status = 'active';
                         $hold->datePlaced = time();
                         $hold->dateUpdated = time();
                         if ($hold->insert()) {
                             $return['result'] = true;
                             $holdPosition = $this->_getHoldPosition($hold);
                             $return['message'] = "Your hold was successfully placed, you are number {$holdPosition} in the queue.";
                             //Record that the record had a hold placed on it
                             $this->recordEContentAction($id, "Place Hold", $eContentRecord->accessType);
                         }
                     }
                 }
             }
         }
     }
     if ($return['result'] == true) {
         //Make a call to strands to update that the item was placed on hold
         global $configArray;
         global $user;
         if (isset($configArray['Strands']['APID']) && $user->disableRecommendations == 0) {
             $strandsUrl = "http://bizsolutions.strands.com/api2/event/addshoppingcart.sbs?needresult=true&apid={$configArray['Strands']['APID']}&item=econtentRecord{$id}&user={$user->id}";
             $ret = file_get_contents($strandsUrl);
         }
     }
     return $return;
 }
 public function placeHold($itemId)
 {
     global $user;
     if (!$user) {
         return array('result' => false, 'message' => 'You must be logged in to place a hold');
     } else {
         require_once ROOT_DIR . '/sys/eContent/EContentHold.php';
         $eContentHold = new EContentHold();
         $eContentHold->userId = $user->id;
         $eContentHold->recordId = $this->getUniqueID();
         $eContentHold->itemId = $itemId;
         $eContentHold->whereAdd("status NOT IN ('cancelled', 'filled')");
         if (!$eContentHold->find(true)) {
             //Make sure the user has access to the title
             $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 {
                 $eContentHold->status = 'active';
                 $eContentHold->datePlaced = time();
                 $eContentHold->title = $this->getTitle();
                 $eContentHold->author = $this->getAuthor();
                 if ($eContentHold->insert()) {
                     return array('result' => true, 'message' => 'Successfully placed hold for you.');
                 } else {
                     return array('result' => false, 'message' => 'There was an unknown error placing a hold on this title.');
                 }
             }
         } else {
             return array('result' => false, 'message' => 'Sorry, this title is already on hold for you.');
         }
     }
 }