public function __construct($indexFields)
 {
     if (is_string($indexFields)) {
         $id = $indexFields;
         //Just got a record id, let's load the full record from Solr
         // Setup Search Engine Connection
         $searchObject = SearchObjectFactory::initSearchObject();
         $searchObject->disableScoping();
         if (function_exists('disableErrorHandler')) {
             disableErrorHandler();
         }
         // Retrieve the record from Solr
         if (!($record = $searchObject->getRecord($id))) {
             $this->isValid = false;
         } else {
             $this->fields = $record;
         }
         $searchObject->enableScoping();
         if (function_exists('enableErrorHandler')) {
             enableErrorHandler();
         }
     } else {
         $this->fields = $indexFields;
     }
 }
Example #2
0
 function __construct($ipAddress, $startTime)
 {
     global $configArray;
     if (!isset($configArray)) {
         die("You must load configuration before creating a tracker");
     }
     global $interface;
     if (!isset($interface)) {
         die("You must setup the interface before creating a tracker");
     }
     //Make sure that we don't track visits from bots
     if (BotChecker::isRequestFromBot() == true) {
         //$logger->log("Disabling logging because the request is from a bot", PEAR_LOG_DEBUG);
         $this->trackingDisabled = true;
         $this->finished = true;
         return;
     }
     //Check to see if analytics is enabled
     if (isset($configArray['System']['enableAnalytics']) && $configArray['System']['enableAnalytics'] == false) {
         $this->trackingDisabled = true;
         return;
     }
     //Check to see if we are in maintenance mode
     if (isset($configArray['System']['available']) && $configArray['System']['available'] == false) {
         $this->trackingDisabled = true;
         return;
     }
     $session = new Analytics_Session();
     //disable error handler since the tables may not be installed yet.
     disableErrorHandler();
     $sessionId = session_id();
     $session->session_id = $sessionId;
     if ($session->find(true)) {
         $this->session = $session;
         if ($this->session->ip != $ipAddress) {
             $this->session->ip = $ipAddress;
             $this->doGeoIP();
         }
     } else {
         $this->session = $session;
         $this->session->sessionStartTime = $startTime;
         $this->session->lastRequestTime = $startTime;
         $this->session->ip = $ipAddress;
         $this->doGeoIP();
         $this->session->insert();
     }
     $this->pageView = new Analytics_PageView();
     $this->pageView->sessionId = $this->session->id;
     $this->pageView->pageStartTime = $startTime;
     $this->pageView->fullUrl = $_SERVER['REQUEST_URI'];
     enableErrorHandler();
 }
