/** * Adds a comment to the article with the given id * @param $article_id the id of the article * @param $text the text of the comment * @return Comment the new comment */ public function add_comment_to_article($article_id, $text) { $username = AuthenticationService::get_current_username(); $date = time(); //get user id from alias $query = "SELECT id FROM user WHERE alias = '{$username}'"; $result = $this->sql_con->query($query); $row = mysqli_fetch_assoc($result); $user_id = $row['id']; $query = "INSERT INTO `webinfo`.`comment` (`user_id`, `text`, `creation_date`, `article`) "; $query .= "VALUES ('{$user_id}', '{$text}', '{$date}', '{$article_id}')"; $result = $this->sql_con->query($query); $id = mysqli_insert_id($this->sql_con); $comment = new Comment($id, $username, $text, $date); return $comment; }