public function fetchPostsByFeeds($feeds, $offset = null, $limit = null)
 {
     $select = new Select(self::$_tableName);
     if (!is_null($offset)) {
         $select->offset($offset);
     }
     if (!is_null($limit)) {
         $select->limit($limit);
     }
     $select->join('directus_social_feeds', 'directus_social_feeds.id = directus_social_posts.feed', ['feed_type' => 'type'])->order('directus_social_posts.datetime DESC');
     $select->where->equalTo('directus_social_posts.status', 1)->equalTo('directus_social_feeds.status', 1);
     $FeedWhere = new Where();
     $SocialCache = new SocialCache();
     foreach ($feeds as $feed) {
         // Run scrape if due
         $SocialCache->scrapeFeedIfDue($feed['name'], $feed['type']);
         $FeedWhere->or->nest->equalTo('directus_social_feeds.name', $feed['name'])->equalTo('directus_social_feeds.type', $feed['type'])->unnest;
         $select->where($FeedWhere);
     }
     $socialPosts = $this->selectWith($select);
     $socialPosts = $socialPosts->toArray();
     // Unserialize cached feed entry API-responses
     foreach ($socialPosts as &$post) {
         $post['data'] = json_decode($post['data'], true);
     }
     return $socialPosts;
 }
 public function fetchFeedsById($feeds)
 {
     $socialFeedsById = [];
     $select = new Select(self::$_tableName);
     $FeedWhere = new Where();
     $SocialCache = new SocialCache();
     foreach ($feeds as $feed) {
         // Run scrape if due
         $SocialCache->scrapeFeedIfDue($feed['name'], $feed['type']);
         $FeedWhere->or->nest->equalTo('directus_social_feeds.name', $feed['name'])->equalTo('directus_social_feeds.type', $feed['type'])->unnest;
         $select->where($FeedWhere);
     }
     $select->where($FeedWhere);
     $socialFeeds = $this->selectWith($select);
     $socialFeeds = $socialFeeds->toArray();
     // Store feeds by ID
     foreach ($socialFeeds as &$feed) {
         $feed['data'] = json_decode($feed['data'], true);
         $socialFeedsById[$feed['id']] = $feed;
     }
     return $socialFeedsById;
 }