| @@ 42-66 (lines=25) @@ | ||
| 39 | * |
|
| 40 | * @return array |
|
| 41 | */ |
|
| 42 | public function getAllPosts($sql, $params) |
|
| 43 | { |
|
| 44 | $posts = $this->findAllWhere("$sql", $params); |
|
| 45 | ||
| 46 | return array_map(function ($post) { |
|
| 47 | ||
| 48 | // Get e-mail for Post |
|
| 49 | $user = new User($this->db); |
|
| 50 | $post->img = $user->getGravatar($post->user); |
|
| 51 | ||
| 52 | // Get comments for Post |
|
| 53 | $comment = new Comment($this->db); |
|
| 54 | $post->comments = $comment->getComments("parentId = ?", [$post->id]); |
|
| 55 | ||
| 56 | ||
| 57 | // Get votes for Post |
|
| 58 | $vote = new Vote($this->db); |
|
| 59 | $post->vote = $vote->getVote("parentId = ? AND parentType = ?", [$post->id, "post"]); |
|
| 60 | ||
| 61 | // Get text |
|
| 62 | $post->markdown = $this->getMD($post->text); |
|
| 63 | ||
| 64 | return $post; |
|
| 65 | }, $posts); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * return question/answer, three attributes are set, comments connected to them is an array. |
|
| @@ 73-94 (lines=22) @@ | ||
| 70 | * |
|
| 71 | * @return object |
|
| 72 | */ |
|
| 73 | public function getPost($sql, $params) |
|
| 74 | { |
|
| 75 | $post = $this->findWhere("$sql", $params); |
|
| 76 | ||
| 77 | // Get e-mail for question |
|
| 78 | $user = new User($this->db); |
|
| 79 | $post->img = $user->getGravatar($post->user); |
|
| 80 | ||
| 81 | // Get comments for Post |
|
| 82 | $comment = new Comment($this->db); |
|
| 83 | $post->comments = $comment->getComments("parentId = ?", [$post->id]); |
|
| 84 | ||
| 85 | // Get votes for Post |
|
| 86 | $vote = new Vote($this->db); |
|
| 87 | $post->vote = $vote->getVote("parentId = ? AND parentType = ?", [$post->id, "post"]); |
|
| 88 | ||
| 89 | // Start setting attributes |
|
| 90 | $post->markdown = $this->getMD($post->text); |
|
| 91 | ||
| 92 | ||
| 93 | return $post; |
|
| 94 | } |
|
| 95 | } |
|
| 96 | ||