return Response::make('Not Found', 404); } $feed = new Feed(); $feed->setTitle($model->getAttribute('title'))->setDescription($model->getAttribute('description'))->setBaseUrl(Url::to('/'))->setGenerator('OctoberCMS/Adrenth.RssFetcher')->setId('Adrenth.RssFecther.' . $model->getAttribute('id'))->setLink(Url::to('/feeds/' . $path))->setFeedLink(Url::to('/feeds/' . $path), $model->getAttribute('type'))->setDateModified()->addAuthor(['name' => 'OctoberCMS']); /** @type Collection $sources */ $sources = $model->sources; $ids = Arr::pluck($sources->toArray(), 'id'); $items = []; Source::with(['items' => function ($builder) use(&$items, $model) { $items = $builder->where('is_published', '=', 1)->whereDate('pub_date', '=', date('Y-m-d'))->orderBy('pub_date', 'desc')->limit($model->getAttribute('max_items'))->get(); }])->whereIn('id', $ids)->where('is_enabled', '=', 1)->get(); /** @type Item $item */ foreach ($items as $item) { try { $entry = new Entry(); $entry->setId((string) $item->getAttribute('id'))->setTitle($item->getAttribute('title'))->setDescription($item->getAttribute('description'))->setLink($item->getAttribute('link'))->setDateModified($item->getAttribute('pub_date')); $comments = $item->getAttribute('comments'); if (!empty($comments)) { $entry->setCommentLink($comments); } $category = $item->getAttribute('category'); if (!empty($category)) { $entry->addCategory(['term' => $category]); } $feed->addEntry($entry); } catch (InvalidArgumentException $e) { continue; } } return Response::make($feed->export($model->getAttribute('type')), 200, ['Content-Type' => sprintf('application/%s+xml', $model->getAttribute('type'))]); });
public function testSetIdThrowsExceptionOnInvalidParameter() { $entry = new Writer\Entry(); try { $entry->setId(''); $this->fail(); } catch (Writer\Exception $e) { } }
/** * Populates a feed entry with data coming from Version objects. * * @param \Zend\Feed\Writer\Entry $entry * @param Version $version */ protected function populateVersionData(Entry $entry, Version $version) { $entry->setTitle($entry->getTitle() . " ({$version->getVersion()})"); $entry->setId($entry->getId() . ' ' . $version->getVersion()); $entry->setDateModified($version->getReleasedAt()); $entry->setDateCreated($version->getReleasedAt()); foreach ($version->getAuthors() as $author) { /** @var $author \Packagist\WebBundle\Entity\Author */ if ($author->getName()) { $entry->addAuthor(array('name' => $author->getName())); } } }