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