public function getMyHolds($patron = null, $page = 1, $recordsPerPage = -1, $sortOption = 'title') { global $configArray; if ($patron) { if (is_object($patron)) { $patron = get_object_vars($patron); } $userId = $patron['id']; $userName = $patron['cat_username']; $userPassword = $patron['cat_password']; } else { global $user; $userId = $user->id; $userName = $user->cat_username; $userPassword = $user->cat_password; } $availableHolds = array(); $unavailableHolds = array(); $holds = array('available' => $availableHolds, 'unavailable' => $unavailableHolds); //Get the session token for the user if (isset(HorizonAPI::$sessionIdsForUsers[$userId])) { $sessionToken = HorizonAPI::$sessionIdsForUsers[$userId]; } else { //Log the user in list($userValid, $sessionToken) = $this->loginViaWebService($userName, $userPassword); if (!$userValid) { // echo("No session id found for user"); //should log this instead return $holds; } } //Now that we have the session token, get holds information $lookupMyAccountInfoResponse = $this->getWebServiceResponse($configArray['Catalog']['webServiceUrl'] . '/standard/lookupMyAccountInfo?clientID=' . $configArray['Catalog']['clientId'] . '&sessionToken=' . $sessionToken . '&includeHoldInfo=true'); if (isset($lookupMyAccountInfoResponse->HoldInfo)) { require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php'; foreach ($lookupMyAccountInfoResponse->HoldInfo as $hold) { $curHold = array(); $bibId = (string) $hold->titleKey; $curHold['id'] = $bibId; $curHold['holdSource'] = 'ILS'; $curHold['itemId'] = (string) $hold->itemKey; $curHold['cancelId'] = (string) $hold->holdKey; $curHold['position'] = (string) $hold->queuePosition; $curHold['recordId'] = $bibId; $curHold['shortId'] = $bibId; $curHold['title'] = (string) $hold->title; $curHold['author'] = (string) $hold->author; $curHold['location'] = (string) $hold->pickupLocDescription; //$curHold['locationId'] = $matches[1]; $curHold['locationUpdateable'] = true; $curHold['currentPickupName'] = $curHold['location']; $curHold['status'] = ucfirst(strtolower((string) $hold->status)); $expireDate = (string) $hold->expireDate; $curHold['expire'] = $expireDate; $curHold['expireTime'] = strtotime($expireDate); $reactivateDate = (string) $hold->reactivateDate; $curHold['reactivate'] = $reactivateDate; $curHold['reactivateTime'] = strtotime($reactivateDate); $curHold['cancelable'] = strcasecmp($curHold['status'], 'Suspended') != 0; $curHold['frozen'] = strcasecmp($curHold['status'], 'Suspended') == 0; if ($curHold['frozen']) { $curHold['reactivateTime'] = (int) $hold->reactivateDate; } $curHold['freezeable'] = true; $curHold['sortTitle'] = (string) $hold->title; $recordDriver = new MarcRecord($bibId); if ($recordDriver->isValid()) { $curHold['sortTitle'] = $recordDriver->getSortableTitle(); $curHold['format'] = $recordDriver->getFormat(); $curHold['isbn'] = $recordDriver->getCleanISBN(); $curHold['upc'] = $recordDriver->getCleanUPC(); $curHold['format_category'] = $recordDriver->getFormatCategory(); //Load rating information $curHold['ratingData'] = $recordDriver->getRatingData(); } if (!isset($curHold['status']) || strcasecmp($curHold['status'], "filled") != 0) { $holds['unavailable'][] = $curHold; } else { $holds['available'][] = $curHold; } } } return array('holds' => $holds, 'numUnavailableHolds' => count($holds['unavailable'])); }
public function getReadingHistory($patron, $page = 1, $recordsPerPage = -1, $sortOption = "checkedOut") { global $timer; $patronDump = $this->driver->_getPatronDump($this->driver->_getBarcode()); //Load the information from millennium using CURL $pageContents = $this->driver->_fetchPatronInfoPage($patronDump, 'readinghistory'); //Check to see if there are multiple pages of reading history $hasPagination = preg_match('/<td[^>]*class="browsePager"/', $pageContents); if ($hasPagination) { //Load a list of extra pages to load. The pagination links display multiple times, so load into an associative array to make them unique preg_match_all('/<a href="readinghistory&page=(\\d+)">/', $pageContents, $additionalPageMatches); $maxPageNum = 0; foreach ($additionalPageMatches[1] as $additionalPageMatch) { if ($additionalPageMatch > $maxPageNum) { $maxPageNum = $additionalPageMatch; } } } $recordsRead = 0; $readingHistoryTitles = $this->parseReadingHistoryPage($pageContents, $patron, $sortOption, $recordsRead); $recordsRead += count($readingHistoryTitles); if (isset($maxPageNum)) { for ($pageNum = 2; $pageNum <= $maxPageNum; $pageNum++) { $pageContents = $this->driver->_fetchPatronInfoPage($patronDump, 'readinghistory&page=' . $pageNum); $additionalTitles = $this->parseReadingHistoryPage($pageContents, $patron, $sortOption, $recordsRead); $recordsRead += count($additionalTitles); $readingHistoryTitles = array_merge($readingHistoryTitles, $additionalTitles); } } if ($sortOption == "checkedOut" || $sortOption == "returned") { krsort($readingHistoryTitles); } else { ksort($readingHistoryTitles); } $numTitles = count($readingHistoryTitles); //process pagination if ($recordsPerPage != -1) { $startRecord = ($page - 1) * $recordsPerPage; $readingHistoryTitles = array_slice($readingHistoryTitles, $startRecord, $recordsPerPage); } set_time_limit(20 * count($readingHistoryTitles)); foreach ($readingHistoryTitles as $key => $historyEntry) { //Get additional information from resources table $historyEntry['ratingData'] = null; $historyEntry['permanentId'] = null; $historyEntry['linkUrl'] = null; $historyEntry['coverUrl'] = null; $historyEntry['format'] = array(); if (isset($historyEntry['shortId']) && strlen($historyEntry['shortId']) > 0) { $historyEntry['recordId'] = "." . $historyEntry['shortId'] . $this->driver->getCheckDigit($historyEntry['shortId']); require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php'; $recordDriver = new MarcRecord($historyEntry['recordId']); if ($recordDriver->isValid()) { $historyEntry['ratingData'] = $recordDriver->getRatingData(); $historyEntry['permanentId'] = $recordDriver->getPermanentId(); $historyEntry['linkUrl'] = $recordDriver->getLinkUrl(); $historyEntry['coverUrl'] = $recordDriver->getBookcoverUrl('medium'); $historyEntry['format'] = $recordDriver->getFormats(); } $recordDriver = null; } $readingHistoryTitles[$key] = $historyEntry; } //The history is active if there is an opt out link. $historyActive = strpos($pageContents, 'OptOut') > 0; $timer->logTime("Loaded Reading history for patron"); global $user; if ($historyActive && !$user->trackReadingHistory) { //The user does have reading history even though we hadn't detected it before. $user->trackReadingHistory = true; $user->update(); $_SESSION['userinfo'] = serialize($user); } if (!$historyActive && $user->trackReadingHistory) { //The user does have reading history even though we hadn't detected it before. $user->trackReadingHistory = false; $user->update(); $_SESSION['userinfo'] = serialize($user); } return array('historyActive' => $historyActive, 'titles' => $readingHistoryTitles, 'numTitles' => $numTitles); }
/** * Get Patron Holds * * This is responsible for retrieving all holds by a specific patron. * * @param array|User $patron The patron array from patronLogin * @param integer $page The current page of holds * @param integer $recordsPerPage The number of records to show per page * @param string $sortOption How the records should be sorted * @param string $summaryPage If the summary page has already been loaded, it can be passed in for performance reasons. * * @return mixed Array of the patron's holds on success, PEAR_Error * otherwise. * @access public */ public function getMyHoldsFromDB($patron, $page = 1, $recordsPerPage = -1, $sortOption = 'title') { global $user; $availableHolds = array(); $unavailableHolds = array(); $holds = array('available' => $availableHolds, 'unavailable' => $unavailableHolds); $this->initDatabaseConnection(); $sql = "SELECT *, title, author FROM reserves inner join biblio on biblio.biblionumber = reserves.biblionumber where borrowernumber = ?"; $holdsStmt = mysqli_prepare($this->dbConnection, $sql); $holdsStmt->bind_param('i', $user->username); $holdsStmt->execute(); $results = $holdsStmt->get_result(); while ($curRow = $results->fetch_assoc()) { //Each row in the table represents a hold $curHold = array(); $curHold['holdSource'] = 'ILS'; $bibId = $curRow['biblionumber']; $curHold['id'] = $curRow['biblionumber']; $curHold['shortId'] = $curRow['biblionumber']; $curHold['recordId'] = $curRow['biblionumber']; $curHold['title'] = $curRow['title']; $curHold['create'] = date_parse_from_format('Y-M-d H:m:s', $curRow['reservedate']); $curHold['expire'] = date_parse_from_format('Y-M-d', $curRow['expirationdate']); $curHold['location'] = $curRow['branchcode']; $curHold['locationUpdateable'] = false; $curHold['currentPickupName'] = $curHold['location']; $curHold['position'] = $curRow['priority']; $curHold['frozen'] = false; $curHold['freezeable'] = false; $curHold['cancelable'] = true; if ($curRow['found'] == 'S') { $curHold['frozen'] = true; $curHold['status'] = "Suspended"; $curHold['cancelable'] = false; } elseif ($curRow['found'] == 'W') { $curHold['status'] = "Ready to Pickup"; } elseif ($curRow['found'] == 'T') { $curHold['status'] = "In Transit"; } else { $curHold['status'] = "Pending"; $curHold['freezeable'] = true; } $curHold['freezeable'] = true; $curHold['cancelId'] = $curRow['reservenumber']; if ($bibId) { require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php'; $recordDriver = new MarcRecord($bibId); if ($recordDriver->isValid()) { $curHold['sortTitle'] = $recordDriver->getSortableTitle(); $curHold['format'] = $recordDriver->getFormat(); $curHold['isbn'] = $recordDriver->getCleanISBN(); $curHold['upc'] = $recordDriver->getCleanUPC(); $curHold['format_category'] = $recordDriver->getFormatCategory(); //Load rating information $curHold['ratingData'] = $recordDriver->getRatingData(); } } if (!isset($curHold['status']) || !preg_match('/^Item waiting.*/i', $curHold['status'])) { $holds['unavailable'][] = $curHold; } else { $holds['available'][] = $curHold; } } return array('holds' => $holds, 'numUnavailableHolds' => count($holds['unavailable'])); }
public function getMyHolds($patron = null, $page = 1, $recordsPerPage = -1, $sortOption = 'title') { global $timer; $patronDump = $this->driver->_getPatronDump($this->driver->_getBarcode()); //Load the information from millennium using CURL $sResult = $this->driver->_fetchPatronInfoPage($patronDump, 'holds'); $timer->logTime("Got holds page from Millennium"); $holds = $this->parseHoldsPage($sResult); $timer->logTime("Parsed Holds page"); require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php'; foreach ($holds as $section => $holdSections) { foreach ($holdSections as $key => $hold) { disableErrorHandler(); $recordDriver = new MarcRecord($hold['recordId']); if ($recordDriver->isValid()) { $hold['id'] = $recordDriver->getUniqueID(); $hold['shortId'] = $recordDriver->getShortId(); //Load title, author, and format information about the title $hold['title'] = $recordDriver->getTitle(); $hold['sortTitle'] = $recordDriver->getSortableTitle(); $hold['author'] = $recordDriver->getAuthor(); $hold['format'] = $recordDriver->getFormat(); $hold['isbn'] = $recordDriver->getCleanISBN(); $hold['upc'] = $recordDriver->getCleanUPC(); $hold['format_category'] = $recordDriver->getFormatCategory(); //Load rating information $hold['ratingData'] = $recordDriver->getRatingData(); $holds[$section][$key] = $hold; } enableErrorHandler(); } } //Process sorting //echo ("<br/>\r\nSorting by $sortOption"); foreach ($holds as $sectionName => $section) { $sortKeys = array(); $i = 0; foreach ($section as $key => $hold) { $sortTitle = isset($hold['sortTitle']) ? $hold['sortTitle'] : (isset($hold['title']) ? $hold['title'] : "Unknown"); if ($sectionName == 'available') { $sortKeys[$key] = $sortTitle; } else { if ($sortOption == 'title') { $sortKeys[$key] = $sortTitle; } elseif ($sortOption == 'author') { $sortKeys[$key] = (isset($hold['author']) ? $hold['author'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'placed') { $sortKeys[$key] = $hold['createTime'] . '-' . $sortTitle; } elseif ($sortOption == 'format') { $sortKeys[$key] = (isset($hold['format']) ? $hold['format'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'location') { $sortKeys[$key] = (isset($hold['location']) ? $hold['location'] : "Unknown") . '-' . $sortTitle; } elseif ($sortOption == 'holdQueueLength') { $sortKeys[$key] = (isset($hold['holdQueueLength']) ? $hold['holdQueueLength'] : 0) . '-' . $sortTitle; } elseif ($sortOption == 'position') { $sortKeys[$key] = str_pad(isset($hold['position']) ? $hold['position'] : 1, 3, "0", STR_PAD_LEFT) . '-' . $sortTitle; } elseif ($sortOption == 'status') { $sortKeys[$key] = (isset($hold['status']) ? $hold['status'] : "Unknown") . '-' . (isset($hold['reactivateTime']) ? $hold['reactivateTime'] : "0") . '-' . $sortTitle; } else { $sortKeys[$key] = $sortTitle; } //echo ("<br/>\r\nSort Key for $key = {$sortKeys[$key]}"); } $sortKeys[$key] = strtolower($sortKeys[$key] . '-' . $i++); } array_multisort($sortKeys, $section); $holds[$sectionName] = $section; } //Limit to a specific number of records if (isset($holds['unavailable'])) { $numUnavailableHolds = count($holds['unavailable']); if ($recordsPerPage != -1) { $startRecord = ($page - 1) * $recordsPerPage; $holds['unavailable'] = array_slice($holds['unavailable'], $startRecord, $recordsPerPage); } } else { $numUnavailableHolds = 0; } if (!isset($holds['available'])) { $holds['available'] = array(); } if (!isset($holds['unavailable'])) { $holds['unavailable'] = array(); } //Sort the hold sections so available holds are first. ksort($holds); $patronId = isset($patron) ? $patron['id'] : $this->driver->_getBarcode(); $this->holds[$patronId] = $holds; $timer->logTime("Processed hold pagination and sorting"); return array('holds' => $holds, 'numUnavailableHolds' => $numUnavailableHolds); }
function getBasicItemInfo() { global $timer; global $configArray; $itemData = array(); //Load basic information $this->id = $_GET['id']; $itemData['id'] = $this->id; // Setup Search Engine Connection $class = $configArray['Index']['engine']; $url = $configArray['Index']['url']; $this->db = new $class($url); // Retrieve Full Marc Record if (!($record = $this->db->getRecord($this->id))) { PEAR_Singleton::raiseError(new PEAR_Error('Record Does Not Exist')); } $this->record = $record; $this->recordDriver = RecordDriverFactory::initRecordDriver($record); $timer->logTime('Initialized the Record Driver'); // Process MARC Data if ($record['recordtype'] == 'econtentRecord') { require_once ROOT_DIR . '/sys/eContent/EContentRecord.php'; $eContentRecord = new EContentRecord(); $eContentRecord->id = substr($record['id'], strlen('econtentRecord')); if (!$eContentRecord->find(true)) { $itemData['error'] = 'Cannot load eContent Record for id ' . $record['id']; } else { $itemData['isbn'] = $eContentRecord->getIsbn(); $itemData['issn'] = $eContentRecord->getissn(); $itemData['upc'] = $eContentRecord->getUpc(); $itemData['issn'] = ''; $itemData['title'] = $record['title']; $itemData['author'] = $eContentRecord->author; $itemData['publisher'] = $eContentRecord->publisher; $itemData['allIsbn'] = $eContentRecord->getPropertyArray('isbn'); $itemData['allUpc'] = $eContentRecord->getPropertyArray('upc'); $itemData['allIssn'] = $eContentRecord->getPropertyArray('issn'); $itemData['format'] = $eContentRecord->format(); $itemData['formatCategory'] = $eContentRecord->format_category(); $itemData['language'] = $eContentRecord->language; $itemData['cover'] = $configArray['Site']['coverUrl'] . "/bookcover.php?id={$itemData['id']}&isbn={$itemData['isbn']}&issn={$itemData['issn']}&upc={$itemData['upc']}&category={$itemData['formatCategory']}&format={$itemData['format'][0]}&size=medium"; $itemData['description'] = $eContentRecord->description; require_once ROOT_DIR . '/sys/eContent/EContentRating.php'; $eContentRating = new EContentRating(); $eContentRating->recordId = $eContentRecord->id; global $user; $itemData['ratingData'] = $eContentRating->getRatingData($user, false); } } else { require_once ROOT_DIR . '/sys/MarcLoader.php'; $marcRecord = MarcLoader::loadMarcRecordFromRecord($record); if ($marcRecord) { $this->marcRecord = $marcRecord; } else { $itemData['error'] = 'Cannot Process MARC Record'; } $timer->logTime('Processed the marc record'); // Get ISBN for cover and review use if ($isbnFields = $this->marcRecord->getFields('020')) { //Use the first good ISBN we find. /** @var File_MARC_Data_Field $isbnField */ foreach ($isbnFields as $isbnField) { if ($isbnSubfield = $isbnField->getSubfield('a')) { $this->isbn = trim($isbnSubfield->getData()); if ($pos = strpos($this->isbn, ' ')) { $this->isbn = substr($this->isbn, 0, $pos); } if (strlen($this->isbn) < 10) { $this->isbn = str_pad($this->isbn, 10, "0", STR_PAD_LEFT); } $itemData['isbn'] = $this->isbn; break; } } } /** @var File_MARC_Data_Field $upcField */ if ($upcField = $this->marcRecord->getField('024')) { if ($upcSubField = $upcField->getSubfield('a')) { $this->upc = trim($upcSubField->getData()); $itemData['upc'] = $this->upc; } } /** @var File_MARC_Data_Field $issnField */ if ($issnField = $this->marcRecord->getField('022')) { if ($issnSubfield = $issnField->getSubfield('a')) { $this->issn = trim($issnSubfield->getData()); if ($pos = strpos($this->issn, ' ')) { $this->issn = substr($this->issn, 0, $pos); } $itemData['issn'] = $this->issn; } } $timer->logTime('Got UPC, ISBN, and ISSN'); //Generate basic information from the marc file to make display easier. $itemData['title'] = $record['title']; $itemData['author'] = isset($record['author']) ? $record['author'] : (isset($record['author2']) ? $record['author2'][0] : ''); $itemData['publisher'] = $record['publisher']; $itemData['allIsbn'] = $record['isbn']; $itemData['allUpc'] = $record['upc']; $itemData['allIssn'] = $record['issn']; $itemData['issn'] = $record['issn']; $itemData['format'] = isset($record['format']) ? $record['format'][0] : ''; $itemData['formatCategory'] = $record['format_category'][0]; $itemData['language'] = $record['language']; $itemData['cover'] = $configArray['Site']['path'] . "/bookcover.php?id={$itemData['id']}&issn={$itemData['issn']}&isbn={$itemData['isbn']}&upc={$itemData['upc']}&category={$itemData['formatCategory']}&format={$itemData['format'][0]}"; //Retrieve description from MARC file $description = ''; /** @var File_MARC_Data_Field $descriptionField */ if ($descriptionField = $this->marcRecord->getField('520')) { if ($descriptionSubfield = $descriptionField->getSubfield('a')) { $description = trim($descriptionSubfield->getData()); } } $itemData['description'] = $description; //setup 5 star ratings $itemData['ratingData'] = $this->recordDriver->getRatingData(); $timer->logTime('Got 5 star data'); } return $itemData; }