Skip to content
Snippets Groups Projects
Commit 25352a43 authored by Hana Fathiyah's avatar Hana Fathiyah
Browse files

create something

parent c0e87f56
No related merge requests found
...@@ -17,22 +17,9 @@ class PremiumSongsController ...@@ -17,22 +17,9 @@ class PremiumSongsController
{ {
//data ada //data ada
$user_id = $req->auth ? $req->auth->user_id : -1; $user_id = $req->auth ? $req->auth->user_id : -1;
$page = $req->getQuery("page") ?
($req->getQuery("page") > 0 ? $req->getQuery("page") : SubsciberController::DEFAULT_PAGE)
: SubsciberController::DEFAULT_PAGE;
$limit = $req->getQuery("limit") ? $limit = $req->getQuery("limit") ?
($req->getQuery("limit") > 0 ? $req->getQuery("limit") : SubsciberController::DEFAULT_LIMIT) ($req->getQuery("limit") > 0 ? $req->getQuery("limit") : SubsciberController::DEFAULT_LIMIT)
: SubsciberController::DEFAULT_LIMIT; : SubsciberController::DEFAULT_LIMIT;
$data = SubsciberController::fetchSubscriptions($page, $limit, $user_id, $req->db);
if ($data === false) {
// return $res->json([
// "status"=>"failed",
// "message"=>"fetch operations failed",
// "data"=>[],
// "errors"=>curl_error($ch)
// ]);
return $res->redirect("/", 500);
}
// $data = json_decode($output,true)["data"]; // $data = json_decode($output,true)["data"];
//fetch max page //fetch max page
...@@ -44,17 +31,15 @@ class PremiumSongsController ...@@ -44,17 +31,15 @@ class PremiumSongsController
$headers = [ $headers = [
"X-API-KEY" => $rest_key "X-API-KEY" => $rest_key
]; ];
$output = $fetcher->get("/singers/max-page", $param, $headers); $output = $fetcher->get("/songs", $param, $headers);
$total_page = 1; $total_page = 1;
if ($output) { if ($output) {
$total_page = json_decode($output, true)["data"]; $total_page = json_decode($output, true)["data"];
} }
$data = $output;
return $res->view("Pages/PremiumSongs", [ return $res->view("Pages/PremiumSongs", [
"singers" => $data, "songs" => $data,
"page" => $page,
"limit" => $limit, "limit" => $limit,
"next_page" => $page < $total_page ? $page + 1 : null,
"prev_page" => $page > 1 ? $page - 1 : null,
"auth" => $req->auth, "auth" => $req->auth,
]); ]);
// return $res->json([ // return $res->json([
......
...@@ -31,11 +31,11 @@ $this->layout("Templates/PageTemplate", [ ...@@ -31,11 +31,11 @@ $this->layout("Templates/PageTemplate", [
</thead> </thead>
<tbody> <tbody>
<?php <?php
foreach ($singers as $number => $singer) { foreach ($songs as $number => $song) {
?> ?>
<tr> <tr>
<td><?= (10 * ($page - 1)) + ($number + 1) ?></td> <td><?= (10 * ($page - 1)) + ($number + 1) ?></td>
<td><?= $singer["name"] ?></td> <td><?= $song["title"] ?></td>
<?php if (isset($auth)) { ?> <?php if (isset($auth)) { ?>
<td> <td>
<div> <div>
...@@ -49,12 +49,4 @@ $this->layout("Templates/PageTemplate", [ ...@@ -49,12 +49,4 @@ $this->layout("Templates/PageTemplate", [
} }
?> ?>
</tbody> </tbody>
</table> </table>
\ No newline at end of file
<?php
$this->component("Component/Pagination", [
"page_number" => $page,
"next_page" => isset($next_page) && !is_null($next_page) ? "/premium?page=$next_page&limit=$limit" : null,
"prev_page" => isset($prev_page) && !is_null($prev_page) ? "/premium?page=$prev_page&limit=$limit" : null,
])
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment