/** * 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); } $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); }
/** * Create and attach entries to a feed * * @param array|Traversable $entries * @param Feed $feed * @return void */ protected static function createEntries($entries, Feed $feed) { if (!is_array($entries) && !$entries instanceof Traversable) { throw new Exception\InvalidArgumentException(sprintf('%s::factory expects the "entries" value to be an array or Traversable; received "%s"', get_called_class(), is_object($entries) ? get_class($entries) : gettype($entries))); } foreach ($entries as $data) { if (!is_array($data) && !$data instanceof Traversable && !$data instanceof Entry) { throw Exception\InvalidArgumentException(sprintf('%s expects an array, Traversable, or Zend\\Feed\\Writer\\Entry argument; received "%s"', __METHOD__, is_object($data) ? get_class($data) : gettype($data))); } // Use case 1: Entry item if ($data instanceof Entry) { $feed->addEntry($data); continue; } // Use case 2: iterate item and populate entry $entry = $feed->createEntry(); foreach ($data as $key => $value) { $key = static::convertKey($key); $method = 'set' . $key; if (!method_exists($entry, $method)) { continue; } $entry->{$method}($value); } $feed->addEntry($entry); } }
$sPosition_mRNA = $sRefSeq . ':c.' . $sDNAStart . ($zData['position_c_end'] == $zData['position_c_start'] ? '' : '_' . $sDNAEnd); $sPosition_genomic = 'chr' . $sChromosome . ':' . $zData['position_g_start'] . ($zData['position_g_end'] == $zData['position_g_start'] ? '' : '_' . $zData['position_g_end']); } else { $sPosition_mRNA = lovd_variantToPosition($zData['VariantOnTranscript/DNA']); $sPosition_genomic = 'chr' . $sChromosome . ':?'; } // Really not quite the best solution, but it kind of works. $n is decreased and if there are no more matches, it will give a 404 anyway. Still has a misleading Feed title, though! // FIXME; do we want to fix that by implementing a $_FEED->setTitle()? if (!$sRefSeq && $bSearching && !empty($_GET['search_position']) && $_GET['search_position'] != $sPosition_mRNA) { // This was a false positive! (only when there is no Reference Sequence LOVD will try the DNA field to find the position) Partial match that should not have been reported. Byeeeeeeee... $n--; // Does not really matter at this point. continue; } $sContent = 'symbol:' . $sSymbol . "\n" . ($bUnique ? '' : 'id:' . $zData['id'] . "\n") . 'position_mRNA:' . $sPosition_mRNA . "\n" . 'position_genomic:' . $sPosition_genomic . "\n" . 'Variant/DNA:' . htmlspecialchars($zData['VariantOnTranscript/DNA']) . "\n" . 'Variant/DBID:' . $zData['VariantOnGenome/DBID'] . "\n" . 'Times_reported:' . $zData['Times']; $_FEED->addEntry($sTitle, $sSelfURL, $sAltURL, $sID, $zData['created_by'], $zData['created_date'], $sContributors, $zData['updated_date'], '', 'text', $sContent); } } elseif ($sDataType == 'genes') { foreach ($aData as $zData) { // Prepare other fields to be included. $sTitle = $zData['id']; if ($sFeedType == 'feed') { $sSelfURL = ($_CONF['location_url'] ? $_CONF['location_url'] : lovd_getInstallURL()) . 'api/rest.php/genes/' . $zData['id']; } else { $sSelfURL = ''; } $sChromosome = $zData['chromosome']; $sAltURL = ($_CONF['location_url'] ? $_CONF['location_url'] : lovd_getInstallURL()) . 'genes/' . $zData['id']; $sID = 'tag:' . $_SERVER['HTTP_HOST'] . ',' . substr($zData['created_date'], 0, 10) . ':' . $zData['id']; $sContributors = ''; $sContributors .= ($sContributors ? ', ' : '') . htmlspecialchars($zData['curators']);