Example #3
0
 /**
  * Load titles that have been rated by other users which are similar to this.
  *
  * @param SearchObject_Solr|SearchObject_Base $db
  * @param UserRating $ratedTitle
  * @param integer $userId
  * @param array $ratedTitles
  * @param array $suggestions
  * @param integer[] $notInterestedTitles
  * @return int The number of suggestions for this title
  */
 static function getSimilarlyRatedTitles($db, $ratedTitle, $userId, $ratedTitles, &$suggestions, $notInterestedTitles)
 {
     $numRecommendations = 0;
     //If there is no ISBN, can we come up with an alternative algorithm?
     //Possibly using common ratings with other patrons?
     //Get a list of other patrons that have rated this title and that like it as much or more than the active user..
     $otherRaters = new UserRating();
     //Query the database to get items that other users who rated this liked.
     $sqlStatement = "SELECT resourceid, record_id, " . " sum(case rating when 5 then 10 when 4 then 6 end) as rating " . " FROM `user_rating` inner join resource on resource.id = user_rating.resourceid WHERE userId in " . " (select userId from user_rating where resourceId = " . $ratedTitle->resourceid . " and rating >= 4 " . " and userid != " . $userId . ") " . " and rating >= 4 " . " and resourceId != " . $ratedTitle->resourceid . " and deleted = 0 " . " group by resourceid order by rating desc limit 10";
     //Sort so the highest titles are on top and limit to 10 suggestions.
     $otherRaters->query($sqlStatement);
     if ($otherRaters->N > 0) {
         //Other users have also rated this title.
         while ($otherRaters->fetch()) {
             //Process the title
             disableErrorHandler();
             if (!($ownedRecord = $db->getRecord($otherRaters->record_id))) {
                 //Old record which has been removed? Ignore for purposes of suggestions.
                 continue;
             }
             enableErrorHandler();
             //get the title from the Solr Index
             if (isset($ownedRecord['isbn'])) {
                 if (strpos($ownedRecord['isbn'][0], ' ') > 0) {
                     $isbnInfo = explode(' ', $ownedRecord['isbn'][0]);
                     $isbn = $isbnInfo[0];
                 } else {
                     $isbn = $ownedRecord['isbn'][0];
                 }
                 $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn);
                 $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn);
             } else {
                 $isbn13 = '';
                 $isbn10 = '';
             }
             //See if we can get the series title from the record
             if (isset($ownedRecord['series'])) {
                 $series = $ownedRecord['series'][0];
             } else {
                 $series = '';
             }
             $similarTitle = array('title' => $ownedRecord['title'], 'title_short' => $ownedRecord['title_short'], 'author' => isset($ownedRecord['author']) ? $ownedRecord['author'] : '', 'publicationDate' => $ownedRecord['publishDate'], 'isbn' => $isbn13, 'isbn10' => $isbn10, 'upc' => isset($ownedRecord['upc']) ? $ownedRecord['upc'][0] : '', 'recordId' => $ownedRecord['id'], 'id' => $ownedRecord['id'], 'libraryOwned' => true, 'isCurrent' => false, 'shortId' => substr($ownedRecord['id'], 1), 'format_category' => isset($ownedRecord['format_category']) ? $ownedRecord['format_category'] : '', 'format' => $ownedRecord['format'], 'recordtype' => $ownedRecord['recordtype'], 'series' => $series, 'grouping_term' => $ownedRecord['grouping_term']);
             $numRecommendations++;
             Suggestions::addTitleToSuggestions($ratedTitle, $similarTitle['title'], $similarTitle['recordId'], $similarTitle, $ratedTitles, $suggestions, $notInterestedTitles);
         }
     }
     return $numRecommendations;
 }
Example #4
0
 /**
  * @param $id
  * @return ExternalEContentDriver|MarcRecord|null|OverDriveRecordDriver|PublicEContentDriver|RestrictedEContentDriver
  */
 static function initRecordDriverById($id)
 {
     if (isset(RecordDriverFactory::$recordDrivers[$id])) {
         return RecordDriverFactory::$recordDrivers[$id];
     }
     $recordInfo = explode(':', $id);
     $recordType = $recordInfo[0];
     $recordId = $recordInfo[1];
     disableErrorHandler();
     if ($recordType == 'overdrive') {
         require_once ROOT_DIR . '/RecordDrivers/OverDriveRecordDriver.php';
         $recordDriver = new OverDriveRecordDriver($recordId);
     } elseif ($recordType == 'public_domain_econtent') {
         require_once ROOT_DIR . '/RecordDrivers/PublicEContentDriver.php';
         $recordDriver = new PublicEContentDriver($recordId);
     } elseif ($recordType == 'external_econtent') {
         require_once ROOT_DIR . '/RecordDrivers/ExternalEContentDriver.php';
         $recordDriver = new ExternalEContentDriver($recordId);
     } elseif ($recordType == 'restricted_econtent') {
         require_once ROOT_DIR . '/RecordDrivers/RestrictedEContentDriver.php';
         $recordDriver = new RestrictedEContentDriver($recordId);
     } elseif ($recordType == 'hoopla') {
         require_once ROOT_DIR . '/RecordDrivers/HooplaDriver.php';
         $recordDriver = new HooplaRecordDriver($recordId);
         if (!$recordDriver->isValid()) {
             global $logger;
             $logger->log("Unable to load record driver for hoopla record {$recordId}", PEAR_LOG_WARNING);
             $recordDriver = null;
         }
     } elseif ($recordType == 'ils') {
         require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
         $recordDriver = new MarcRecord($recordId);
         if (!$recordDriver->isValid()) {
             global $logger;
             $logger->log("Unable to load record driver for {$recordId}", PEAR_LOG_WARNING);
             $recordDriver = null;
         }
     } else {
         global $logger;
         $logger->log("Unknown record type " . $recordType, PEAR_LOG_ERR);
         $recordDriver = null;
     }
     enableErrorHandler();
     RecordDriverFactory::$recordDrivers[$id] = $recordDriver;
     return $recordDriver;
 }
