/**
  * The item is valid if it was last updated after the modified since date.
  *
  * @param Item $item
  *
  * @return bool
  */
 public function isValid(Item $item)
 {
     if ($item->getUpdated() instanceof \DateTime) {
         return $item->getUpdated() > $this->getDate();
     }
     return false;
 }
 /**
  * @param \Symfony\Component\OptionsResolver\Options $options
  * @return \Debril\FeedAggregatorBundle\Provider\Feed
  * @throws FeedNotFoundException
  */
 public function getFeedContent(array $options)
 {
     // fetch feed from data repository
     /*  $qb->select( 'e' )
         ->from( 'Entity\Event',  'e' )
         ->Where(
         $qb->expr()->andX(
         $qb->expr()->between('e.dateStart', ':from', ':to')
         )
         )
         ->orderBy('e.dateStart', 'ASC')
         ->setFirstResult( $offset )
         ->setMaxResults( $limit );*/
     $repository = $this->doctrine->getRepository('OpenSourceFeedBundle:Post');
     // createQueryBuilder automatically selects FROM AppBundle:Product
     // and aliases it to "p"
     $query = $repository->createQueryBuilder('p')->orderBy('p.date', 'DESC')->setMaxResults(10)->getQuery();
     $entities = $query->getResult();
     $feed = new FeedContent();
     //$feed -> setLastModified();
     $feed->setLastModified(new \DateTime());
     foreach ($entities as $post) {
         $item = new Item();
         $item->setTitle($post->getTitle());
         $item->setUpdated($post->getDate());
         $item->setLink($this->generateUrl('post_show', array('id' => $post->getId(), 'slug' => $post->getSlug())));
         $feed->addItem($item);
     }
     /*$feed = new FeedContent;
      *
      * $feed->setLastModified($lastTimeANewsWasUpdated);
      *
      * $feed->setTitle('your feed title');
      * $feed->setDescription('the description');
      * $feed->addItem($item);*/
     // if the feed is an actual FeedOut instance, then return it
     //if ($feed instanceof \Debril\RssAtomBundle\Protocol\FeedOut)
     return $feed;
     // $feed is null, which means no Feed was found with this id.
     throw new FeedNotFoundException();
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     $this->feed = new FeedContent();
     $this->feed->setPublicId('feed id');
     $this->feed->setLink('http://example.com');
     $this->feed->setTitle('feed title');
     $this->feed->setDescription('feed subtitle');
     $this->feed->setLastModified(new \DateTime());
     $item = new Item();
     $item->setPublicId('item id');
     $item->setLink('http://example.com/1');
     $item->setSummary('lorem ipsum');
     $item->setTitle('title 1');
     $item->setUpdated(new \DateTime());
     $item->setComment('http://linktothecomments.com');
     $item->setAuthor('Contributor');
     $media = new Media();
     $media->setUrl('http://media');
     $media->setUrl('image/jpeg');
     $item->addMedia($media);
     $this->feed->addItem($item);
 }
 /**
  * @param array $options
  *
  * @return FeedContent
  *
  * @throws FeedNotFoundException
  */
 public function getFeedContent(array $options)
 {
     $content = new FeedContent();
     $id = array_key_exists('id', $options) ? $options['id'] : null;
     if ($id === 'not-found') {
         throw new FeedNotFoundException();
     }
     $content->setPublicId($id);
     $content->setTitle('thank you for using RssAtomBundle');
     $content->setDescription('this is the mock FeedContent');
     $content->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/');
     $content->setLastModified(new \DateTime());
     $item = new Item();
     $item->setPublicId('1');
     $item->setLink('https://raw.github.com/alexdebril/rss-atom-bundle/somelink');
     $item->setTitle('This is an item');
     $item->setSummary('this stream was generated using the MockProvider class');
     $item->setDescription('lorem ipsum ....');
     $item->setUpdated(new \DateTime());
     $item->setComment('http://example.com/comments');
     $item->setAuthor('Contributor');
     $content->addItem($item);
     return $content;
 }
Ejemplo n.º 5
0
 /**
  * @covers Debril\RssAtomBundle\Protocol\Parser::addAcceptableItem
  */
 public function testAddUnacceptableItem()
 {
     $feed = new FeedContent();
     $item = new Item();
     $date = new \DateTime();
     $item->setUpdated($date);
     $ret = $this->object->addAcceptableItem($feed, $item, $date);
     $this->assertInstanceOf('Debril\\RssAtomBundle\\Protocol\\Parser', $ret);
     $this->assertEquals(0, $feed->getItemsCount());
 }