/**
  * Return the first valid ISBN found in the record (favoring ISBN-10 over
  * ISBN-13 when possible).
  *
  * @return  mixed
  */
 public function getCleanISBN()
 {
     require_once ROOT_DIR . '/sys/ISBN.php';
     //Check to see if we already have NovelistData loaded with a primary ISBN
     require_once ROOT_DIR . '/sys/Novelist/NovelistData.php';
     $novelistData = new NovelistData();
     $novelistData->groupedRecordPermanentId = $this->getPermanentId();
     if (!isset($_REQUEST['reload']) && $this->getPermanentId() != null && $this->getPermanentId() != '' && $novelistData->find(true) && $novelistData->primaryISBN != null) {
         return $novelistData->primaryISBN;
     } else {
         // Get all the ISBNs and initialize the return value:
         $isbns = $this->getISBNs();
         $isbn10 = false;
         // Loop through the ISBNs:
         foreach ($isbns as $isbn) {
             // If we find an ISBN-13, return it immediately; otherwise, if we find
             // an ISBN-10, save it if it is the first one encountered.
             $isbnObj = new ISBN($isbn);
             if ($isbnObj->isValid()) {
                 if ($isbn13 = $isbnObj->get13()) {
                     return $isbn13;
                 }
                 if (!$isbn10) {
                     $isbn10 = $isbnObj->get10();
                 }
             }
         }
         return $isbn10;
     }
 }
Exemple #2
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;
 }