Exemplo n.º 1
0
 /**
  * Try to build an array of OCLC Number, ISBN or ISSN-based sub-queries by
  * using OCLC X-services against a record driver object.
  *
  * @param \VuFind\RecordDriver\AbstractBase $driver Record driver object
  *
  * @return array
  */
 protected function getQueryParts($driver)
 {
     $parts = [];
     $oclcNum = $driver->tryMethod('getCleanOCLCNum');
     if (!empty($oclcNum)) {
         $oclcList = $this->wcUtils->getXOCLCNUM($oclcNum);
         if (!empty($oclcList)) {
             $parts[] = '(srw.no any "' . implode(' ', $oclcList) . '")';
         }
     }
     $isbn = $driver->tryMethod('getCleanISBN');
     if (!empty($isbn)) {
         $isbnList = $this->wcUtils->getXISBN($isbn);
         if (!empty($isbnList)) {
             $parts[] = '(srw.bn any "' . implode(' ', $isbnList) . '")';
         }
     }
     $issn = $driver->tryMethod('getCleanISSN');
     if (!empty($issn)) {
         $issnList = $this->wcUtils->getXISSN($issn);
         if (!empty($issnList)) {
             $parts[] = '(srw.sn any "' . implode(' ', $issnList) . '")';
         }
     }
     return $parts;
 }
Exemplo n.º 2
0
 /**
  * Support method to turn a record driver object into an RSS entry.
  *
  * @param Feed                              $feed   Feed to update
  * @param \VuFind\RecordDriver\AbstractBase $record Record to add to feed
  *
  * @return void
  */
 protected function addEntry($feed, $record)
 {
     $entry = $feed->createEntry();
     $title = $record->tryMethod('getTitle');
     $title = empty($title) ? $record->getBreadcrumb() : $title;
     $entry->setTitle(empty($title) ? $this->translate('Title not available') : $title);
     $serverUrl = $this->getView()->plugin('serverurl');
     $recordLink = $this->getView()->plugin('recordlink');
     try {
         $url = $serverUrl($recordLink->getUrl($record));
     } catch (\Zend\Mvc\Router\Exception\RuntimeException $e) {
         // No route defined? See if we can get a URL out of the driver.
         // Useful for web results, among other things.
         $url = $record->tryMethod('getUrl');
         if (empty($url) || !is_string($url)) {
             throw new \Exception('Cannot find URL for record.');
         }
     }
     $entry->setLink($url);
     $date = $this->getDateModified($record);
     if (!empty($date)) {
         $entry->setDateModified($date);
     }
     $author = $record->tryMethod('getPrimaryAuthor');
     if (!empty($author)) {
         $entry->addAuthor(['name' => $author]);
     }
     $authors = $record->tryMethod('getSecondaryAuthors');
     if (is_array($authors)) {
         foreach ($authors as $author) {
             $entry->addAuthor(['name' => $author]);
         }
     }
     $formats = $record->tryMethod('getFormats');
     if (is_array($formats)) {
         // Take only the most specific format and get rid of level indicator
         // and trailing slash
         $format = end($formats);
         $format = implode('/', array_slice(explode('/', $format), 1, -1));
         $entry->addDCFormat($format);
     }
     $dcDate = $this->getDcDate($record);
     if (!empty($dcDate)) {
         $entry->setDCDate($dcDate);
     }
     $urlHelper = $this->getView()->plugin('url');
     $recordHelper = $this->getView()->plugin('record');
     $recordImage = $this->getView()->plugin('recordImage');
     $imageUrl = $recordImage($recordHelper($record))->getLargeImage();
     $entry->setEnclosure(['uri' => $serverUrl($imageUrl), 'type' => 'image/jpeg', 'length' => 1]);
     $entry->setCommentCount(count($record->getComments()));
     $summaries = $record->tryMethod('getSummary');
     if (!empty($summaries)) {
         $entry->setDescription(implode(' -- ', $summaries));
     }
     $feed->addEntry($entry);
 }
Exemplo n.º 3
0
 /**
  * Generate a thumbnail URL (return false if unsupported).
  *
  * @param RecordDriver $driver Record driver
  * @param string       $size   Size of thumbnail (small, medium or large --
  * small is default).
  *
  * @return string|bool
  */
 public function getUrl(RecordDriver $driver, $size = 'small')
 {
     // Try to build thumbnail:
     $thumb = $driver->tryMethod('getThumbnail', [$size]);
     // No thumbnail?  Return false:
     if (empty($thumb)) {
         return false;
     }
     // Array?  It's parameters to send to the cover generator:
     if (is_array($thumb)) {
         return $this->dynamicUrl . '?' . http_build_query($thumb);
     }
     // Default case -- return fixed string:
     return $thumb;
 }
