Пример #1
0
 static function loadDescriptionFromMarc($marcRecord, $allowExternalDescription = true)
 {
     global $interface;
     global $configArray;
     global $library;
     global $timer;
     global $memCache;
     // Get ISBN for cover and review use
     $isbn = null;
     if ($isbnFields = $marcRecord->getFields('020')) {
         //Use the first good ISBN we find.
         foreach ($isbnFields as $isbnField) {
             if ($isbnSubfieldA = $isbnField->getSubfield('a')) {
                 $tmpIsbn = trim($isbnSubfieldA->getData());
                 if (strlen($tmpIsbn) > 0) {
                     $pos = strpos($tmpIsbn, ' ');
                     if ($pos > 0) {
                         $tmpIsbn = substr($tmpIsbn, 0, $pos);
                     }
                     $tmpIsbn = trim($tmpIsbn);
                     if (strlen($tmpIsbn) > 0) {
                         if (strlen($tmpIsbn) < 10) {
                             $tmpIsbn = str_pad($tmpIsbn, 10, "0", STR_PAD_LEFT);
                         }
                         $isbn = $tmpIsbn;
                         break;
                     }
                 }
             }
         }
     }
     $upc = null;
     if ($upcField = $marcRecord->getField('024')) {
         if ($upcField = $upcField->getSubfield('a')) {
             $upc = trim($upcField->getData());
         }
     }
     $descriptionArray = $memCache->get("record_description_{$isbn}_{$upc}_{$allowExternalDescription}");
     if (!$descriptionArray) {
         $marcDescription = null;
         $description = '';
         if ($descriptionField = $marcRecord->getField('520')) {
             if ($descriptionSubfield = $descriptionField->getSubfield('a')) {
                 $description = trim($descriptionSubfield->getData());
                 $marcDescription = Record_Description::trimDescription($description);
             }
         }
         //Load the description
         //Check to see if there is a description in Syndetics and use that instead if available
         $useMarcSummary = true;
         if ($allowExternalDescription) {
             if (!is_null($isbn) || !is_null($upc)) {
                 require_once ROOT_DIR . '/Drivers/marmot_inc/GoDeeperData.php';
                 $summaryInfo = GoDeeperData::getSummary($isbn, $upc);
                 if (isset($summaryInfo['summary'])) {
                     $descriptionArray['description'] = Record_Description::trimDescription($summaryInfo['summary']);
                     $useMarcSummary = false;
                 }
             }
         }
         if ($useMarcSummary) {
             if ($marcDescription != null) {
                 $descriptionArray['description'] = $marcDescription;
                 $description = $marcDescription;
             } else {
                 $description = "Description Not Provided";
                 $descriptionArray['description'] = $description;
             }
         }
         $interface->assign('description', $description);
         //Load page count
         if ($length = $marcRecord->getField('300')) {
             if ($length = $length->getSubfield('a')) {
                 $length = trim($length->getData());
                 $length = preg_replace("/[\\/|;:]/", "", $length);
                 $length = preg_replace("/p\\./", "pages", $length);
                 $descriptionArray['length'] = $length;
             }
         }
         //Load publisher
         if ($publisher = $marcRecord->getField('260')) {
             if ($publisher = $publisher->getSubfield('b')) {
                 $publisher = trim($publisher->getData());
                 $descriptionArray['publisher'] = $publisher;
             }
         }
         $memCache->set("record_description_{$isbn}_{$upc}_{$allowExternalDescription}", $descriptionArray, 0, $configArray['Caching']['record_description']);
     }
     return $descriptionArray;
 }