/** * Load status (holdings) for a record and filter them based on the logged in user information. * * Format of return array is: * key = {section#}{location}-### where ### is the holding iteration * * value = array ( * id = The id of the bib * number = The position of the holding within the original list of holdings * section = A description of the section * sectionId = a numeric id of the section for sorting * type = holding * status * statusfull * availability * holdable * nonHoldableReason * reserve * holdQueueLength * duedate * location * libraryDisplayName * locationCode * locationLink * callnumber * link = array * linkText * isDownload * ) * * Includes both physical titles as well as titles on order * * @param string $id the id of the record * @return array A list of holdings for the record */ public function getHolding($id) { if (array_key_exists($id, HorizonAPI::$loadedStatus)) { return HorizonAPI::$loadedStatus[$id]; } global $configArray; global $library; //Get location information so we can put things into sections global $locationSingleton; /** @var $locationSingleton Location */ $physicalLocation = $locationSingleton->getPhysicalLocation(); if ($physicalLocation != null) { $physicalBranch = $physicalLocation->holdingBranchLabel; } else { $physicalBranch = ''; } $homeBranch = ''; $homeBranchId = 0; $nearbyBranch1 = ''; $nearbyBranch1Id = 0; $nearbyBranch2 = ''; $nearbyBranch2Id = 0; //Set location information based on the user login. This will override information based if (isset($user) && $user != false) { $homeBranchId = $user->homeLocationId; $nearbyBranch1Id = $user->myLocation1Id; $nearbyBranch2Id = $user->myLocation2Id; } else { //Check to see if the cookie for home location is set. if (isset($_COOKIE['home_location']) && is_numeric($_COOKIE['home_location'])) { $cookieLocation = new Location(); $locationId = $_COOKIE['home_location']; $cookieLocation->whereAdd("locationId = '{$locationId}'"); $cookieLocation->find(); if ($cookieLocation->N == 1) { $cookieLocation->fetch(); $homeBranchId = $cookieLocation->locationId; $nearbyBranch1Id = $cookieLocation->nearbyLocation1; $nearbyBranch2Id = $cookieLocation->nearbyLocation2; } } } //Load the holding label for the user's home location. $userLocation = new Location(); $userLocation->whereAdd("locationId = '{$homeBranchId}'"); $userLocation->find(); if ($userLocation->N == 1) { $userLocation->fetch(); $homeBranch = $userLocation->holdingBranchLabel; } //Load nearby branch 1 $nearbyLocation1 = new Location(); $nearbyLocation1->whereAdd("locationId = '{$nearbyBranch1Id}'"); $nearbyLocation1->find(); if ($nearbyLocation1->N == 1) { $nearbyLocation1->fetch(); $nearbyBranch1 = $nearbyLocation1->holdingBranchLabel; } //Load nearby branch 2 $nearbyLocation2 = new Location(); $nearbyLocation2->whereAdd(); $nearbyLocation2->whereAdd("locationId = '{$nearbyBranch2Id}'"); $nearbyLocation2->find(); if ($nearbyLocation2->N == 1) { $nearbyLocation2->fetch(); $nearbyBranch2 = $nearbyLocation2->holdingBranchLabel; } //Get a list of items from Horizon $lookupTitleInfoUrl = $configArray['Catalog']['webServiceUrl'] . '/standard/lookupTitleInfo?clientID=' . $configArray['Catalog']['clientId'] . '&titleKey=' . $id . '&includeItemInfo=true&includeHoldCount=true'; $lookupTitleInfoResponse = $this->getWebServiceResponse($lookupTitleInfoUrl); $holdings = array(); if ($lookupTitleInfoResponse->titleInfo) { $i = 0; foreach ($lookupTitleInfoResponse->titleInfo->itemInfo as $itemInfo) { if (!isset($itemInfo->locationID)) { //Suppress anything without a location code continue; } $i++; $holding = array('id' => $id, 'number' => $i++, 'type' => 'holding', 'status' => isset($itemInfo->statusID) ? (string) $itemInfo->statusID : 'Unknown', 'statusfull' => isset($itemInfo->statusDescription) ? (string) $itemInfo->statusDescription : 'Unknown', 'availability' => isset($itemInfo->available) ? (string) $itemInfo->available == "true" : false, 'holdable' => true, 'reserve' => 'N', 'holdQueueLength' => (int) $lookupTitleInfoResponse->titleInfo->holdCount, 'dueDate' => isset($itemInfo->dueDate) ? (string) $itemInfo->dueDate : 'Unknown', 'locationCode' => (string) $itemInfo->locationID, 'location' => (string) $itemInfo->locationDescription, 'callnumber' => (string) $itemInfo->callNumber, 'isDownload' => false, 'barcode' => (string) $itemInfo->barcode, 'isLocalItem' => false, 'isLibraryItem' => true, 'locationLabel' => (string) $itemInfo->locationDescription, 'shelfLocation' => (string) $itemInfo->locationDescription); $holding['groupedStatus'] = mapValue('item_grouped_status', $holding['status']); $paddedNumber = str_pad($i, 3, '0', STR_PAD_LEFT); $sortString = $holding['location'] . '-' . $paddedNumber; //$sortString = $holding['location'] . $holding['callnumber']. $i; if (strlen($physicalBranch) > 0 && stripos($holding['location'], $physicalBranch) !== false) { //If the user is in a branch, those holdings come first. $holding['section'] = 'In this library'; $holding['sectionId'] = 1; $holding['isLocalItem'] = true; $sorted_array['1' . $sortString] = $holding; } else { if (strlen($homeBranch) > 0 && stripos($holding['location'], $homeBranch) !== false) { //Next come the user's home branch if the user is logged in or has the home_branch cookie set. $holding['section'] = 'Your library'; $holding['sectionId'] = 2; $holding['isLocalItem'] = true; $sorted_array['2' . $sortString] = $holding; } else { if (strlen($nearbyBranch1) > 0 && stripos($holding['location'], $nearbyBranch1) !== false) { //Next come nearby locations for the user $holding['section'] = 'Nearby Libraries'; $holding['sectionId'] = 3; $sorted_array['3' . $sortString] = $holding; } else { if (strlen($nearbyBranch2) > 0 && stripos($holding['location'], $nearbyBranch2) !== false) { //Next come nearby locations for the user $holding['section'] = 'Nearby Libraries'; $holding['sectionId'] = 4; $sorted_array['4' . $sortString] = $holding; //MDN 11/17 - taken out because all Horizon libraries are single institution (so far) /*} else if (strlen($libraryLocationLabels) > 0 && preg_match($libraryLocationLabels, $holding['location'])){ //Next come any locations within the same system we are in. $holding['section'] = $library->displayName; $holding['sectionId'] = 5; $sorted_array['5' . $sortString] = $holding; */ } else { //Finally, all other holdings are shown sorted alphabetically. $holding['section'] = $library->displayName; $holding['sectionId'] = 5; $sorted_array['5' . $sortString] = $holding; } } } } $holdings[] = $holding; } } return $holdings; }
function getRelatedRecords($realTimeStatusNeeded) { global $configArray; global $timer; $recordId = $this->getUniqueID(); $timer->logTime("Starting getRelatedRecords for OverDrive record {$recordId}"); $availability = $this->getAvailability(); $timer->logTime("Finished loading availability"); $available = false; $availableCopies = 0; $totalCopies = 0; $numHolds = 0; $hasLocalItem = true; foreach ($availability as $curAvailability) { if ($curAvailability->available) { $available = true; $availableCopies += $curAvailability->copiesAvailable; } $totalCopies += $curAvailability->copiesOwned; } //If there are no copies, this isn't valid if ($totalCopies == 0 && $availableCopies == 0) { return array(); } $url = $configArray['Site']['path'] . '/OverDrive/' . $recordId; $this->getOverDriveMetaData(); $timer->logTime("Finished loading metadata"); $format = $this->overDriveProduct->mediaType; if ($format == 'Audiobook') { $format = 'eAudiobook'; } elseif ($format == 'Music') { $format = 'eMusic'; } $relatedRecord = array('id' => $recordId, 'url' => $url, 'format' => $format, 'edition' => '', 'language' => $this->getLanguage(), 'title' => $this->overDriveProduct->title, 'subtitle' => $this->overDriveProduct->subtitle, 'publisher' => $this->overDriveMetaData->publisher, 'publicationDate' => $this->overDriveMetaData->publishDate, 'section' => '', 'physical' => '', 'callNumber' => '', 'shelfLocation' => '', 'availableOnline' => $available, 'available' => $available, 'hasLocalItem' => $hasLocalItem, 'copies' => $totalCopies, 'numHolds' => $numHolds, 'availableCopies' => $availableCopies, 'holdRatio' => $totalCopies > 0 ? $availableCopies + ($totalCopies - $numHolds) / $totalCopies : 0, 'locationLabel' => 'Online', 'source' => 'OverDrive', 'actions' => array()); $formatCategory = mapValue('format_category_by_format', $relatedRecord['format']); $relatedRecord['formatCategory'] = $formatCategory; if ($available) { $relatedRecord['actions'][] = array('title' => 'Check Out', 'onclick' => "return VuFind.OverDrive.checkoutOverDriveItemOneClick('{$recordId}');", 'requireLogin' => false); } else { $relatedRecord['actions'][] = array('title' => 'Place Hold', 'onclick' => "return VuFind.OverDrive.placeOverDriveHold('{$recordId}');", 'requireLogin' => false); } $timer->logTime("Finished getRelatedRecords for OverDrive record {$recordId}"); return array($relatedRecord); }
function getFormatCategory() { /** @var File_MARC_Data_Field[] $itemFields */ $itemFields = $this->getMarcRecord()->getFields('989'); foreach ($itemFields as $item) { $subfieldW = $item->getSubfield('w'); if ($subfieldW != null) { if (strpos($subfieldW->getData(), ':') !== FALSE) { $eContentFieldData = explode(':', $subfieldW->getData()); $protectionType = trim($eContentFieldData[1]); if ($this->isValidProtectionType($protectionType)) { //Format is based off the iType $iTypeField = $item->getSubfield('j'); if ($iTypeField != null) { return mapValue('econtent_itype_format_category', $iTypeField->getData()); } else { return 'eBook'; } } } } } return 'eBook'; }
function getEContentFormatCategory($fileOrUrl, $iType) { if ($fileOrUrl) { $fileExtension = ''; if (strpos($fileOrUrl, '.') !== FALSE) { $fileExtension = substr($fileOrUrl, strrpos($fileOrUrl, '.') + 1); } $format = mapValue('format_category', $fileExtension); } if (isset($format) && strlen($format) > 0) { return $format; } else { return mapValue('econtent_itype_format', $iType); } }
/** * Load all items from the database. * * Uses some code based on C4::Items GetItemsInfo in koha * * @param $recordId * @return array */ private function getHoldingsFromKohaDB($recordId) { $holdingsFromKoha = array(); $this->initDatabaseConnection(); if ($this->getHoldingsStmt == null) { $sql = "SELECT itemnumber, barcode, itype, holdingbranch, location, itemcallnumber, onloan, ccode, itemnotes, enumchron, damaged, itemlost, wthdrawn, restricted FROM items where biblionumber = ? AND suppress = 0"; $this->getHoldingsStmt = mysqli_prepare($this->dbConnection, $sql); } $this->getHoldingsStmt->bind_param("i", $recordId); if (!$this->getHoldingsStmt->execute()) { global $logger; $logger->log("Unable to load holdings from Koha ({$this->getHoldingsStmt->errno}) {$this->getHoldingsStmt->error}", PEAR_LOG_ERR); } else { //Read the information $results = $this->getHoldingsStmt->get_result(); while ($curRow = $results->fetch_assoc()) { if ($curRow['itype'] == 'EAUDIO' || $curRow['itype'] == 'EBOOK' || $curRow['itype'] == 'ONLINE') { continue; } $curItem = array(); $curItem['type'] = 'holding'; $curItem['id'] = $curRow['itemnumber']; $curItem['barcode'] = $curRow['barcode']; $curItem['itemType'] = mapValue('itype', $curRow['itype']); $curItem['locationCode'] = $curRow['location']; $curItem['library'] = mapValue('location', $curRow['holdingbranch']); $curItem['location'] = $curRow['location']; $curItem['collection'] = mapValue('ccode', $curRow['ccode']); $curItem['callnumber'] = $curRow['itemcallnumber']; $curItem['volInfo'] = $curRow['enumchron']; $curItem['copy'] = $curRow['itemcallnumber']; $curItem['notes'] = $curRow['itemnotes']; $curItem['dueDate'] = $curRow['onloan']; //Figure out status based on all of the fields that make up the status if ($curRow['damaged'] == 1) { $curItem['status'] = "Damaged"; } else { if ($curRow['itemlost'] != null) { if ($curRow['itemlost'] == 'longoverdue') { $curItem['status'] = "Long Overdue"; } elseif ($curRow['itemlost'] == 'missing') { $curItem['status'] = "Missing"; } elseif ($curRow['itemlost'] == 'lost') { $curItem['status'] = "Lost"; } elseif ($curRow['itemlost'] == 'trace') { $curItem['status'] = "Trace"; } } else { if ($curRow['restricted'] == 1) { $curItem['status'] = "Not For Loan"; } else { if ($curRow['wthdrawn'] == 1) { $curItem['status'] = "Withdrawn"; } else { if ($curItem['dueDate'] == null) { $curItem['status'] = "On Shelf"; } else { $curItem['status'] = "Due {$curItem['dueDate']}"; } } } } } $holdingsFromKoha[] = $curItem; } $results->close(); } return $holdingsFromKoha; }
public function getItemsFast() { global $timer; if ($this->fastItems == null || isset($_REQUEST['reload'])) { $searchLibrary = Library::getSearchLibrary(); $extraLocations = ''; if ($searchLibrary) { $libraryLocationCode = $searchLibrary->ilsCode; } $searchLocation = Location::getSearchLocation(); if ($searchLocation) { $homeLocationCode = $searchLocation->code; $extraLocations = $searchLocation->extraLocationCodesToInclude; } if ($this->itemsFromIndex) { $this->fastItems = array(); foreach ($this->itemsFromIndex as $itemData) { $isOrderItem = false; $onOrderCopies = 0; $status = null; $groupedStatus = null; $inLibraryUseOnly = false; $isHoldable = true; $isLocalItem = false; $isLibraryItem = false; if (array_key_exists('item', $itemData)) { //New style with item, record, and scope information separated $shelfLocation = $itemData['item'][7]; $locationCode = $itemData['item'][1]; $callNumber = $itemData['item'][2]; if (substr($itemData['item'][0], 0, 2) == '.o') { $isOrderItem = true; $onOrderCopies = $itemData['item'][7]; $available = false; $shelfLocation = mapValue('shelf_location', $itemData['item'][1]); } else { $status = mapValue('item_status', $itemData['item'][6]); $groupedStatus = mapValue('item_grouped_status', $itemData['item'][6]); $available = $itemData['item'][3] == 'true'; $inLibraryUseOnly = $itemData['item'][4] == 'true'; } //Don't use scoping section yet because it isn't ready for prime time. /*if (array_key_exists('scope', $itemData) && count($itemData['scope']) > 0){ $isHoldable = $itemData['scope'][0] == 'true'; $isLocalItem = $itemData['scope'][1] == 'true'; $isLibraryItem = $itemData['scope'][2] == 'true'; }*/ if (!isset($libraryLocationCode) || $libraryLocationCode == '') { $isLibraryItem = true; } else { $isLibraryItem = strpos($locationCode, $libraryLocationCode) === 0; } $isLocalItem = isset($homeLocationCode) && strlen($homeLocationCode) > 0 && strpos($locationCode, $homeLocationCode) === 0 || $extraLocations != '' && preg_match("/^{$extraLocations}\$/i", $locationCode); } else { //Old style where record and item information are combined $shelfLocation = $itemData[2]; $locationCode = $itemData[2]; if (strpos($shelfLocation, ':') === false) { $shelfLocation = mapValue('shelf_location', $itemData[2]); } else { $shelfLocationParts = explode(":", $shelfLocation); $locationCode = $shelfLocationParts[0]; $branch = mapValue('shelf_location', $locationCode); $shelfLocationTmp = mapValue('collection', $shelfLocationParts[1]); $shelfLocation = $branch . ' ' . $shelfLocationTmp; } $callNumber = $itemData[3]; if (substr($itemData[1], 0, 2) == '.o') { $isOrderItem = true; $onOrderCopies = $itemData[8]; $available = false; } else { $status = mapValue('item_status', $itemData[7]); $groupedStatus = mapValue('item_grouped_status', $itemData[7]); $available = $itemData[4] == 'true'; $inLibraryUseOnly = $itemData[5] == 'true'; } if (!isset($libraryLocationCode) || $libraryLocationCode == '') { $isLibraryItem = true; } else { $isLibraryItem = strpos($locationCode, $libraryLocationCode) === 0; } $isLocalItem = isset($homeLocationCode) && strlen($homeLocationCode) > 0 && strpos($locationCode, $homeLocationCode) === 0 || $extraLocations != '' && preg_match("/^{$extraLocations}\$/i", $locationCode); } //Try to trim the courier code if any if (preg_match('/(.*?)\\sC\\d{3}\\w{0,2}$/', $shelfLocation, $locationParts)) { $shelfLocation = $locationParts[1]; } //Determine the structure of the item data based on if it's an order record or not. //TODO: This needs a better way of handling things because .o will only work for Sierra/Millennium systems if ($isOrderItem) { $groupedStatus = "On Order"; $callNumber = "ON ORDER"; $status = "On Order"; } else { //This is a regular (physical) item if ($status != null) { if ($status == 'On Shelf' && $available != true) { $status = 'Checked Out'; $groupedStatus = "Checked Out"; } } else { if ($available) { $status = "On Shelf"; $groupedStatus = "On Shelf"; } else { $status = "Checked Out"; $groupedStatus = "Checked Out"; } } } $this->fastItems[] = array('location' => $locationCode, 'callnumber' => $callNumber, 'availability' => $available, 'holdable' => $isHoldable, 'inLibraryUseOnly' => $inLibraryUseOnly, 'isLibraryItem' => $isLibraryItem, 'isLocalItem' => $isLocalItem, 'locationLabel' => true, 'shelfLocation' => $shelfLocation, 'onOrderCopies' => $onOrderCopies, 'status' => $status, 'groupedStatus' => $groupedStatus); } $timer->logTime("Finished getItemsFast for marc record based on data in index"); } else { $driver = MarcRecord::getCatalogDriver(); $this->fastItems = $driver->getItemsFast($this->getUniqueID(), $this->scopingEnabled, $this->getMarcRecord()); $timer->logTime("Finished getItemsFast for marc record based on data in driver"); } } return $this->fastItems; }
function getEContentFormat($fileOrUrl, $iType) { return mapValue('econtent_itype_format', $iType); }
/** * Loads items information as quickly as possible (no direct calls to the ILS). Does do filtering by loan rules * * return is an array of items with the following information: * location * callnumber * available * holdable * lastStatusCheck (time) * * @param $id * @param $scopingEnabled * @param $marcRecord * @return mixed */ public function getItemsFast($id, $scopingEnabled, $marcRecord = null) { if ($marcRecord == null) { $marcRecord = MarcLoader::loadMarcRecordByILSId($id); global $timer; $timer->logTime("Finished loading MARC Record for getItemsFast"); } MillenniumDriver::loadLibraryLocationInformation(); //Get the items Fields from the record /** @var File_MARC_Data_Field[] $itemFields */ $itemFields = $marcRecord->getFields('989'); global $timer; $timer->logTime("Finished loading item fields for {$id}, found " . count($itemFields)); $items = array(); $pType = $this->getPType(); //$timer->logTime("Finished loading pType"); global $configArray; $statusSubfield = $configArray['Reindex']['statusSubfield']; $iTypeSubfield = $configArray['Reindex']['iTypeSubfield']; $dueDateSubfield = $configArray['Reindex']['dueDateSubfield']; $lastCheckinDateSubfield = $configArray['Reindex']['lastCheckinDateSubfield']; foreach ($itemFields as $itemField) { //Ignore eContent items $eContentData = trim($itemField->getSubfield('w') != null ? $itemField->getSubfield('w')->getData() : ''); if ($eContentData && strpos($eContentData, ':') > 0) { continue; } $locationCode = $itemField->getSubfield('d') != null ? trim($itemField->getSubfield('d')->getData()) : ''; //Do a quick check of location code so we can remove this quickly when scoping is enabled if ($scopingEnabled && strlen(MillenniumDriver::$scopingLocationCode) > 0 && strpos($locationCode, MillenniumDriver::$scopingLocationCode) !== 0) { global $logger; $logger->log("Removed item because scoping is enabled and the location code {$locationCode} did not start with " . MillenniumDriver::$scopingLocationCode, PEAR_LOG_DEBUG); continue; } $iType = $itemField->getSubfield($iTypeSubfield) != null ? trim($itemField->getSubfield($iTypeSubfield)->getData()) : ''; $holdable = $this->isItemHoldableToPatron($locationCode, $iType, $pType); $isLibraryItem = false; $locationLabel = ''; foreach (MillenniumDriver::$libraryLocations as $tmpLocation) { if (strpos($locationCode, $tmpLocation) === 0) { $isLibraryItem = true; $locationLabel = MillenniumDriver::$libraryLocationLabels[$tmpLocation]; break; } } $timer->logTime("Finished checking if item is holdable"); //Check to make sure the user has access to this item if ($holdable || $isLibraryItem) { $isLocalItem = false; if (MillenniumDriver::$homeLocationCode != null && strpos($locationCode, MillenniumDriver::$homeLocationCode) === 0) { $isLocalItem = true; $locationLabel = MillenniumDriver::$homeLocationLabel; } $status = trim($itemField->getSubfield($statusSubfield) != null ? trim($itemField->getSubfield($statusSubfield)->getData()) : ''); $dueDate = $itemField->getSubfield($dueDateSubfield) != null ? trim($itemField->getSubfield($dueDateSubfield)->getData()) : null; $lastCheckinDate = $itemField->getSubfield($lastCheckinDateSubfield); if ($lastCheckinDate) { // convert to timestamp for ease of display in template $lastCheckinDate = trim($lastCheckinDate->getData()); $lastCheckinDate = DateTime::createFromFormat('m-d-Y G:i', $lastCheckinDate); if ($lastCheckinDate) { $lastCheckinDate = $lastCheckinDate->getTimestamp(); } } if (!$lastCheckinDate) { $lastCheckinDate = null; } $available = in_array($status, array('-', 'o', 'd', 'w', ')', 'u')) && ($dueDate == null || strlen($dueDate) == 0); $inLibraryUseOnly = $status == 'o'; $fullCallNumber = $itemField->getSubfield('s') != null ? $itemField->getSubfield('s')->getData() . ' ' : ''; $fullCallNumber .= $itemField->getSubfield('a') != null ? $itemField->getSubfield('a')->getData() : ''; $fullCallNumber .= $itemField->getSubfield('r') != null ? ' ' . $itemField->getSubfield('r')->getData() : ''; $fullCallNumber .= $itemField->getSubfield('v') != null ? ' ' . $itemField->getSubfield('v')->getData() : ''; $shelfLocation = mapValue('shelf_location', $locationCode); if (preg_match('/(.*?)\\sC\\d{3}\\w{0,2}$/', $shelfLocation, $locationParts)) { $shelfLocation = $locationParts[1]; } $item = array('location' => $locationCode, 'callnumber' => $fullCallNumber, 'availability' => $available, 'holdable' => $holdable, 'inLibraryUseOnly' => $inLibraryUseOnly, 'isLocalItem' => $isLocalItem, 'isLibraryItem' => $isLibraryItem, 'locationLabel' => $locationLabel, 'shelfLocation' => $shelfLocation, 'status' => $status, 'dueDate' => $dueDate, 'iType' => $iType, 'lastCheckinDate' => $lastCheckinDate); $items[] = $item; } //$timer->logTime("Finished processing item"); } global $timer; $timer->logTime("Finished load items fast for Millennium record {$id} there were " . count($itemFields) . " item fields originally, filtered to " . count($items)); return $items; }
protected function translateStatusCode($status, $dueDate) { if ($status == '-') { if (!is_null($dueDate) && strlen($dueDate) > 0 && $dueDate != '- -') { //Reformat the date global $configArray; $dueDateAsDate = DateTime::createFromFormat("ymd", $dueDate); if ($dueDateAsDate) { return 'Due ' . $dueDateAsDate->format('m-d-y'); } else { return 'Due ' . $dueDate; } } else { return 'On Shelf'; } } else { return mapValue('item_status', $status); } }
public function translateStatus($statusCode) { return mapValue('item_status', $statusCode); }
public function getRelatedManifestations() { global $timer; $timer->logTime("Starting to load related records in getRelatedManifestations"); $relatedRecords = $this->getRelatedRecords(); $timer->logTime("Finished loading related records in getRelatedManifestations"); //Group the records based on format $relatedManifestations = array(); foreach ($relatedRecords as $curRecord) { if (!array_key_exists($curRecord['format'], $relatedManifestations)) { $relatedManifestations[$curRecord['format']] = array('format' => $curRecord['format'], 'formatCategory' => $curRecord['formatCategory'], 'copies' => 0, 'availableCopies' => 0, 'localCopies' => 0, 'localAvailableCopies' => 0, 'onOrderCopies' => 0, 'numHolds' => 0, 'available' => false, 'hasLocalItem' => false, 'relatedRecords' => array(), 'preferredEdition' => null, 'statusMessage' => '', 'itemLocations' => array(), 'availableLocally' => false, 'availableOnline' => false, 'availableHere' => false, 'inLibraryUseOnly' => false, 'allLibraryUseOnly' => true, 'hideByDefault' => false, 'itemSummary' => array(), 'itemSummaryLocal' => array(), 'groupedStatus' => ''); } if (isset($curRecord['availableLocally']) && $curRecord['availableLocally'] == true) { $relatedManifestations[$curRecord['format']]['availableLocally'] = true; } if (isset($curRecord['availableHere']) && $curRecord['availableHere'] == true) { $relatedManifestations[$curRecord['format']]['availableHere'] = true; } if ($curRecord['available'] && $curRecord['locationLabel'] === 'Online') { $relatedManifestations[$curRecord['format']]['availableOnline'] = true; } if (isset($curRecord['availableOnline']) && $curRecord['availableOnline']) { $relatedManifestations[$curRecord['format']]['availableOnline'] = true; } if (!$relatedManifestations[$curRecord['format']]['available'] && $curRecord['available']) { $relatedManifestations[$curRecord['format']]['available'] = $curRecord['available']; } if (isset($curRecord['inLibraryUseOnly']) && $curRecord['inLibraryUseOnly']) { $relatedManifestations[$curRecord['format']]['inLibraryUseOnly'] = $curRecord['inLibraryUseOnly']; } else { $relatedManifestations[$curRecord['format']]['allLibraryUseOnly'] = false; } if (!$relatedManifestations[$curRecord['format']]['hasLocalItem'] && $curRecord['hasLocalItem']) { $relatedManifestations[$curRecord['format']]['hasLocalItem'] = $curRecord['hasLocalItem']; } if ($curRecord['shelfLocation']) { $relatedManifestations[$curRecord['format']]['shelfLocation'][$curRecord['shelfLocation']] = $curRecord['shelfLocation']; } if ($curRecord['callNumber']) { $relatedManifestations[$curRecord['format']]['callNumber'][$curRecord['callNumber']] = $curRecord['callNumber']; } $relatedManifestations[$curRecord['format']]['relatedRecords'][] = $curRecord; $relatedManifestations[$curRecord['format']]['copies'] += $curRecord['copies']; $relatedManifestations[$curRecord['format']]['availableCopies'] += $curRecord['availableCopies']; if ($curRecord['hasLocalItem']) { $relatedManifestations[$curRecord['format']]['localCopies'] += isset($curRecord['localCopies']) ? $curRecord['localCopies'] : 0; $relatedManifestations[$curRecord['format']]['localAvailableCopies'] += isset($curRecord['localAvailableCopies']) ? $curRecord['localAvailableCopies'] : 0; } if (isset($curRecord['itemSummary'])) { $relatedManifestations[$curRecord['format']]['itemSummary'] = $this->mergeItemSummary($relatedManifestations[$curRecord['format']]['itemSummary'], $curRecord['itemSummary']); } if ($curRecord['numHolds']) { $relatedManifestations[$curRecord['format']]['numHolds'] += $curRecord['numHolds']; } if (isset($curRecord['onOrderCopies'])) { $relatedManifestations[$curRecord['format']]['onOrderCopies'] += $curRecord['onOrderCopies']; } $statusRankings = array('On Order' => 1, 'Currently Unavailable' => 2, 'Coming Soon' => 3, 'Checked Out' => 4, 'Library Use Only' => 5, 'Available Online' => 6, 'On Shelf' => 7); if (isset($curRecord['groupedStatus']) && $curRecord['groupedStatus'] != '') { $groupedStatus = $relatedManifestations[$curRecord['format']]['groupedStatus']; if ($groupedStatus == '') { $groupedStatus = $curRecord['groupedStatus']; //Check to see if we are getting a better status } elseif ($statusRankings[$curRecord['groupedStatus']] > $statusRankings[$groupedStatus]) { $groupedStatus = $curRecord['groupedStatus']; } $relatedManifestations[$curRecord['format']]['groupedStatus'] = $groupedStatus; } } $timer->logTime("Finished initial processing of related records"); //Check to see if we have applied a format or format category facet $selectedFormat = null; $selectedFormatCategory = null; $selectedAvailability = null; if (isset($_REQUEST['filter'])) { foreach ($_REQUEST['filter'] as $filter) { if (preg_match('/^format_category(?:\\w*):"?(.+?)"?$/', $filter, $matches)) { $selectedFormatCategory = urldecode($matches[1]); } elseif (preg_match('/^format(?:\\w*):"?(.+?)"?$/', $filter, $matches)) { $selectedFormat = urldecode($matches[1]); } elseif (preg_match('/^availability_toggle(?:\\w*):"?(.+?)"?$/', $filter, $matches)) { $selectedAvailability = urldecode($matches[1]); } } } //Check to see what we need to do for actions, and determine if the record should be hidden by default foreach ($relatedManifestations as $key => $manifestation) { $manifestation['numRelatedRecords'] = count($manifestation['relatedRecords']); if (count($manifestation['relatedRecords']) == 1) { $firstRecord = reset($manifestation['relatedRecords']); $manifestation['url'] = $firstRecord['url']; $manifestation['actions'] = $firstRecord['actions']; } else { //Figure out what the preferred record is to place a hold on. Since sorting has been done properly, this should always be the first $bestRecord = reset($manifestation['relatedRecords']); $manifestation['actions'] = $bestRecord['actions']; } if ($selectedFormat && $selectedFormat != $manifestation['format']) { //Do a secondary check to see if we have a more detailed format in the facet $detailedFormat = mapValue('format_by_detailed_format', $selectedFormat); if ($manifestation['format'] != $detailedFormat) { $manifestation['hideByDefault'] = true; } } if ($selectedFormatCategory && $selectedFormatCategory != $manifestation['formatCategory']) { $manifestation['hideByDefault'] = true; } if ($selectedAvailability == 'Available Now' && !($manifestation['availableLocally'] || $manifestation['availableOnline'])) { $manifestation['hideByDefault'] = true; } elseif ($selectedAvailability == 'Entire Collection' && !$manifestation['hasLocalItem']) { $manifestation['hideByDefault'] = true; } $relatedManifestations[$key] = $manifestation; } $timer->logTime("Finished loading related manifestations"); return $relatedManifestations; }
function getRelatedRecords() { if ($this->relatedRecords == null) { global $timer; $recordId = $this->getUniqueID(); $url = $this->getRecordUrl(); //Load data needed for the related record if ($this->detailedRecordInfoFromIndex) { //This is fast because it is already loaded within the index $format = $this->detailedRecordInfoFromIndex[1]; $edition = $this->detailedRecordInfoFromIndex[2]; $language = $this->detailedRecordInfoFromIndex[3]; $publisher = $this->detailedRecordInfoFromIndex[4]; $publicationDate = $this->detailedRecordInfoFromIndex[5]; $physicalDescription = $this->detailedRecordInfoFromIndex[6]; $timer->logTime("Finished loading information from indexed info for {$recordId}"); } else { //This is slow because we need to load from marc record $publishers = $this->getPublishers(); $publisher = count($publishers) >= 1 ? $publishers[0] : ''; $publicationDates = $this->getPublicationDates(); $publicationDate = count($publicationDates) >= 1 ? $publicationDates[0] : ''; $physicalDescriptions = $this->getPhysicalDescriptions(); $physicalDescription = count($physicalDescriptions) >= 1 ? $physicalDescriptions[0] : ''; $format = reset($this->getFormat()); $edition = $this->getEdition(true); $language = $this->getLanguage(); $timer->logTime("Finished loading MARC information in getRelatedRecords {$recordId}"); } $formatCategory = mapValue('format_category_by_format', $format); //TODO: Load items? //Setup our record $relatedRecord = array('id' => $recordId, 'url' => $url, 'format' => $format, 'formatCategory' => $formatCategory, 'edition' => $edition, 'language' => $language, 'publisher' => $publisher, 'publicationDate' => $publicationDate, 'physical' => $physicalDescription, 'callNumber' => '', 'available' => true, 'availableOnline' => true, 'availableLocally' => false, 'availableHere' => false, 'inLibraryUseOnly' => false, 'availableCopies' => 'Unlimited', 'copies' => 'Unlimited', 'onOrderCopies' => 0, 'localAvailableCopies' => 'Unlimited', 'localCopies' => 'Unlimited', 'numHolds' => 0, 'hasLocalItem' => true, 'holdRatio' => 999999, 'locationLabel' => 'Hoopla Digital', 'shelfLocation' => 'Hoopla Digital', 'groupedStatus' => 'Available Online', 'source' => 'Hoopla', 'actions' => $this->getActions()); $this->relatedRecords[] = $relatedRecord; } return $this->relatedRecords; }