Exemplo n.º 4
0
 /**
  * Establishes base settings for making recommendations.
  *
  * @param string                            $settings Settings from config.ini
  * @param \VuFind\RecordDriver\AbstractBase $driver   Record driver object
  *
  * @return void
  */
 public function init($settings, $driver)
 {
     // Create array of query parts:
     $parts = [];
     // Add Dewey class to query
     $deweyClass = $driver->tryMethod('getDeweyCallNumber');
     if (!empty($deweyClass)) {
         // Skip "English Fiction" Dewey class -- this won't give us useful
         // matches because there's too much of it and it's too broad.
         if (substr($deweyClass, 0, 3) != '823') {
             $parts[] = 'srw.dd any "' . $deweyClass . '"';
         }
     }
     // Add author to query
     $author = $driver->getPrimaryAuthor();
     if (!empty($author)) {
         $parts[] = 'srw.au all "' . $author . '"';
     }
     // Add subjects to query
     $subjects = $driver->getAllSubjectHeadings();
     foreach ($subjects as $current) {
         $parts[] = 'srw.su all "' . implode(' ', $current) . '"';
     }
     // Add title to query
     $title = $driver->getTitle();
     if (!empty($title)) {
         $parts[] = 'srw.ti any "' . str_replace('"', '', $title) . '"';
     }
     // Build basic query:
     $query = '(' . implode(' or ', $parts) . ')';
     // Not current record ID if this is already a WorldCat record:
     if ($driver->getSourceIdentifier() == 'WorldCat') {
         $id = $driver->getUniqueId();
         $query .= " not srw.no all \"{$id}\"";
     }
     // Perform the search and save results:
     $queryObj = new \VuFindSearch\Query\Query($query);
     $result = $this->searchService->search('WorldCat', $queryObj, 0, 5);
     $this->results = $result->getRecords();
 }
Exemplo n.º 5
0
 /**
  * Construct volume/issue/date portion of APA citation.  Returns an array with
  * three elements: volume, issue and date (since these end up in different areas
  * of the final citation, we don't return a single string, but since their
  * determination is related, we need to do the work in a single function).
  *
  * @return array
  */
 protected function getAPANumbersAndDate()
 {
     $vol = $this->driver->tryMethod('getContainerVolume');
     $num = $this->driver->tryMethod('getContainerIssue');
     $date = $this->details['pubDate'];
     if (strlen($date) > 4) {
         try {
             $year = $this->dateConverter->convertFromDisplayDate('Y', $date);
             $month = $this->dateConverter->convertFromDisplayDate('F', $date);
             $day = $this->dateConverter->convertFromDisplayDate('j', $date);
         } catch (DateException $e) {
             // If conversion fails, use raw date as year -- not ideal,
             // but probably better than nothing:
             $year = $date;
             $month = $day = '';
         }
     } else {
         $year = $date;
         $month = $day = '';
     }
     // We need to supply additional date information if no vol/num:
     if (!empty($vol) || !empty($num)) {
         // If only the number is non-empty, move the value to the volume to
         // simplify template behavior:
         if (empty($vol) && !empty($num)) {
             $vol = $num;
             $num = '';
         }
         return [$vol, $num, $year];
     } else {
         // Right now, we'll assume if day == 1, this is a monthly publication;
         // that's probably going to result in some bad citations, but it's the
         // best we can do without writing extra record driver methods.
         $finalDate = $year . (empty($month) ? '' : ', ' . $month) . ($day > 1 ? ' ' . $day : '');
         return ['', '', $finalDate];
     }
 }
Exemplo n.º 6
0
 /**
  * Get all the links associated with this record.  Returns an array of
  * associative arrays each containing 'desc' and 'url' keys.
  *
  * @return array
  */
 public function getLinkDetails()
 {
     // See if there are any links available:
     $urls = $this->driver->tryMethod('getURLs');
     if (empty($urls)) {
         return [];
     }
     // If we found links, we may need to convert from the "route" format
     // to the "full URL" format.
     $urlHelper = $this->getView()->plugin('url');
     $serverUrlHelper = $this->getView()->plugin('serverurl');
     $formatLink = function ($link) use($urlHelper, $serverUrlHelper) {
         // Error if route AND URL are missing at this point!
         if (!isset($link['route']) && !isset($link['url'])) {
             throw new \Exception('Invalid URL array.');
         }
         // Build URL from route/query details if missing:
         if (!isset($link['url'])) {
             $routeParams = isset($link['routeParams']) ? $link['routeParams'] : [];
             $link['url'] = $serverUrlHelper($urlHelper($link['route'], $routeParams));
             if (isset($link['queryString'])) {
                 $link['url'] .= $link['queryString'];
             }
         }
         // Apply prefix if found
         if (isset($link['prefix'])) {
             $link['url'] = $link['prefix'] . $link['url'];
         }
         // Use URL as description if missing:
         if (!isset($link['desc'])) {
             $link['desc'] = $link['url'];
         }
         return $link;
     };
     return array_map($formatLink, $urls);
 }
