function launch() { global $interface; global $timer; global $logger; global $user; //Build the actual view $interface->setTemplate('view-series.tpl'); $id = $_REQUEST['id']; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $recordDriver = new GroupedWorkDriver($id); if (!$recordDriver->isValid) { $logger->log("Did not find a record for id {$id} in solr.", PEAR_LOG_DEBUG); $interface->setTemplate('invalidRecord.tpl'); $interface->display('layout.tpl'); die; } $timer->logTime('Initialized the Record Driver'); $novelist = NovelistFactory::getNovelist(); $seriesData = $novelist->getSeriesTitles($id, $recordDriver->getISBNs()); //Loading the series title is not reliable. Do not try to load it. $seriesTitle = null; $seriesAuthors = array(); $resourceList = array(); $seriesTitles = $seriesData->seriesTitles; $recordIndex = 1; if (isset($seriesTitles) && is_array($seriesTitles)) { foreach ($seriesTitles as $key => $title) { if (isset($title['series']) && strlen($title['series']) > 0 && !isset($seriesTitle)) { $seriesTitle = $title['series']; $interface->assign('seriesTitle', $seriesTitle); } if (isset($title['author'])) { $author = preg_replace('/[^\\w]*$/i', '', $title['author']); $seriesAuthors[$author] = $author; } $interface->assign('recordIndex', $recordIndex); $interface->assign('resultIndex', $recordIndex++); if ($title['libraryOwned']) { /** @var GroupedWorkDriver $tmpRecordDriver */ $tmpRecordDriver = $title['recordDriver']; $resourceList[] = $interface->fetch($tmpRecordDriver->getSearchResult($user, null, false)); } else { $interface->assign('record', $title); $resourceList[] = $interface->fetch('RecordDrivers/Index/nonowned_result.tpl'); } } } $interface->assign('seriesAuthors', $seriesAuthors); $interface->assign('recordSet', $seriesTitles); $interface->assign('resourceList', $resourceList); $interface->assign('recordStart', 1); $interface->assign('recordEnd', count($seriesTitles)); $interface->assign('recordCount', count($seriesTitles)); $interface->assign('recordDriver', $recordDriver); $interface->assign('sidebar', 'GroupedWork/full-record-sidebar.tpl'); $interface->setPageTitle($seriesTitle); // Display Page $interface->display('layout.tpl'); }
private function getGroupedWorkCover() { if ($this->loadGroupedWork()) { //Have not found a grouped work based on isbn or upc, check based on related records $relatedRecords = $this->groupedWork->getRelatedRecords(false); foreach ($relatedRecords as $relatedRecord) { if ($relatedRecord['source'] == 'OverDrive') { if ($this->getOverDriveCover($relatedRecord['id'])) { return true; } } elseif ($relatedRecord['source'] == 'Hoopla') { if ($this->getHooplaCover($relatedRecord['id'])) { return true; } } else { /** @var GroupedWorkDriver $driver */ $driver = $relatedRecord['driver']; //First check to see if there is a specific record defined in an 856 etc. if (method_exists($driver, 'getMarcRecord') && $this->getCoverFromMarc($driver->getMarcRecord())) { return true; } else { //Finally, check the isbns if we don't have an override $isbns = $driver->getCleanISBNs(); if ($isbns) { foreach ($isbns as $isbn) { $this->isn = $isbn; if ($this->getCoverFromProvider()) { return true; } } } $upcs = $driver->getCleanUPCs(); $this->isn = null; if ($upcs) { foreach ($upcs as $upc) { $this->upc = ltrim($upc, '0'); if ($this->getCoverFromProvider()) { return true; } //If we tried trimming the leading zeroes, also try without. if ($this->upc !== $upc) { $this->upc = $upc; if ($this->getCoverFromProvider()) { return true; } } } } } } } } return false; }
public function launch() { global $interface; global $user; //Load user ratings require_once ROOT_DIR . '/sys/LocalEnrichment/UserWorkReview.php'; require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php'; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $rating = new UserWorkReview(); $rating->userId = $user->id; $rating->find(); $ratings = array(); while ($rating->fetch()) { $groupedWorkDriver = new GroupedWorkDriver($rating->groupedRecordPermanentId); if ($groupedWorkDriver->isValid) { $ratings[] = array('id' => $rating->id, 'groupedWorkId' => $rating->groupedRecordPermanentId, 'title' => $groupedWorkDriver->getTitle(), 'author' => $groupedWorkDriver->getPrimaryAuthor(), 'rating' => $rating->rating, 'review' => $rating->review, 'link' => $groupedWorkDriver->getLinkUrl(), 'dateRated' => $rating->dateRated, 'ratingData' => $groupedWorkDriver->getRatingData()); } } asort($ratings); //Load titles the user is not interested in $notInterested = array(); require_once ROOT_DIR . '/sys/LocalEnrichment/NotInterested.php'; $notInterestedObj = new NotInterested(); $notInterestedObj->userId = $user->id; $notInterestedObj->find(); while ($notInterestedObj->fetch()) { $groupedWorkId = $notInterestedObj->groupedRecordPermanentId; $groupedWorkDriver = new GroupedWorkDriver($groupedWorkId); if ($groupedWorkDriver->isValid) { $notInterested[] = array('id' => $notInterestedObj->id, 'title' => $groupedWorkDriver->getTitle(), 'author' => $groupedWorkDriver->getPrimaryAuthor(), 'dateMarked' => $notInterestedObj->dateMarked, 'link' => $groupedWorkDriver->getLinkUrl()); } } $interface->assign('ratings', $ratings); $interface->assign('notInterested', $notInterested); $interface->assign('showNotInterested', false); $interface->setPageTitle('My Ratings'); $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl'); $interface->setTemplate('myRatings.tpl'); $interface->display('layout.tpl'); }
/** * Turn our results into an RSS feed * * @access public * @public array $result Existing result set (null to do new search) * @return string XML document */ public function buildRSS($result = null) { global $configArray; // XML HTTP header header('Content-type: text/xml', true); // First, get the search results if none were provided // (we'll go for 50 at a time) if (is_null($result)) { $this->limit = 50; $result = $this->processSearch(false, false); } // Now prepare the serializer $serializer_options = array('addDecl' => TRUE, 'encoding' => 'UTF-8', 'indent' => ' ', 'rootName' => 'json', 'mode' => 'simplexml'); $serializer = new XML_Serializer($serializer_options); $baseUrl = $configArray['Site']['url']; for ($i = 0; $i < count($result['response']['docs']); $i++) { //Since the base URL can be different depending on the record type, add the url to the response if (strcasecmp($result['response']['docs'][$i]['recordtype'], 'econtentRecord') == 0) { $id = str_replace('econtentRecord', '', $result['response']['docs'][$i]['id']); $result['response']['docs'][$i]['recordUrl'] = $baseUrl . '/EcontentRecord/' . $id; } else { if (strcasecmp($result['response']['docs'][$i]['recordtype'], 'grouped_work') == 0) { $id = str_replace('econtentRecord', '', $result['response']['docs'][$i]['id']); $result['response']['docs'][$i]['recordUrl'] = $baseUrl . '/GroupedWork/' . $id; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $groupedWorkDriver = new GroupedWorkDriver($id); $image = $groupedWorkDriver->getBookcoverUrl('medium'); $description = "<img src='{$image}'/> " . $groupedWorkDriver->getDescriptionFast(); $result['response']['docs'][$i]['description'] = $description; } else { $id = $result['response']['docs'][$i]['id']; $result['response']['docs'][$i]['recordUrl'] = $baseUrl . '/Record/' . $id; } } } // Serialize our results from PHP arrays to XML if ($serializer->serialize($result)) { $xmlResults = $serializer->getSerializedData(); } // Prepare an XSLT processor and pass it some variables $xsl = new XSLTProcessor(); $xsl->registerPHPFunctions('urlencode'); $xsl->registerPHPFunctions('translate'); // On-screen display value for our search if ($this->searchType == 'newitem') { $lookfor = translate('New Items'); } else { if ($this->searchType == 'reserves') { $lookfor = translate('Course Reserves'); } else { $lookfor = $this->displayQuery(); } } if (count($this->filterList) > 0) { // TODO : better display of filters $xsl->setParameter('', 'lookfor', $lookfor . " (" . translate('with filters') . ")"); } else { $xsl->setParameter('', 'lookfor', $lookfor); } // The full url to recreate this search $xsl->setParameter('', 'searchUrl', $this->renderSearchUrl()); // Stub of a url for a records screen $xsl->setParameter('', 'baseUrl', $configArray['Site']['url'] . "/Record/"); // Load up the style sheet $style = new DOMDocument(); $style->load('services/Search/xsl/json-rss.xsl'); $xsl->importStyleSheet($style); // Load up the XML document $xml = new DOMDocument(); $xml->loadXML($xmlResults); // Process and return the xml through the style sheet try { $xmlResult = $xsl->transformToXML($xml); return $xmlResult; } catch (Exception $e) { global $logger; $logger->log("Error loading RSS feed {$e}", PEAR_LOG_ERR); return ""; } }
function reloadCover() { require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; global $configArray; $id = $_REQUEST['id']; $recordDriver = new GroupedWorkDriver($id); //Reload small cover $smallCoverUrl = $configArray['Site']['coverUrl'] . $recordDriver->getBookcoverUrl('small') . '&reload'; $ret = file_get_contents($smallCoverUrl); //Reload medium cover $mediumCoverUrl = $configArray['Site']['coverUrl'] . $recordDriver->getBookcoverUrl('medium') . '&reload'; $ret = file_get_contents($mediumCoverUrl); //Reload large cover $largeCoverUrl = $configArray['Site']['coverUrl'] . $recordDriver->getBookcoverUrl('large') . '&reload'; $ret = file_get_contents($largeCoverUrl); return json_encode(array('success' => true, 'message' => 'Covers have been reloaded. You may need to refresh the page to clear your local cache.')); }
static function compareEditionsForRecords($literaryForm, $a, $b) { //We only want to compare editions if the work is non-fiction if ($literaryForm == 'Non Fiction') { $editionA = GroupedWorkDriver::normalizeEdition($a['edition']); $editionB = GroupedWorkDriver::normalizeEdition($b['edition']); if ($editionA == $editionB) { return 0; } else { if ($editionA > $editionB) { return -1; } else { return 1; } } } return 0; }
function reloadCover() { require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php'; $id = $_REQUEST['id']; $recordDriver = new MarcRecord($id); //Reload small cover $smallCoverUrl = str_replace('&', '&', $recordDriver->getBookcoverUrl('small')) . '&reload'; file_get_contents($smallCoverUrl); //Reload medium cover $mediumCoverUrl = str_replace('&', '&', $recordDriver->getBookcoverUrl('medium')) . '&reload'; file_get_contents($mediumCoverUrl); //Reload large cover $largeCoverUrl = str_replace('&', '&', $recordDriver->getBookcoverUrl('large')) . '&reload'; file_get_contents($largeCoverUrl); //Also reload covers for the grouped work require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $groupedWorkDriver = new GroupedWorkDriver($recordDriver->getGroupedWorkId()); global $configArray; //Reload small cover $smallCoverUrl = $configArray['Site']['coverUrl'] . str_replace('&', '&', $groupedWorkDriver->getBookcoverUrl('small')) . '&reload'; file_get_contents($smallCoverUrl); //Reload medium cover $mediumCoverUrl = $configArray['Site']['coverUrl'] . str_replace('&', '&', $groupedWorkDriver->getBookcoverUrl('medium')) . '&reload'; file_get_contents($mediumCoverUrl); //Reload large cover $largeCoverUrl = $configArray['Site']['coverUrl'] . str_replace('&', '&', $groupedWorkDriver->getBookcoverUrl('large')) . '&reload'; file_get_contents($largeCoverUrl); return $this->json_utf8_encode(array('success' => true, 'message' => 'Covers have been reloaded. You may need to refresh the page to clear your local cache.')); }
private function loadNoveListTitle($currentId, $item, &$titleList, &$titlesOwned, $seriesName = '') { global $user; global $timer; global $configArray; //Find the correct grouped work based on the isbns; require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php'; require_once ROOT_DIR . '/sys/Grouping/GroupedWorkIdentifier.php'; require_once ROOT_DIR . '/sys/Grouping/GroupedWorkIdentifierRef.php'; $timer->logTime("Start loadNoveListTitle"); /** @var SimpleXMLElement $titleItem */ $permanentId = null; $concatenatedIsbns = "'" . implode("','", $item->isbns) . "'"; $groupedWorkIdentifier = new GroupedWorkIdentifier(); $groupedWorkIdentifier->type = "isbn"; $groupedWorkIdentifier->whereAdd("identifier in ({$concatenatedIsbns})"); if ($groupedWorkIdentifier->find()) { while ($groupedWorkIdentifier->fetch()) { $groupedWorkIdentifierRef = new GroupedWorkIdentifierRef(); $groupedWorkIdentifierRef->identifier_id = $groupedWorkIdentifier->id; $groupedWorkIdentifierRef->find(); if ($groupedWorkIdentifierRef->N == 1) { $groupedWorkIdentifierRef->fetch(); $groupedWork = new GroupedWork(); $groupedWork->id = $groupedWorkIdentifierRef->grouped_work_id; if ($groupedWork->find(true)) { $permanentId = $groupedWork->permanent_id; break; } } } } $timer->logTime("Load Novelist Title - Find Grouped Work based on identifier {$permanentId}"); $isCurrent = $currentId == $permanentId; if (isset($seriesName)) { $series = $seriesName; } else { $series = ''; } $volume = ''; if (isset($item->volume)) { $volume = $item->volume; } //We didn't find a match in the database so we don't own it if ($permanentId == null) { $isbn = reset($item->isbns); $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn); $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn); $curTitle = array('title' => $item->full_title, 'author' => $item->author, 'isbn' => $isbn13, 'isbn10' => $isbn10, 'recordId' => -1, 'libraryOwned' => false, 'isCurrent' => $isCurrent, 'series' => $series, 'volume' => $volume, 'reason' => isset($item->reason) ? $item->reason : '', 'smallCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=small&isn=" . $isbn13, 'mediumCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=medium&isn=" . $isbn13); } else { //Get more information from Solr /** @var GroupedWorkDriver $recordDriver */ $recordDriver = new GroupedWorkDriver($permanentId); $timer->logTime("Find grouped work in solr"); if ($recordDriver->isValid) { if (!isset($series)) { if (isset($ownedRecord['series'])) { $series = $ownedRecord['series'][0]; } } //Load data about the record $ratingData = $recordDriver->getRatingData($user); $timer->logTime("Get Rating data"); $fullRecordLink = $recordDriver->getLinkUrl(); //See if we can get the series title from the record $curTitle = array('title' => $recordDriver->getTitle(), 'title_short' => $recordDriver->getTitle(), 'author' => $recordDriver->getPrimaryAuthor(), 'isbn' => $recordDriver->getCleanISBN(), 'isbn10' => $recordDriver->getCleanISBN(), 'upc' => $recordDriver->getCleanUPC(), 'recordId' => $recordDriver->getPermanentId(), 'recordtype' => 'grouped_work', 'id' => $recordDriver->getPermanentId(), 'libraryOwned' => true, 'isCurrent' => $isCurrent, 'shortId' => $recordDriver->getPermanentId(), 'format_category' => $recordDriver->getFormatCategory(), 'series' => $series, 'volume' => $volume, 'ratingData' => $ratingData, 'fullRecordLink' => $fullRecordLink, 'reason' => isset($item->reason) ? $item->reason : '', 'recordDriver' => $recordDriver, 'smallCover' => $recordDriver->getBookcoverUrl('small'), 'mediumCover' => $recordDriver->getBookcoverUrl('medium')); $timer->logTime("Load title information"); $titlesOwned++; } else { $isbn = reset($item->isbns); $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn); $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn); $curTitle = array('title' => $item->full_title, 'author' => $item->author, 'isbn' => $isbn13, 'isbn10' => $isbn10, 'recordId' => -1, 'libraryOwned' => false, 'isCurrent' => $isCurrent, 'series' => $series, 'volume' => $volume, 'reason' => isset($item->reason) ? $item->reason : '', 'smallCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=small&isn=" . $isbn13, 'mediumCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=medium&isn=" . $isbn13); } } $titleList[] = $curTitle; return $curTitle; }
function getDescriptionByRecordId() { global $configArray; //Load the record id that the user wants to search for $recordId = trim($_REQUEST['recordId']); // Setup Search Engine Connection $class = $configArray['Index']['engine']; $url = $configArray['Index']['url']; /** @var SearchObject_Solr db */ $this->db = new $class($url); //Search the database by title and author if ($recordId) { if (preg_match('/^b\\d{7}[\\dx]$/', $recordId)) { $recordId = '.' . $recordId; } $searchResults = $this->db->search("{$recordId}", 'Id'); } else { $results = array('result' => false, 'message' => 'Please enter the record Id to look for'); return $results; } if ($searchResults['response']['numFound'] == 0) { $results = array('result' => false, 'message' => 'Sorry, we could not find a description for that record id'); } else { $firstRecord = $searchResults['response']['docs'][0]; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $groupedWork = new GroupedWorkDriver($firstRecord); $results = array('result' => true, 'message' => 'Found a summary for record ' . $firstRecord['title_display'] . ' by ' . $firstRecord['author_display'], 'recordsFound' => $searchResults['response']['numFound'], 'description' => $groupedWork->getDescription()); } return $results; }