Example #5
0
 function loadEnrichment($isbn, $loadSeries = true, $loadSimilarTitles = true, $loadSimilarAuthors = true)
 {
     global $timer;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     if (isset($configArray['Novelist']) && isset($configArray['Novelist']['profile']) && strlen($configArray['Novelist']['profile']) > 0) {
         $profile = $configArray['Novelist']['profile'];
         $pwd = $configArray['Novelist']['pwd'];
     } else {
         return null;
     }
     if (!isset($isbn) || strlen($isbn) == 0) {
         return null;
     }
     $enrichment = $memCache->get("novelist_enrichment_{$isbn}");
     if ($enrichment == false || isset($_REQUEST['reload'])) {
         $requestUrl = "http://eit.ebscohost.com/Services/NovelistSelect.asmx/AllContent?prof={$profile}&pwd={$pwd}&authType=&ipprof=&isbn={$isbn}";
         try {
             //Get the XML from the service
             disableErrorHandler();
             $req = new Proxy_Request($requestUrl);
             //$result = file_get_contents($req);
             if (PEAR_Singleton::isError($req->sendRequest())) {
                 enableErrorHandler();
                 return null;
             }
             enableErrorHandler();
             $response = $req->getResponseBody();
             $timer->logTime("Made call to Novelist for enrichment information");
             //Parse the XML
             $data = new SimpleXMLElement($response);
             //Convert the data into a structure suitable for display
             if (isset($data->Features->FeatureGroup)) {
                 /** @var SimpleXMLElement $featureGroup */
                 foreach ($data->Features->FeatureGroup as $featureGroup) {
                     $groupType = (string) $featureGroup->attributes()->type;
                     foreach ($featureGroup->Feature as $feature) {
                         $featureType = (string) $feature->attributes()->type;
                         if ($featureType == 'SeriesTitles' && $loadSeries) {
                             $this->loadSeriesInfo($isbn, $feature, $enrichment);
                             $timer->logTime("Loaded enrichment series info");
                         } else {
                             if ($featureType == 'SimilarTitles' && $loadSimilarTitles) {
                                 $this->loadSimilarTitleInfo($isbn, $feature, $enrichment);
                                 $timer->logTime("Loaded similar title info");
                             } else {
                                 if ($featureType == 'SimilarAuthors' && $loadSimilarAuthors) {
                                     $this->loadSimilarAuthorInfo($isbn, $feature, $enrichment);
                                     $timer->logTime("Loaded similar title info");
                                 }
                             }
                         }
                         //TODO: Load Related Content (Awards and Recommended Reading Lists)
                         //      For now, don't worry about this since the data is not worth using
                     }
                 }
             } else {
                 $enrichment = null;
             }
         } catch (Exception $e) {
             global $logger;
             $logger->log("Error fetching data from NoveList {$e}", PEAR_LOG_ERR);
             if (isset($response)) {
                 $logger->log($response, PEAR_LOG_DEBUG);
             }
             $enrichment = null;
         }
         $memCache->set("novelist_enrichment_{$isbn}", $enrichment, 0, $configArray['Caching']['novelist_enrichement']);
     }
     return $enrichment;
 }
 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);
 }
