/** * 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); }
/** * 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; }
/** * 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'); $entry->setTitle(empty($title) ? $record->getBreadcrumb() : $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]); } $formats = $record->tryMethod('getFormats'); if (is_array($formats)) { foreach ($formats as $format) { $entry->addDCFormat($format); } } $date = $record->tryMethod('getPublicationDates'); if (isset($date[0]) && !empty($date[0])) { $entry->setDCDate($date[0]); } $feed->addEntry($entry); }
/** * Get the default subject line for sendRecord() * * @param \VuFind\RecordDriver\AbstractBase $record Record being emailed * * @return string */ public function getDefaultRecordSubject($record) { return $this->translate('Library Catalog Record') . ': ' . $record->getBreadcrumb(); }
/** * 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'); $entry->setTitle(empty($title) ? $record->getBreadcrumb() : $title); $serverUrl = $this->getView()->plugin('serverurl'); $recordLink = $this->getView()->plugin('recordlink'); $entry->setLink($serverUrl($recordLink->getUrl($record))); $date = $this->getDateModified($record); if (!empty($date)) { $entry->setDateModified($date); } $author = $record->tryMethod('getPrimaryAuthor'); if (!empty($author)) { $entry->addAuthor(array('name' => $author)); } $formats = $record->tryMethod('getFormats'); if (is_array($formats)) { foreach ($formats as $format) { $entry->addDCFormat($format); } } $date = $record->tryMethod('getPublicationDates'); if (isset($date[0]) && !empty($date[0])) { $entry->setDCDate($date[0]); } $feed->addEntry($entry); }
/** * Send an email message representing a record. * * @param string $to Recipient email address * @param string $from Sender email address * @param string $msg User notes to include in * message * @param \VuFind\RecordDriver\AbstractBase $record Record being emailed * @param \Zend\View\Renderer\RendererInterface $view View object (used to * render email templates) * * @throws MailException * @return void */ public function sendRecord($to, $from, $msg, $record, $view) { $subject = $this->translate('Library Catalog Record') . ': ' . $record->getBreadcrumb(); $body = $view->partial('Email/record.phtml', array('driver' => $record, 'to' => $to, 'from' => $from, 'message' => $msg)); return $this->send($to, $from, $subject, $body); }