@@ -195,8 +195,8 @@ |
||
| 195 | 195 | } |
| 196 | 196 | $page->add("post/show", |
| 197 | 197 | ["post" => $posts[0], |
| 198 | - "postscore" => $postscore[0]->postscore?:0, |
|
| 199 | - "totalanswer" => $answer[0]->totalanswer?:0, |
|
| 198 | + "postscore" => $postscore[0]->postscore?:0, |
|
| 199 | + "totalanswer" => $answer[0]->totalanswer?:0, |
|
| 200 | 200 | "answers" => $answers, |
| 201 | 201 | "comments0" => $comments0, |
| 202 | 202 | "isOwner" => $isOwner, |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | // Connect the database |
| 45 | 45 | $this->db = $this->di->get("db"); |
| 46 | 46 | $this->db->connect(); |
| 47 | - if ($this->currentUser !=null) { |
|
| 47 | + if ($this->currentUser!=null) { |
|
| 48 | 48 | $sql = "SELECT id from users where username = ?;"; |
| 49 | - $res = $this->db->executeFetchAll($sql, [$this->currentUser]); |
|
| 50 | - $this->userId = $res[0]->id; |
|
| 49 | + $res = $this->db->executeFetchAll($sql, [ $this->currentUser ]); |
|
| 50 | + $this->userId = $res[ 0 ]->id; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | $tags = $request->getPost("Tags") ?: null; |
| 115 | 115 | |
| 116 | 116 | $sql = "INSERT INTO posts (title, content, user_id) VALUES (?, ?, ?);"; |
| 117 | - $this->db->execute($sql, [$title, $content, $this->userId]); |
|
| 117 | + $this->db->execute($sql, [ $title, $content, $this->userId ]); |
|
| 118 | 118 | $lastInsertId = $this->db->lastInsertId(); |
| 119 | 119 | var_dump($lastInsertId); |
| 120 | 120 | $tagsArray = explode(",", $tags); |
| 121 | 121 | foreach ($tagsArray as $value) { |
| 122 | 122 | $sql = "INSERT INTO post2tag (post_id, tag_name) VALUES (?, ?);"; |
| 123 | - $this->db->execute($sql, [$lastInsertId, trim($value)]); |
|
| 123 | + $this->db->execute($sql, [ $lastInsertId, trim($value) ]); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $response->redirect("post"); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $comment = $request->getPost("answer") ?: null; |
| 147 | 147 | |
| 148 | 148 | $sql = "INSERT INTO comments (comment, user_id, post_id, answer) VALUES (?, ?, ?, ?);"; |
| 149 | - $this->db->execute($sql, [$comment, $this->userId, $post_id, 1]); |
|
| 149 | + $this->db->execute($sql, [ $comment, $this->userId, $post_id, 1 ]); |
|
| 150 | 150 | $response = $this->di->get("response"); |
| 151 | 151 | return $response->redirect("post/show/$post_id"); |
| 152 | 152 | } |
@@ -171,32 +171,32 @@ discard block |
||
| 171 | 171 | $orderBy = $request->getGet("orderby") ?: "created"; |
| 172 | 172 | $order = $request->getGet("order") ?: "asc"; |
| 173 | 173 | $sql = "SELECT * from posts WHERE id=?;"; |
| 174 | - $posts = $this->db->executeFetchAll($sql, [$postid]); |
|
| 174 | + $posts = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 175 | 175 | $sql = "select * from post2tag where post_id=?;"; |
| 176 | - $posttags = $db->executeFetchAll($sql, [$item->id]); |
|
| 176 | + $posttags = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 177 | 177 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 178 | - $score = $this->db->executeFetchAll($sql, [$item->id]); |
|
| 178 | + $score = $this->db->executeFetchAll($sql, [ $item->id ]); |
|
| 179 | 179 | $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;"; |
| 180 | - $answer = $this->db->executeFetchAll($sql, [$item->id]); |
|
| 180 | + $answer = $this->db->executeFetchAll($sql, [ $item->id ]); |
|
| 181 | 181 | |
| 182 | 182 | $sql = "SELECT * from v_comments_user WHERE post_id=? and answer=1 order by accepted desc, $orderBy $order;"; |
| 183 | 183 | //Get the answers for the post |
| 184 | - $answers = $this->db->executeFetchAll($sql, [$postid]); |
|
| 184 | + $answers = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 185 | 185 | $sql = "SELECT * from v_comments_user WHERE post_id=? and answer=0 and ISNULL(comment_reply_id);"; |
| 186 | 186 | // Get the comments for the post |
| 187 | - $comments0 = $this->db->executeFetchAll($sql, [$postid]); |
|
| 187 | + $comments0 = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | // check if the current user is the owner of the question, if yes, show the accepted answer button otherwise not |
| 191 | 191 | // var_dump($this->currentUser,$posts[0]->username ); |
| 192 | - $isOwner=true; |
|
| 193 | - if ($this->currentUser != $posts[0]->username ) { |
|
| 192 | + $isOwner = true; |
|
| 193 | + if ($this->currentUser!=$posts[ 0 ]->username) { |
|
| 194 | 194 | $isOwner = false; |
| 195 | 195 | } |
| 196 | 196 | $page->add("post/show", |
| 197 | - ["post" => $posts[0], |
|
| 198 | - "postscore" => $postscore[0]->postscore?:0, |
|
| 199 | - "totalanswer" => $answer[0]->totalanswer?:0, |
|
| 197 | + [ "post" => $posts[ 0 ], |
|
| 198 | + "postscore" => $postscore[ 0 ]->postscore ?: 0, |
|
| 199 | + "totalanswer" => $answer[ 0 ]->totalanswer ?: 0, |
|
| 200 | 200 | "answers" => $answers, |
| 201 | 201 | "comments0" => $comments0, |
| 202 | 202 | "isOwner" => $isOwner, |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $page = $this->di->get("page"); |
| 213 | 213 | |
| 214 | 214 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 215 | - $this->db->execute($sql, [1, $id, $this->userId]); |
|
| 215 | + $this->db->execute($sql, [ 1, $id, $this->userId ]); |
|
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | $response = $this->di->get("response"); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $page = $this->di->get("page"); |
| 225 | 225 | |
| 226 | 226 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 227 | - $this->db->execute($sql, [-1, $id, $this->userId]); |
|
| 227 | + $this->db->execute($sql, [-1, $id, $this->userId ]); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | $response = $this->di->get("response"); |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | // Connect the database |
| 45 | 45 | $this->db = $this->di->get("db"); |
| 46 | 46 | $this->db->connect(); |
| 47 | - if ($this->currentUser !=null) { |
|
| 47 | + if ($this->currentUser!=null) { |
|
| 48 | 48 | $sql = "SELECT id from users where username = ?;"; |
| 49 | - $res = $this->db->executeFetchAll($sql, [$this->currentUser]); |
|
| 50 | - $this->userId = $res[0]->id; |
|
| 49 | + $res = $this->db->executeFetchAll($sql, [ $this->currentUser ]); |
|
| 50 | + $this->userId = $res[ 0 ]->id; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | $tags = $request->getPost("Tags") ?: null; |
| 121 | 121 | |
| 122 | 122 | $sql = "INSERT INTO posts (title, content, user_id) VALUES (?, ?, ?);"; |
| 123 | - $this->db->execute($sql, [$title, $content, $this->userId]); |
|
| 123 | + $this->db->execute($sql, [ $title, $content, $this->userId ]); |
|
| 124 | 124 | $lastInsertId = $this->db->lastInsertId(); |
| 125 | 125 | // var_dump($lastInsertId); |
| 126 | 126 | $tagsArray = explode(",", $tags); |
| 127 | 127 | foreach ($tagsArray as $value) { |
| 128 | 128 | $sql = "INSERT INTO post2tag (post_id, tag_name) VALUES (?, ?);"; |
| 129 | - $this->db->execute($sql, [$lastInsertId, trim($value)]); |
|
| 129 | + $this->db->execute($sql, [ $lastInsertId, trim($value) ]); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return $response->redirect("post"); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $comment = $request->getPost("answer") ?: null; |
| 153 | 153 | |
| 154 | 154 | $sql = "INSERT INTO comments (comment, user_id, post_id, answer) VALUES (?, ?, ?, ?);"; |
| 155 | - $this->db->execute($sql, [$comment, $this->userId, $post_id, 1]); |
|
| 155 | + $this->db->execute($sql, [ $comment, $this->userId, $post_id, 1 ]); |
|
| 156 | 156 | $response = $this->di->get("response"); |
| 157 | 157 | return $response->redirect("post/show/$post_id"); |
| 158 | 158 | } |
@@ -179,43 +179,43 @@ discard block |
||
| 179 | 179 | // Get the post $id , votes and answers and tags and username |
| 180 | 180 | $sql = "SELECT * from posts where id=?;"; |
| 181 | 181 | |
| 182 | - $posts = $this->db->executeFetchAll($sql, [$postid]); |
|
| 182 | + $posts = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 183 | 183 | $sql = "SELECT username FROM users WHERE id=?;"; |
| 184 | - $username = $this->db->executeFetchAll($sql, [$posts[0]->user_id]); |
|
| 184 | + $username = $this->db->executeFetchAll($sql, [ $posts[ 0 ]->user_id ]); |
|
| 185 | 185 | $sql = "select * from post2tag where post_id=?;"; |
| 186 | - $posttags = $this->db->executeFetchAll($sql, [$postid]); |
|
| 186 | + $posttags = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 187 | 187 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 188 | - $postscore = $this->db->executeFetchAll($sql, [$postid]); |
|
| 188 | + $postscore = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 189 | 189 | // Get the comments for the post |
| 190 | 190 | |
| 191 | 191 | $sql = "SELECT * from comments WHERE post_id=? and answer=0 and ISNULL(comment_reply_id);"; |
| 192 | - $comments0 = $this->db->executeFetchAll($sql, [$postid]); |
|
| 192 | + $comments0 = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 193 | 193 | //Get the answers for the post $id |
| 194 | 194 | // $sql = "SELECT * from comments WHERE post_id=? and answer=1 order by accepted desc, $orderBy $order;"; |
| 195 | - $sql ="SELECT c.*, sum(v.score) votes |
|
| 195 | + $sql = "SELECT c.*, sum(v.score) votes |
|
| 196 | 196 | FROM comments AS c |
| 197 | 197 | LEFT JOIN comment_votes AS v |
| 198 | 198 | ON c.id = v.comment_id |
| 199 | 199 | WHERE post_id=? and answer=1 |
| 200 | 200 | group by id |
| 201 | 201 | order by accepted desc, $orderBy $order"; |
| 202 | - $answers = $this->db->executeFetchAll($sql, [$postid]); |
|
| 202 | + $answers = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 203 | 203 | // var_dump($sql); |
| 204 | 204 | // var_dump($answers); |
| 205 | 205 | // check if the current user is the owner of the question, if yes, show the accepted answer button otherwise not |
| 206 | 206 | // var_dump($this->currentUser,$posts[0]->username ); |
| 207 | - $isOwner=true; |
|
| 208 | - if ($this->userId != $posts[0]->user_id ) { |
|
| 207 | + $isOwner = true; |
|
| 208 | + if ($this->userId!=$posts[ 0 ]->user_id) { |
|
| 209 | 209 | $isOwner = false; |
| 210 | 210 | } |
| 211 | 211 | $page->add("post/show", |
| 212 | - ["post" => $posts[0], |
|
| 213 | - "postscore" => $postscore[0]->postscore?:0, |
|
| 212 | + [ "post" => $posts[ 0 ], |
|
| 213 | + "postscore" => $postscore[ 0 ]->postscore ?: 0, |
|
| 214 | 214 | "posttags" => $posttags, |
| 215 | 215 | "answers" => $answers, |
| 216 | 216 | "comments0" => $comments0, |
| 217 | 217 | "isOwner" => $isOwner, |
| 218 | - "post_owner" => $username[0]->username, |
|
| 218 | + "post_owner" => $username[ 0 ]->username, |
|
| 219 | 219 | ]); |
| 220 | 220 | |
| 221 | 221 | return $page->render([ |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | public function uppvoteAction(int $id) : object |
| 227 | 227 | { |
| 228 | 228 | $page = $this->di->get("page"); |
| 229 | - if ($this->currentUser){ |
|
| 229 | + if ($this->currentUser) { |
|
| 230 | 230 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 231 | - $this->db->execute($sql, [1, $id, $this->userId]); |
|
| 231 | + $this->db->execute($sql, [ 1, $id, $this->userId ]); |
|
| 232 | 232 | $response = $this->di->get("response"); |
| 233 | 233 | return $response->redirect("post/show/$id"); |
| 234 | 234 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $page = $this->di->get("page"); |
| 242 | 242 | if ($this->currentUser) { |
| 243 | 243 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 244 | - $this->db->execute($sql, [-1, $id, $this->userId]); |
|
| 244 | + $this->db->execute($sql, [-1, $id, $this->userId ]); |
|
| 245 | 245 | |
| 246 | 246 | $response = $this->di->get("response"); |
| 247 | 247 | return $response->redirect("post/show/$id"); |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | // Connect the database |
| 45 | 45 | $this->db = $this->di->get("db"); |
| 46 | 46 | $this->db->connect(); |
| 47 | - if ($this->currentUser !=null) { |
|
| 47 | + if ($this->currentUser!=null) { |
|
| 48 | 48 | $sql = "SELECT id from users where username = ?;"; |
| 49 | - $res = $this->db->executeFetchAll($sql, [$this->currentUser]); |
|
| 50 | - $this->userId = $res[0]->id; |
|
| 49 | + $res = $this->db->executeFetchAll($sql, [ $this->currentUser ]); |
|
| 50 | + $this->userId = $res[ 0 ]->id; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | if ($submit) { |
| 62 | 62 | $comment = $request->getPost("comment") ?: null; |
| 63 | 63 | $sql = "INSERT INTO comments (comment, post_id, user_id, answer) VALUES (?, ?, ?, ?);"; |
| 64 | - $this->db->execute($sql, [$comment, $id, $this->userId, 0]); |
|
| 64 | + $this->db->execute($sql, [ $comment, $id, $this->userId, 0 ]); |
|
| 65 | 65 | return $response->redirect("post/show/$id"); |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $page = $this->di->get("page"); |
| 75 | 75 | if ($this->currentUser) { |
| 76 | 76 | $sql = "INSERT INTO comment_votes (score, comment_id, user_id) VALUES (?, ?, ?);"; |
| 77 | - $this->db->execute($sql, [1, $id, $this->userId]); |
|
| 77 | + $this->db->execute($sql, [ 1, $id, $this->userId ]); |
|
| 78 | 78 | |
| 79 | 79 | $response = $this->di->get("response"); |
| 80 | 80 | return $response->redirect("post/show/$post_id"); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $page = $this->di->get("page"); |
| 89 | 89 | if ($this->currentUser) { |
| 90 | 90 | $sql = "INSERT INTO comment_votes (score, comment_id, user_id) VALUES (?, ?, ?);"; |
| 91 | - $this->db->execute($sql, [-1, $id, $this->userId]); |
|
| 91 | + $this->db->execute($sql, [-1, $id, $this->userId ]); |
|
| 92 | 92 | |
| 93 | 93 | $response = $this->di->get("response"); |
| 94 | 94 | return $response->redirect("post/show/$post_id"); |
@@ -107,16 +107,16 @@ discard block |
||
| 107 | 107 | $page = $this->di->get("page"); |
| 108 | 108 | //get the status of this answer |
| 109 | 109 | $sql = "select accepted from comments where post_id=? and id=?;"; |
| 110 | - $res = $this->db->executeFetchAll($sql, [$post_id, $id]); |
|
| 110 | + $res = $this->db->executeFetchAll($sql, [ $post_id, $id ]); |
|
| 111 | 111 | |
| 112 | - if ($res[0]->accepted==0) { |
|
| 113 | - $accepted =1; |
|
| 114 | - } elseif ($res[0]->accepted==1) { |
|
| 115 | - $accepted=0; |
|
| 112 | + if ($res[ 0 ]->accepted==0) { |
|
| 113 | + $accepted = 1; |
|
| 114 | + } elseif ($res[ 0 ]->accepted==1) { |
|
| 115 | + $accepted = 0; |
|
| 116 | 116 | } |
| 117 | 117 | //change the status of this answer |
| 118 | 118 | $sql = "update comments set accepted=? where post_id=? and id=?;"; |
| 119 | - $this->db->execute($sql, [$accepted, $post_id, $id]); |
|
| 119 | + $this->db->execute($sql, [ $accepted, $post_id, $id ]); |
|
| 120 | 120 | $response = $this->di->get("response"); |
| 121 | 121 | return $response->redirect("post/show/$post_id"); |
| 122 | 122 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | if ($submit) { |
| 138 | 138 | $comment = $request->getPost("comment") ?: null; |
| 139 | 139 | $sql = "INSERT INTO comments (comment, comment_reply_id, post_id, user_id, answer) VALUES (?, ?, ?, ?, ?);"; |
| 140 | - $this->db->execute($sql, [$comment, $id, $post_id, $this->userId, 0]); |
|
| 140 | + $this->db->execute($sql, [ $comment, $id, $post_id, $this->userId, 0 ]); |
|
| 141 | 141 | return $response->redirect("post/show/$post_id"); |
| 142 | 142 | } |
| 143 | 143 | } |
@@ -85,10 +85,10 @@ |
||
| 85 | 85 | { |
| 86 | 86 | $page = $this->di->get("page"); |
| 87 | 87 | $sql = "Select * from posts where id IN (SELECT post_id from post2tag WHERE tag_name=?);;"; |
| 88 | - $posts = $this->db->executeFetchAll($sql, [$tagname]); |
|
| 88 | + $posts = $this->db->executeFetchAll($sql, [ $tagname ]); |
|
| 89 | 89 | |
| 90 | 90 | $page->add("tag/show", |
| 91 | - ["tagName" => $tagname, |
|
| 91 | + [ "tagName" => $tagname, |
|
| 92 | 92 | "items" => $posts, |
| 93 | 93 | ]); |
| 94 | 94 | |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | // Connect the database |
| 45 | 45 | $this->db = $this->di->get("db"); |
| 46 | 46 | $this->db->connect(); |
| 47 | - if ($this->currentUser !=null) { |
|
| 47 | + if ($this->currentUser!=null) { |
|
| 48 | 48 | $sql = "SELECT id from users where username = ?;"; |
| 49 | - $res = $this->db->executeFetchAll($sql, [$this->currentUser]); |
|
| 50 | - $this->userId = $res[0]->id; |
|
| 49 | + $res = $this->db->executeFetchAll($sql, [ $this->currentUser ]); |
|
| 50 | + $this->userId = $res[ 0 ]->id; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | //Get Posts |
| 77 | 77 | $user_id = $res->id; |
| 78 | 78 | $sql = "SELECT * FROM posts WHERE user_id=?;"; |
| 79 | - $posts = $this->db->executeFetchAll($sql, [$user_id]); |
|
| 79 | + $posts = $this->db->executeFetchAll($sql, [ $user_id ]); |
|
| 80 | 80 | |
| 81 | 81 | // var_dump($posts); |
| 82 | 82 | //Get the answers for the user |
| 83 | 83 | $sql = "SELECT * from comments WHERE user_id=? and answer=1;"; |
| 84 | - $answers = $this->db->executeFetchAll($sql, [$user_id]); |
|
| 84 | + $answers = $this->db->executeFetchAll($sql, [ $user_id ]); |
|
| 85 | 85 | $bonus = 0; |
| 86 | 86 | foreach ($answers as $value) { |
| 87 | 87 | // var_dump($value->accepted); |
@@ -92,19 +92,19 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | // Get the comments for the user |
| 94 | 94 | $sql = "SELECT * from comments WHERE user_id=? and answer=0;"; |
| 95 | - $comments = $this->db->executeFetchAll($sql, [$user_id]); |
|
| 95 | + $comments = $this->db->executeFetchAll($sql, [ $user_id ]); |
|
| 96 | 96 | // var_dump($comments); |
| 97 | - $reputation = count($posts)*3 + (count($answers)- $bonus)*3 + |
|
| 97 | + $reputation = count($posts)*3 + (count($answers) - $bonus)*3 + |
|
| 98 | 98 | + $bonus*100 + count($comments); |
| 99 | 99 | $page->add("user/index", |
| 100 | - ["current_user" => $this->currentUser, |
|
| 100 | + [ "current_user" => $this->currentUser, |
|
| 101 | 101 | "avatar" => $avatar, |
| 102 | 102 | "reputation" => $reputation, |
| 103 | 103 | "items" => $posts, |
| 104 | 104 | "answers" => $answers, |
| 105 | 105 | "comments" => $comments, |
| 106 | 106 | ]); |
| 107 | - return $page->render(["title" => $title, ]); |
|
| 107 | + return $page->render([ "title" => $title, ]); |
|
| 108 | 108 | } |
| 109 | 109 | $response = $this->di->get("response"); |
| 110 | 110 | return $response->redirect("user/login"); |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | //Get Posts |
| 125 | 125 | |
| 126 | 126 | $sql = "SELECT * from posts WHERE user_id=?;"; |
| 127 | - $posts = $this->db->executeFetchAll($sql, [$user_id]); |
|
| 127 | + $posts = $this->db->executeFetchAll($sql, [ $user_id ]); |
|
| 128 | 128 | // var_dump($res->email); |
| 129 | 129 | //Get the answers for the user |
| 130 | 130 | $sql = "SELECT * from comments WHERE user_id=? and answer=1;"; |
| 131 | - $answers = $this->db->executeFetchAll($sql, [$user_id]); |
|
| 131 | + $answers = $this->db->executeFetchAll($sql, [ $user_id ]); |
|
| 132 | 132 | $bonus = 0; |
| 133 | 133 | foreach ($answers as $value) { |
| 134 | 134 | if ($value->accepted==1) { |
@@ -138,19 +138,19 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | // Get the comments for the user |
| 140 | 140 | $sql = "SELECT * from comments WHERE user_id=? and answer=0;"; |
| 141 | - $comments = $this->db->executeFetchAll($sql, [$user_id]); |
|
| 141 | + $comments = $this->db->executeFetchAll($sql, [ $user_id ]); |
|
| 142 | 142 | // var_dump($comments); |
| 143 | - $reputation = count($posts)*3 + (count($answers)- $bonus)*3 + |
|
| 143 | + $reputation = count($posts)*3 + (count($answers) - $bonus)*3 + |
|
| 144 | 144 | + $bonus*100 + count($comments); |
| 145 | 145 | $page->add("user/profile", |
| 146 | - ["user" => $res->username, |
|
| 146 | + [ "user" => $res->username, |
|
| 147 | 147 | "avatar" => $avatar, |
| 148 | 148 | "reputation" => $reputation, |
| 149 | 149 | "posts" => $posts, |
| 150 | 150 | "answers" => $answers, |
| 151 | 151 | "comments" => $comments, |
| 152 | 152 | ]); |
| 153 | - return $page->render(["title" => $title, ]); |
|
| 153 | + return $page->render([ "title" => $title, ]); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -18,20 +18,20 @@ discard block |
||
| 18 | 18 | endif; |
| 19 | 19 | ?> |
| 20 | 20 | <?php foreach ($items as $item) : |
| 21 | - $db = $this->di->get("db"); |
|
| 21 | + $db = $this->di->get("db"); |
|
| 22 | 22 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 23 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 23 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 24 | 24 | $sql = "select * from post2tag where post_id=?;"; |
| 25 | - $posttags = $db->executeFetchAll($sql, [$item->id]); |
|
| 25 | + $posttags = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 26 | 26 | $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;"; |
| 27 | - $answer = $db->executeFetchAll($sql, [$item->id]); |
|
| 27 | + $answer = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 28 | 28 | ?> |
| 29 | 29 | |
| 30 | 30 | <div class=posts> |
| 31 | 31 | <div class=leftpost> |
| 32 | - <div class=countvotes><?= $score[0]->postscore?:0?></div> |
|
| 32 | + <div class=countvotes><?= $score[ 0 ]->postscore ?: 0?></div> |
|
| 33 | 33 | <div class=countvotes>votes</div> |
| 34 | - <div class=countanswers><?= $answer[0]->totalanswer?: 0?></div> |
|
| 34 | + <div class=countanswers><?= $answer[ 0 ]->totalanswer ?: 0?></div> |
|
| 35 | 35 | <div class=countvotes>answers</div> |
| 36 | 36 | </div> |
| 37 | 37 | <div class=rightpost> |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | <table class=table> |
| 60 | 60 | <?php foreach ($answers as $answer): |
| 61 | 61 | if ($answer->accepted==1) { |
| 62 | - $acceptAns ="accepted"; |
|
| 62 | + $acceptAns = "accepted"; |
|
| 63 | 63 | } else { |
| 64 | - $acceptAns ="NoShowAcceptButton"; |
|
| 64 | + $acceptAns = "NoShowAcceptButton"; |
|
| 65 | 65 | }; |
| 66 | 66 | ?> |
| 67 | 67 | <tr> |
@@ -23,21 +23,21 @@ discard block |
||
| 23 | 23 | endif; |
| 24 | 24 | ?> |
| 25 | 25 | <?php foreach ($posts as $item) : |
| 26 | - $db = $this->di->get("db"); |
|
| 26 | + $db = $this->di->get("db"); |
|
| 27 | 27 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 28 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 28 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 29 | 29 | $sql = "select * from post2tag where post_id=?;"; |
| 30 | - $posttags = $db->executeFetchAll($sql, [$item->id]); |
|
| 30 | + $posttags = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 31 | 31 | $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;"; |
| 32 | - $answer = $db->executeFetchAll($sql, [$item->id]); |
|
| 32 | + $answer = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 33 | 33 | |
| 34 | - $urlToShowPost = url("post/show/$item->id");?> |
|
| 34 | + $urlToShowPost = url("post/show/$item->id"); ?> |
|
| 35 | 35 | |
| 36 | 36 | <div class=posts> |
| 37 | 37 | <div class=leftpost> |
| 38 | - <div class=countvotes><?= $score[0]->postscore?:0?></div> |
|
| 38 | + <div class=countvotes><?= $score[ 0 ]->postscore ?: 0?></div> |
|
| 39 | 39 | <div class=countvotes>votes</div> |
| 40 | - <div class=countanswers><?= $answer[0]->totalanswer?: 0?></div> |
|
| 40 | + <div class=countanswers><?= $answer[ 0 ]->totalanswer ?: 0?></div> |
|
| 41 | 41 | <div class=countvotes>answers</div> |
| 42 | 42 | </div> |
| 43 | 43 | <div class=rightpost> |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | <?php foreach ($answers as $answer): |
| 65 | 65 | if ($answer->accepted==1) { |
| 66 | - $acceptAns ="accepted"; |
|
| 66 | + $acceptAns = "accepted"; |
|
| 67 | 67 | } else { |
| 68 | - $acceptAns ="NoShowAcceptButton"; |
|
| 68 | + $acceptAns = "NoShowAcceptButton"; |
|
| 69 | 69 | }; |
| 70 | 70 | // var_dump($acceptAns); |
| 71 | 71 | ?> |
| 72 | 72 | <div class=profileposts> |
| 73 | - <a href="<?= url("post/show/{$answer->post_id}"); ?>"><?= Markdown::defaultTransform($answer->comment);?></a> |
|
| 73 | + <a href="<?= url("post/show/{$answer->post_id}"); ?>"><?= Markdown::defaultTransform($answer->comment); ?></a> |
|
| 74 | 74 | <div class=<?=$acceptAns?>><i class="fa-2x fas fa-check"></i></div> |
| 75 | 75 | </div> |
| 76 | 76 | <?php endforeach; ?> |
@@ -33,21 +33,21 @@ |
||
| 33 | 33 | endif; |
| 34 | 34 | ?> |
| 35 | 35 | <?php foreach ($items as $item) : |
| 36 | - $db = $this->di->get("db"); |
|
| 36 | + $db = $this->di->get("db"); |
|
| 37 | 37 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 38 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 38 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 39 | 39 | $sql = "select * from post2tag where post_id=?;"; |
| 40 | - $posttags = $db->executeFetchAll($sql, [$item->id]); |
|
| 40 | + $posttags = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 41 | 41 | $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;"; |
| 42 | - $answer = $db->executeFetchAll($sql, [$item->id]); |
|
| 42 | + $answer = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 43 | 43 | $urlToShowPost = url("post/show/$item->id"); |
| 44 | 44 | ?> |
| 45 | 45 | |
| 46 | 46 | <div class=posts> |
| 47 | 47 | <div class=leftpost> |
| 48 | - <div class=countvotes><?= $score[0]->postscore?:0?></div> |
|
| 48 | + <div class=countvotes><?= $score[ 0 ]->postscore ?: 0?></div> |
|
| 49 | 49 | <div class=countvotes>votes</div> |
| 50 | - <div class=countanswers><?= $answer[0]->totalanswer?: 0?></div> |
|
| 50 | + <div class=countanswers><?= $answer[ 0 ]->totalanswer ?: 0?></div> |
|
| 51 | 51 | <div class=countvotes>answers</div> |
| 52 | 52 | </div> |
| 53 | 53 | <div class=rightpost> |
@@ -20,13 +20,13 @@ discard block |
||
| 20 | 20 | endif; |
| 21 | 21 | ?> |
| 22 | 22 | <?php foreach ($posts as $item) : |
| 23 | - $db = $this->di->get("db"); |
|
| 23 | + $db = $this->di->get("db"); |
|
| 24 | 24 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 25 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 25 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 26 | 26 | $sql = "select * from post2tag where post_id=?;"; |
| 27 | - $posttags = $db->executeFetchAll($sql, [$item->id]); |
|
| 27 | + $posttags = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 28 | 28 | $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;"; |
| 29 | - $answer = $db->executeFetchAll($sql, [$item->id]); |
|
| 29 | + $answer = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 30 | 30 | // var_dump($answer); |
| 31 | 31 | // if (!$score) { |
| 32 | 32 | // $score = 0; |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | <div class=posts> |
| 38 | 38 | <div class=leftpost> |
| 39 | - <div class=countvotes><?= $score[0]->postscore?: 0 ?></div> |
|
| 39 | + <div class=countvotes><?= $score[ 0 ]->postscore ?: 0 ?></div> |
|
| 40 | 40 | <div class=countvotes>votes</div> |
| 41 | - <div class=countanswers><?= $answer[0]->totalanswer?: 0?></div> |
|
| 41 | + <div class=countanswers><?= $answer[ 0 ]->totalanswer ?: 0?></div> |
|
| 42 | 42 | <div class=countvotes>answers</div> |
| 43 | 43 | </div> |
| 44 | 44 | <div class=rightpost> |