/** * Get Holding * * This is responsible for retrieving the holding information of a certain * record. * * @param string $recordId The record id to retrieve the holdings for * @return mixed An associative array with the following keys: * availability (boolean), status, location, * reserve, callnumber, duedate, number, * holding summary, holding notes * If an error occurs, return a PEAR_Error * @access public */ public function getHolding($id, $allowReindex = true) { if (array_key_exists($id, EContentDriver::$holdings)) { return EContentDriver::$holdings[$id]; } global $user; global $configArray; $libaryScopeId = $this->getLibraryScopingId(); //Get any items that are stored for the record $eContentRecord = new EContentRecord(); $eContentRecord->id = $id; $eContentRecord->find(true); if ($eContentRecord->accessType != 'external') { //Check to see if the record is checked out or on hold within VuFind $checkedOutToUser = false; $onHoldForUser = false; $holdPosition = 0; if ($user) { $eContentCheckout = new EContentCheckout(); $eContentCheckout->userId = $user->id; $eContentCheckout->status = 'out'; $eContentCheckout->recordId = $id; $eContentCheckout->find(); if ($eContentCheckout->N > 0) { //The item is checked out to the current user $eContentCheckout->fetch(); $checkedOutToUser = true; } else { $eContentHold = new EContentHold(); $eContentHold->userId = $user->id; $eContentHold->whereAdd("status in ('active', 'suspended', 'available')"); $eContentHold->recordId = $id; $eContentHold->find(); if ($eContentHold->N > 0) { $onHoldForUser = true; $eContentHold->fetch(); $holdPosition = $this->_getHoldPosition($eContentHold); } } } $eContentItem = new EContentItem(); $eContentItem->recordId = $id; if ($libaryScopeId != -1) { $eContentItem->whereAdd("libraryId = -1 or libraryId = {$libaryScopeId}"); } $items = array(); $eContentItem->find(); while ($eContentItem->fetch()) { $item = clone $eContentItem; $item->source = $eContentRecord->source; //Generate links for the items $links = array(); if ($checkedOutToUser) { $links = $this->_getCheckedOutEContentLinks($eContentRecord, $item, $eContentCheckout); } else { if ($eContentRecord->accessType == 'free' && $item->isExternalItem()) { $links = $this->_getFreeExternalLinks($eContentRecord, $item); } else { if ($onHoldForUser) { $links = $this->getOnHoldEContentLinks($eContentHold); } } } $item->checkedOut = $checkedOutToUser; $item->onHold = $onHoldForUser; $item->holdPosition = $holdPosition; $item->links = $links; $items[] = $item; } } else { $items = $eContentRecord->getItems(); //We have econtent stored on an external server. Check to see if it is available there (if possible) if (strcasecmp($eContentRecord->source, 'OverDrive') == 0) { //Add links as needed $availability = $eContentRecord->getAvailability(); $addCheckoutLink = false; $addPlaceHoldLink = false; foreach ($availability as $availableFrom) { if ($availableFrom->libraryId == -1) { if ($availableFrom->availableCopies > 0) { $addCheckoutLink = true; } else { $addPlaceHoldLink = true; } } else { //Non shared item, check to see if we are in the correct scope to show it if ($libaryScopeId == -1 || $availableFrom->libraryId == $libaryScopeId) { if ($availableFrom->availableCopies > 0) { $addCheckoutLink = true; } else { $addPlaceHoldLink = true; } } } } foreach ($items as $key => $item) { $item->links = array(); if ($addCheckoutLink) { if ($configArray['OverDrive']['interfaceVersion'] == 1) { $checkoutLink = "return checkoutOverDriveItem('{$eContentRecord->externalId}', '{$item->externalFormatNumeric}');"; } else { $checkoutLink = "return checkoutOverDriveItemOneClick('{$eContentRecord->externalId}', '{$item->externalFormatNumeric}');"; } $item->links[] = array('onclick' => $checkoutLink, 'text' => 'Check Out', 'overDriveId' => $eContentRecord->externalId, 'formatId' => $item->externalFormatNumeric, 'action' => 'CheckOut'); } else { if ($addPlaceHoldLink) { $item->links[] = array('onclick' => "return placeOverDriveHold('{$eContentRecord->externalId}', '{$item->externalFormatNumeric}');", 'text' => 'Place Hold', 'overDriveId' => $eContentRecord->externalId, 'formatId' => $item->externalFormatNumeric, 'action' => 'Hold'); } } $items[$key] = $item; } } else { foreach ($items as $key => $item) { $item->links = $this->_getFreeExternalLinks($eContentRecord, $item); $items[$key] = $item; } } if ($libaryScopeId != -1) { foreach ($items as $key => $item) { if ($item->libraryId != -1 && $item->libraryId != $libaryScopeId) { unset($items[$key]); } } } } EContentDriver::$holdings[$id] = $items; return $items; }