Example #7
0
 function getIPLocation()
 {
     if ($this->ipLocation != 'unset') {
         return $this->ipLocation;
     }
     global $timer;
     /** @var Memcache $memCache */
     global $memCache;
     global $configArray;
     global $logger;
     //Check the current IP address to see if we are in a branch
     $activeIp = $this->getActiveIp();
     //$logger->log("Active IP is $activeIp", PEAR_LOG_DEBUG);
     $this->ipLocation = $memCache->get('location_for_ip_' . $activeIp);
     $this->ipId = $memCache->get('ipId_for_ip_' . $activeIp);
     if ($this->ipId == -1) {
         $this->ipLocation = false;
     }
     if ($this->ipLocation == false || $this->ipId == false) {
         $timer->logTime('Starting getIPLocation');
         //echo("Active IP is $activeIp");
         require_once ROOT_DIR . '/Drivers/marmot_inc/subnet.php';
         $subnet = new subnet();
         $ipVal = ip2long($activeIp);
         $this->ipLocation = null;
         $this->ipId = -1;
         if (is_numeric($ipVal)) {
             disableErrorHandler();
             $subnet->whereAdd('startIpVal <= ' . $ipVal);
             $subnet->whereAdd('endIpVal >= ' . $ipVal);
             if ($subnet->find(true)) {
                 //$logger->log("Found {$subnet->N} matching IP addresses {$subnet->location}", PEAR_LOG_DEBUG);
                 $matchedLocation = new Location();
                 $matchedLocation->locationId = $subnet->locationid;
                 if ($matchedLocation->find(true)) {
                     //Only use the physical location regardless of where we are
                     //$logger->log("Active location is {$matchedLocation->displayName}", PEAR_LOG_DEBUG);
                     $this->ipLocation = clone $matchedLocation;
                     $this->ipId = $subnet->id;
                 } else {
                     $logger->log("Did not find location for ip location id {$subnet->locationid}", PEAR_LOG_WARNING);
                 }
             }
             enableErrorHandler();
         }
         $memCache->set('ipId_for_ip_' . $activeIp, $this->ipId, 0, $configArray['Caching']['ipId_for_ip']);
         $memCache->set('location_for_ip_' . $activeIp, $this->ipLocation, 0, $configArray['Caching']['location_for_ip']);
         $timer->logTime('Finished getIPLocation');
     }
     return $this->ipLocation;
 }
Example #8
0
 public function getMillenniumRecordInfo($id)
 {
     global $configArray;
     require_once ROOT_DIR . '/Drivers/marmot_inc/MillenniumCache.php';
     /** @var Memcache $memCache */
     global $memCache;
     $scope = $this->getMillenniumScope();
     //Clear millennium cache once per minute
     $lastCacheClear = $memCache->get('millennium_cache_interval');
     //echo ("lastCacheClear = $lastCacheClear, cache_interval = {$configArray['Caching']['millennium_cache_interval']}");
     if ($lastCacheClear == false || isset($_REQUEST['reload'])) {
         //Get rid of anything in the cache older than 5 minutes
         $millenniumCache = new MillenniumCache();
         //First clean out any records that are more than 5 minutes old
         if (isset($_REQUEST['reload'])) {
             $cacheExpirationTime = time();
         } else {
             $cacheExpirationTime = time() - 5 * 60;
         }
         //$logger->log("Clearing millennium cache before $cacheExpirationTime", PEAR_LOG_INFO);
         //Update memcache before clearing the database so we don't have tons of threads trying to clear the cache
         $memCache->set('millennium_cache_interval', $cacheExpirationTime, 0, $configArray['Caching']['millennium_cache_interval']);
         $millenniumCache->whereAdd("cacheDate < {$cacheExpirationTime}");
         $millenniumCache->delete(true);
     }
     //Now see if the record already exists in our cache.
     $millenniumCache = new MillenniumCache();
     $millenniumCache->recordId = $id;
     $millenniumCache->scope = $scope;
     $millenniumCache->find();
     if ($millenniumCache->N > 0) {
         //Found a cache entry
         $millenniumCache->fetch();
         //We already deleted old cache entries so we don't need to check to see if the entry is stale.
         //Just return the entry
         return $millenniumCache;
     }
     //Load the pages for holdings, order information, and items
     $millenniumCache = new MillenniumCache();
     $millenniumCache->recordId = $id;
     $millenniumCache->scope = $scope;
     global $configArray;
     global $timer;
     if (substr($configArray['Catalog']['url'], -1) == '/') {
         $host = substr($configArray['Catalog']['url'], 0, -1);
     } else {
         $host = $configArray['Catalog']['url'];
     }
     // Strip ID
     $id_ = substr(str_replace('.b', '', $id), 0, -1);
     $req = $host . "/search~S{$scope}/.b" . $id_ . "/.b" . $id_ . "/1,1,1,B/holdings~" . $id_;
     $millenniumCache->holdingsInfo = file_get_contents($req);
     //$logger->log("Loaded holdings from url $req", PEAR_LOG_DEBUG);
     $timer->logTime('got holdings from millennium');
     $req = $host . "/search~S{$scope}/.b" . $id_ . "/.b" . $id_ . "/1,1,1,B/frameset~" . $id_;
     $millenniumCache->framesetInfo = file_get_contents($req);
     $timer->logTime('got frameset info from millennium');
     $millenniumCache->cacheDate = time();
     //Temporarily ignore errors
     disableErrorHandler();
     $millenniumCache->insert();
     enableErrorHandler();
     return $millenniumCache;
 }
