/** * 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; }