Example #1
0
 public static function fromID($id)
 {
     $sql = "SELECT *, COALESCE(release_date, created_date) AS \"date\" FROM articles WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     if ($res == false) {
         throw new Exception("Impossible de trouver cet article", 404);
     }
     $instance = new Article($res["id"], $res["title"], $res["summary"], $res["content"], null, null);
     $instance->_author = User::fromID($res["author_id"]);
     $instance->_categories = array();
     $instance->_date = $res["date"];
     $instance->_published = $res["published"];
     $instance->_last_modified_date = $res["last_modified_date"];
     $instance->_comment_fb_url = DOMAIN_NAME . WEBAPP_WEBSITE_URL . "news/" . $instance->_id;
     $instance->_comments = $instance->queryCommentsCount();
     // Get the count of articles.
     $sql = "SELECT * FROM categories INNER JOIN articles_categories ON (articles_categories.category_id = categories.id) WHERE article_id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     while ($row = $sth->fetch()) {
         array_push($instance->_categories, $row);
     }
     return $instance;
 }