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;
 }
Example #2
0
File: Page.php Project: tgdn/cs139
 public function authenticate_user()
 {
     global $user;
     if (is_null($user)) {
         $user = new User();
     }
     if (array_key_exists('uid', $_SESSION)) {
         $user = User::fromID($_SESSION['uid']);
     }
 }
 function prepareUser()
 {
     $id = isset($_SESSION["user_id"]) ? $_SESSION["user_id"] : -1;
     if ($id != -1) {
         $this->_user = User::fromID($id);
         // Update last logon date
         $sql = "UPDATE users SET last_logon_date = now() WHERE id = ?";
         $sth = DatabaseHelper::getInstance()->prepare($sql);
         $sth->bindParam($id);
         $sth->execute();
     } else {
         $this->_user = new User(-1, User::ANONYMOUS, array());
     }
 }
Example #4
0
 function build($tpl)
 {
     $sql = "SELECT a.id, (SELECT COUNT(*) FROM published_articles WHERE author_id = a.id) AS articles_count FROM users a";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $users = array();
     while ($row = $sth->fetch()) {
         $user = User::fromID($row["id"]);
         $data = $user->getProperties();
         $data["icon"] = WEBAPP_WEBSITE_URL . "upload/bc6cea68f3a413d20d17202cb67b03d2.jpg";
         $data["articles_count"] = $row["articles_count"];
         array_push($users, $data);
     }
     $tpl->assign("users", $users);
     $tpl->display('users-list.tpl');
 }
Example #5
0
 function build($tpl)
 {
     $sql = "SELECT id FROM users WHERE username LIKE ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $_GET["name"]);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $user = User::fromID($res["id"]);
     $arr = $user->getProperties();
     // Query the number of articles.
     $sql = "SELECT COUNT(*) AS count FROM published_articles INNER JOIN users ON (published_articles.author_id = users.id) WHERE published = 1";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $arr["articles_count"] = $res["count"];
     $tpl->assign("userInfo", $arr);
     $tpl->display('users-view.tpl');
 }
Example #6
0
 public function __construct()
 {
     global $db;
     // if SESSION died
     if (empty($_SESSION[$this->sessionName])) {
         // if cookie is set
         if (isset($_COOKIE[self::COOKIE_AUTO_USERNAME]) && isset($_COOKIE[self::COOKIE_AUTO_TOKEN])) {
             // try to log in
             $this->login($_COOKIE[self::COOKIE_AUTO_USERNAME], $_COOKIE[self::COOKIE_AUTO_TOKEN], true, null);
         } else {
             $this->updateOnlineList();
         }
     } else {
         // get user from session
         $this->user = User::fromID($_SESSION[$this->sessionName]);
         $this->setLastVisit();
         $this->updateOnlineList();
     }
 }
Example #7
0
 public function getUser()
 {
     if (!$this->user instanceof User) {
         $this->user = User::fromID($this->userID);
     }
     return $this->user;
 }