Example #9
0
 function loadEnrichment($isbn, $loadSeries = true, $loadSimilarTitles = true, $loadSimilarAuthors = true)
 {
     global $timer;
     global $configArray;
     /** @var Memcache $memCache */
     global $memCache;
     if (isset($configArray['Novelist']) && isset($configArray['Novelist']['profile']) && strlen($configArray['Novelist']['profile']) > 0) {
         $profile = $configArray['Novelist']['profile'];
         $pwd = $configArray['Novelist']['pwd'];
     } else {
         return null;
     }
     if (!isset($isbn) || strlen($isbn) == 0) {
         return null;
     }
     $enrichment = $memCache->get("novelist_enrichment_{$isbn}");
     if ($enrichment == false || isset($_REQUEST['reload'])) {
         $requestUrl = "http://novselect.ebscohost.com/Data/ContentByQuery?profile={$profile}&password={$pwd}&ClientIdentifier={$isbn}&isbn={$isbn}&version=2.1&tmpstmp=" . time();
         //echo($requestUrl);
         try {
             //Get the JSON from the service
             disableErrorHandler();
             $req = new Proxy_Request($requestUrl);
             //$result = file_get_contents($req);
             if (PEAR_Singleton::isError($req->sendRequest())) {
                 enableErrorHandler();
                 return null;
             }
             enableErrorHandler();
             $response = $req->getResponseBody();
             $timer->logTime("Made call to Novelist for enrichment information");
             //Parse the JSON
             $data = json_decode($response);
             //print_r($data);
             //Related ISBNs
             if (isset($data->FeatureContent)) {
                 //Series Information
                 if ($loadSeries && isset($data->FeatureContent->SeriesInfo)) {
                     $this->loadSeriesInfo($isbn, $data->FeatureContent->SeriesInfo, $enrichment);
                 }
                 //Similar Titles
                 if ($loadSimilarTitles && isset($data->FeatureContent->SimilarTitles)) {
                     $this->loadSimilarTitleInfo($isbn, $data->FeatureContent->SimilarTitles, $enrichment);
                 }
                 //Similar Authors
                 if ($loadSimilarAuthors && isset($data->FeatureContent->SimilarAuthors)) {
                     $this->loadSimilarAuthorInfo($data->FeatureContent->SimilarAuthors, $enrichment);
                 }
                 //Similar Series
                 if ($loadSeries && isset($data->FeatureContent->SimilarSeries)) {
                     $this->loadSimilarSeries($data->FeatureContent->SimilarSeries, $enrichment);
                 }
                 //Related Content
                 if (isset($data->FeatureContent->RelatedContent)) {
                     $this->loadRelatedContent($data->FeatureContent->RelatedContent, $enrichment);
                 }
                 //GoodReads Ratings
                 if (isset($data->FeatureContent->GoodReads)) {
                     $this->loadGoodReads($data->FeatureContent->GoodReads, $enrichment);
                 }
                 //print_r($data);
             }
         } catch (Exception $e) {
             global $logger;
             $logger->log("Error fetching data from NoveList {$e}", PEAR_LOG_ERR);
             if (isset($response)) {
                 $logger->log($response, PEAR_LOG_DEBUG);
             }
             $enrichment = null;
         }
         $memCache->set("novelist_enrichment_{$isbn}", $enrichment, 0, $configArray['Caching']['novelist_enrichement']);
     }
     return $enrichment;
 }
