@@ 20-39 (lines=20) @@ | ||
17 | * @return array |
|
18 | * |
|
19 | */ |
|
20 | public function getAll($pageNum = 1){ |
|
21 | ||
22 | // get pagination object |
|
23 | $pagination = Pagination::pagination("files", "", [], $pageNum); |
|
24 | $offset = $pagination->getOffset(); |
|
25 | $limit = $pagination->perPage; |
|
26 | ||
27 | $database = Database::openConnection(); |
|
28 | $query = "SELECT files.id AS id, files.filename, users.id AS user_id, users.name AS user_name, files.extension AS format, files.hashed_filename, files.date "; |
|
29 | $query .= "FROM users, files "; |
|
30 | $query .= "WHERE users.id = files.user_id "; |
|
31 | $query .= "ORDER BY files.date DESC "; |
|
32 | $query .= "LIMIT $limit OFFSET $offset"; |
|
33 | ||
34 | $database->prepare($query); |
|
35 | $database->execute(); |
|
36 | $files = $database->fetchAllAssociative(); |
|
37 | ||
38 | return array("files" => $files, "pagination" => $pagination); |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * get file by Id. |
@@ 19-37 (lines=19) @@ | ||
16 | * @return array |
|
17 | * |
|
18 | */ |
|
19 | public function getAll($pageNum = 1){ |
|
20 | ||
21 | $pagination = Pagination::pagination("newsfeed", "", [], $pageNum); |
|
22 | $offset = $pagination->getOffset(); |
|
23 | $limit = $pagination->perPage; |
|
24 | ||
25 | $database = Database::openConnection(); |
|
26 | $query = "SELECT newsfeed.id AS id, users.profile_picture, users.id AS user_id, users.name AS user_name, newsfeed.content, newsfeed.date "; |
|
27 | $query .= "FROM users, newsfeed "; |
|
28 | $query .= "WHERE users.id = newsfeed.user_id "; |
|
29 | $query .= "ORDER BY newsfeed.date DESC "; |
|
30 | $query .= "LIMIT $limit OFFSET $offset"; |
|
31 | ||
32 | $database->prepare($query); |
|
33 | $database->execute(); |
|
34 | $newsfeed = $database->fetchAllAssociative(); |
|
35 | ||
36 | return array("newsfeed" => $newsfeed, "pagination" => $pagination); |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * get news feed by Id. |
@@ 20-40 (lines=21) @@ | ||
17 | * @return array Associative array of the posts, and Pagination Object. |
|
18 | * |
|
19 | */ |
|
20 | public function getAll($pageNum = 1){ |
|
21 | ||
22 | $pagination = Pagination::pagination("posts", "", [], $pageNum); |
|
23 | $offset = $pagination->getOffset(); |
|
24 | $limit = $pagination->perPage; |
|
25 | ||
26 | $database = Database::openConnection(); |
|
27 | $query = "SELECT posts.id AS id, users.profile_picture, users.id AS user_id, users.name AS user_name, posts.title, posts.content, posts.date "; |
|
28 | $query .= "FROM users, posts "; |
|
29 | $query .= "WHERE users.id = posts.user_id "; |
|
30 | $query .= "ORDER BY posts.date DESC "; |
|
31 | $query .= "LIMIT $limit OFFSET $offset"; |
|
32 | ||
33 | $database->prepare($query); |
|
34 | $database->execute(); |
|
35 | $posts = $database->fetchAllAssociative(); |
|
36 | ||
37 | $this->appendNumberOfComments($posts, $database); |
|
38 | ||
39 | return array("posts" => $posts, "pagination" => $pagination); |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * append number of comments to the array of posts for each post. |