@@ -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 v_all WHERE find_in_set(?, tags);"; |
| 88 | - $posts = $this->db->executeFetchAll($sql, [$tagname]); |
|
| 88 | + $posts = $this->db->executeFetchAll($sql, [ $tagname ]); |
|
| 89 | 89 | var_dump($posts); |
| 90 | 90 | $page->add("tag/show", |
| 91 | - ["tagName" => $tagname, |
|
| 91 | + [ "tagName" => $tagname, |
|
| 92 | 92 | "items" => $posts, |
| 93 | 93 | ]); |
| 94 | 94 | |
@@ -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> |
@@ -21,19 +21,19 @@ |
||
| 21 | 21 | ?> |
| 22 | 22 | <?php foreach ($posts as $item) : |
| 23 | 23 | $sql = "select * from v_post_votes where post_id=?;"; |
| 24 | - $db = $this->di->get("db"); |
|
| 25 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 24 | + $db = $this->di->get("db"); |
|
| 25 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 26 | 26 | if (!$score) { |
| 27 | 27 | $score = 0; |
| 28 | 28 | } else { |
| 29 | - $score = $score[0]-> postscore; |
|
| 29 | + $score = $score[ 0 ]-> postscore; |
|
| 30 | 30 | }?> |
| 31 | 31 | |
| 32 | 32 | <div class=posts> |
| 33 | 33 | <div class=leftpost> |
| 34 | 34 | <div class=countvotes><?= $score?></div> |
| 35 | 35 | <div class=countvotes>votes</div> |
| 36 | - <div class=countanswers><?= $item->answer?: 0?></div> |
|
| 36 | + <div class=countanswers><?= $item->answer ?: 0?></div> |
|
| 37 | 37 | <div class=countvotes>answers</div> |
| 38 | 38 | </div> |
| 39 | 39 | <div class=rightpost> |