Beispiel #1
0
 /**
  * @return Article
  */
 public function findRandomArticleWithoutTweets()
 {
     $stmt = $this->pdo->prepare("\n            SELECT\n                a.article_id\n              , a.title\n              , a.url\n            FROM\n                articles a\n                    LEFT JOIN\n                        tweets t ON\n                            a.article_id = t.article_id\n            WHERE\n                t.updated_at IS NULL\n            ORDER BY\n                rand()\n            LIMIT 1\n        ");
     $stmt->execute();
     $record = $stmt->fetch(PDO::FETCH_ASSOC);
     if (empty($record)) {
         return null;
     }
     $article = new Article($record['article_id']);
     $article->setTitle($record['title']);
     $article->setUrl($record['url']);
     return $article;
 }
 /**
  * @param Article $article
  */
 protected function storeTweets(Article $article)
 {
     $stmt = $this->pdo->prepare("\n            INSERT INTO tweets (\n                article_id\n            )\n            VALUES (\n                :article_id\n            )\n        ");
     $stmt->bindValue(':article_id', $article->getArticleId(), PDO::PARAM_INT);
     $stmt->execute();
 }