Exemplo n.º 7
0
 /**
  * Use a record driver to assign metadata to the current row.  Return the
  * current object to allow fluent interface.
  *
  * @param \VuFind\RecordDriver\AbstractBase $driver    The record driver
  * @param \VuFind\Date\Converter            $converter Date converter
  *
  * @return \VuFind\Db\Row\Resource
  */
 public function assignMetadata($driver, \VuFind\Date\Converter $converter)
 {
     // Grab title -- we have to have something in this field!
     $this->title = $driver->tryMethod('getSortTitle');
     if (empty($this->title)) {
         $this->title = $driver->getBreadcrumb();
     }
     // Try to find an author; if not available, just leave the default null:
     $author = $driver->tryMethod('getPrimaryAuthor');
     if (!empty($author)) {
         $this->author = $author;
     }
     // Try to find a year; if not available, just leave the default null:
     $dates = $driver->tryMethod('getPublicationDates');
     if (isset($dates[0]) && strlen($dates[0]) > 4) {
         try {
             $year = $converter->convertFromDisplayDate('Y', $dates[0]);
         } catch (DateException $e) {
             // If conversion fails, don't store a date:
             $year = '';
         }
     } else {
         $year = isset($dates[0]) ? $dates[0] : '';
     }
     if (!empty($year)) {
         $this->year = intval($year);
     }
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Does the specified record support the specified export format?
  *
  * @param \VuFind\RecordDriver\AbstractBase $driver Record driver
  * @param string                            $format Format to check
  *
  * @return bool
  */
 public function recordSupportsFormat($driver, $format)
 {
     // Check if the driver explicitly disallows the format:
     if ($driver->tryMethod('exportDisabled', [$format])) {
         return false;
     }
     // Check the requirements for export in the requested format:
     if (isset($this->exportConfig->{$format})) {
         if (isset($this->exportConfig->{$format}->requiredMethods)) {
             foreach ($this->exportConfig->{$format}->requiredMethods as $method) {
                 // If a required method is missing, give up now:
                 if (!is_callable([$driver, $method])) {
                     return false;
                 }
             }
         }
         // If we got this far, we didn't encounter a problem, and the
         // requested export format is valid, so we can report success!
         return true;
     }
     // If we got this far, we couldn't find evidence of support:
     return false;
 }
Exemplo n.º 9
0
 /**
  * Try to build an array of OCLC Number, ISBN or ISSN-based sub-queries by
  * using OCLC X-services against a record driver object.
  *
  * @param \VuFind\RecordDriver\AbstractBase $driver Record driver object
  *
  * @return array
  */
 protected function getQueryParts($driver)
 {
     $parts = [];
     $oclcNum = $driver->tryMethod('getCleanOCLCNum');
     if (!empty($oclcNum)) {
         $oclcList = $this->wcUtils->getXOCLCNUM($oclcNum);
         foreach ($oclcList as $current) {
             $parts[] = "oclc_num:" . $current;
         }
     }
     $isbn = $driver->tryMethod('getCleanISBN');
     if (!empty($isbn)) {
         $isbnList = $this->wcUtils->getXISBN($isbn);
         foreach ($isbnList as $current) {
             $parts[] = 'isbn:' . $current;
         }
     }
     $issn = $driver->tryMethod('getCleanISSN');
     if (!empty($issn)) {
         $issnList = $this->wcUtils->getXISSN($issn);
         foreach ($issnList as $current) {
             $parts[] = 'issn:' . $current;
         }
     }
     return $parts;
 }
Exemplo n.º 10
0
 /**
  * Support method to extract modified date from a record driver object.
  *
  * @param \VuFind\RecordDriver\AbstractBase $record Record to pull date from.
  *
  * @return int|DateTime|null
  */
 protected function getDateModified($record)
 {
     // Best case -- "last indexed" date is available:
     $date = $record->tryMethod('getLastIndexed');
     if (!empty($date)) {
         return strtotime($date);
     }
     // Next, try publication date:
     $date = $record->tryMethod('getPublicationDates');
     if (isset($date[0])) {
         // Extract first string of numbers -- this should be a year:
         preg_match('/[^0-9]*([0-9]+).*/', $date[0], $matches);
         $date = new DateTime();
         $date->setDate($matches[1], 1, 1);
         return $date;
     }
     // If we got this far, no date is available:
     return null;
 }