Exemplo n.º 1
0
 /**
  * @param Feed $feed
  * @depends testSaveFeeds
  */
 public function testSaveSameFeed(Feed $feed)
 {
     $store = new PdoStore($this->dsn, null, null);
     // we should search for feed
     $feed->setId(null);
     $record = new Record();
     $record->setTitle('item 2');
     $record->setPublicationDate(new \DateTime('-10 hours'));
     $feed->addRecord($record);
     $store->save($feed);
     $loadedFeed = $store->loadFeed(1);
     $records = $store->loadItems($loadedFeed->getId());
     static::assertEquals($record->getTitle(), $records[2]->getTitle());
 }
Exemplo n.º 2
0
 private function extract(\DOMElement $node)
 {
     $item = new Record();
     foreach (self::$propertiesMapping as $nodeName => $methodName) {
         $item->{$methodName}($this->getNodeValueByTagName($node, $nodeName));
     }
     if ($date = $this->getNodeValueByTagName($node, 'pubDate')) {
         $item->setPublicationDate(\DateTime::createFromFormat(\DateTime::RSS, $date));
     }
     $tags = $node->getElementsByTagName('category');
     if ($tags->length) {
         foreach ($tags as $tag) {
             /** @var \DomElement $tag */
             if ($tag->nodeValue) {
                 $item->addTag($tag->nodeValue);
             }
         }
     }
     return $item;
 }
Exemplo n.º 3
0
 private function hydrateRecord(array $row)
 {
     $feed = new Record();
     $feed->setId($row['id']);
     $feed->setTitle($row['title']);
     $feed->setContent($row['content']);
     $feed->setPicture($row['picture']);
     $feed->setAuthor($row['author']);
     $feed->setLink($row['link']);
     $feed->setGuid($row['guid']);
     $feed->setPublicationDate(new \DateTime($row['publication_date']));
     $feed->setTags(json_decode($row['tags'], true));
     return $feed;
 }
Exemplo n.º 4
0
 private function setTags(\DOMElement $node, Record $item)
 {
     $tags = $node->getElementsByTagName('category');
     foreach ($tags as $tag) {
         /** @var \DomElement $tag */
         if ($tag->getAttribute('term')) {
             $item->addTag($tag->getAttribute('label') ?: $tag->getAttribute('term'));
         }
     }
 }