Example #10
0
 /**
  * Loads Novelist data from Novelist for a grouped record
  *
  * @param String    $groupedRecordId  The permanent id of the grouped record
  * @param String[]  $isbns            a list of ISBNs for the record
  * @return NovelistData
  */
 function getSeriesTitles($groupedRecordId, $isbns)
 {
     global $timer;
     global $configArray;
     //First make sure that Novelist is enabled
     if (isset($configArray['Novelist']) && isset($configArray['Novelist']['profile']) && strlen($configArray['Novelist']['profile']) > 0) {
         $profile = $configArray['Novelist']['profile'];
         $pwd = $configArray['Novelist']['pwd'];
     } else {
         return null;
     }
     if ($groupedRecordId == null || $groupedRecordId == '') {
         return null;
     }
     //Check to see if we have cached data, first check MemCache.
     /** @var Memcache $memCache */
     global $memCache;
     $novelistData = $memCache->get("novelist_series_{$groupedRecordId}");
     if ($novelistData != false && !isset($_REQUEST['reload'])) {
         return $novelistData;
     }
     //Now check the database
     $novelistData = new NovelistData();
     $novelistData->groupedRecordPermanentId = $groupedRecordId;
     $recordExists = false;
     if ($novelistData->find(true)) {
         $recordExists = true;
     }
     $novelistData->groupedRecordHasISBN = count($isbns) > 0;
     //When loading full data, we aways need to load the data since we can't cache due to terms of sevice
     if ($recordExists && $novelistData->primaryISBN != null && strlen($novelistData->primaryISBN) > 0) {
         //Just check the primary ISBN since we know that was good.
         $isbns = array($novelistData->primaryISBN);
     }
     //Update the last update time to optimize caching
     $novelistData->lastUpdate = time();
     if (count($isbns) == 0) {
         //Whoops, no ISBNs, can't get enrichment for this
         $novelistData->hasNovelistData = false;
     } else {
         $novelistData->hasNovelistData = false;
         //Check each ISBN for enrichment data
         foreach ($isbns as $isbn) {
             $requestUrl = "http://novselect.ebscohost.com/Data/ContentByQuery?profile={$profile}&password={$pwd}&ClientIdentifier={$isbn}&isbn={$isbn}&version=2.1&tmpstmp=" . time();
             //echo($requestUrl);
             try {
                 //Get the JSON from the service
                 disableErrorHandler();
                 $req = new Proxy_Request($requestUrl);
                 //$result = file_get_contents($req);
                 if (PEAR_Singleton::isError($req->sendRequest())) {
                     enableErrorHandler();
                     //No enrichment for this isbn, go to the next one
                     continue;
                 }
                 enableErrorHandler();
                 $response = $req->getResponseBody();
                 $timer->logTime("Made call to Novelist for enrichment information");
                 //Parse the JSON
                 $data = json_decode($response);
                 //print_r($data);
                 //Related ISBNs
                 if (isset($data->FeatureContent) && $data->FeatureCount > 0) {
                     $novelistData->hasNovelistData = true;
                     //We got data!
                     $novelistData->primaryISBN = $data->TitleInfo->primary_isbn;
                     //Series Information
                     if (isset($data->FeatureContent->SeriesInfo) && count($data->FeatureContent->SeriesInfo->series_titles) > 0) {
                         $this->loadSeriesInfo($groupedRecordId, $data->FeatureContent->SeriesInfo, $novelistData);
                         break;
                     }
                 }
             } catch (Exception $e) {
                 global $logger;
                 $logger->log("Error fetching data from NoveList {$e}", PEAR_LOG_ERR);
                 if (isset($response)) {
                     $logger->log($response, PEAR_LOG_DEBUG);
                 }
                 $enrichment = null;
             }
         }
         //Loop on each ISBN
     }
     //Check for number of ISBNs
     $memCache->set("novelist_series_{$groupedRecordId}", $novelistData, 0, $configArray['Caching']['novelist_enrichment']);
     return $novelistData;
 }
Example #11
0
 function getItemAvailability()
 {
     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
     disableErrorHandler();
     $record = $this->db->getRecord($this->id);
     enableErrorHandler();
     if ($record == false) {
         $marcRecord = new MarcRecord($this->id);
         if ($marcRecord->isValid()) {
             $itemData['holdings'] = Record_Holdings::loadHoldings($this->id);
             $timer->logTime('Loaded Holdings');
         } else {
             $itemData['error'] = 'Cannot load Record for id ' . $record['id'];
         }
     } else {
         $this->record = $record;
         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 {
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $driver = new EContentDriver();
                 $itemData['holdings'] = $driver->getHolding($eContentRecord->id);
             }
         } else {
             $this->recordDriver = RecordDriverFactory::initRecordDriver($record);
             $timer->logTime('Initialized the Record Driver');
             //Load Holdings
             $itemData['holdings'] = Record_Holdings::loadHoldings($this->id);
             $timer->logTime('Loaded Holdings');
         }
     }
     return $itemData;
 }