diff --git a/app/controllers/PremiumController.php b/app/controllers/PremiumController.php index 95dcbbc54d90a70386460c65af177ea3db6914a7..633891d80911c7a0d3d6b6420af7dd8c0d58a70b 100644 --- a/app/controllers/PremiumController.php +++ b/app/controllers/PremiumController.php @@ -54,8 +54,29 @@ class PremiumController extends Controller implements ControllerInterface header("Location: /user/login", true, 301); exit; } - $premiumView = $this->view('premium', 'PremiumBookDetailView'); - $premiumView->render(); + try { + switch ($_SERVER['REQUEST_METHOD']) { + case 'GET': + $bookId = (int)$params; + // User + if(isset($_SESSION['username'])){ + $userData = $this->model('UserModel'); + $user = $userData->getUserByUsername($_SESSION['username']); + $username = $user['username']; + $nav = ['username'=>$username]; + }else{ + $nav = ['username'=>null]; + } + $premiumView = $this->view('premium', 'PremiumBookDetailView',array_merge($nav, ['bookId'=>$bookId])); + $premiumView->render(); + break; + default: + throw new RequestException('Method Not Allowed', 405); + } + } catch (Exception $e) { + http_response_code($e->getCode()); + exit; + } } } diff --git a/app/pages/premium/CollectionDetailPage.php b/app/pages/premium/CollectionDetailPage.php index bfad3a94dc46efceaec8329ea908f160bb92f7ce..dd3193b75b3fa8730a22e515e7da838096ef5833 100644 --- a/app/pages/premium/CollectionDetailPage.php +++ b/app/pages/premium/CollectionDetailPage.php @@ -36,10 +36,7 @@ <?php $collectionId = $this->data['collectionId']; $raw_data = file_get_contents("http://host.docker.internal:8040/api/curator-collection/$collectionId"); - echo var_dump($raw_data); - echo `http://host.docker.internal:8040/api/curator-collection/$collectionId`; $data = json_decode($raw_data, true); - echo var_dump($data); $books = $data['books']; foreach (($books) as $index => $book) { @@ -47,7 +44,7 @@ echo "<td>" . $index+1 . "</td>"; echo "<td>" . $book['title'] . "</td>"; echo "<td>" . $book['author'] . "</td>"; - echo '<td><a href="/book/update/' . $book['book_id'] .'">Details</a></td>'; + echo '<td><a href="/premium/book/' . $book['book_id'] .'">Details</a></td>'; echo "</tr>"; } ?> diff --git a/app/pages/premium/PremiumBookDetailPage.php b/app/pages/premium/PremiumBookDetailPage.php index dbcd27552a0727b3ce9ebc2e5fe6c699d9477e88..d8bcf5b5ba0ba15f5d066362a9a841af6d521914 100644 --- a/app/pages/premium/PremiumBookDetailPage.php +++ b/app/pages/premium/PremiumBookDetailPage.php @@ -17,44 +17,21 @@ <!-- Navigation bar --> <?php include(dirname(__DIR__) . '../../components/Navbar.php') ?> <div class="container"> - <?php if(isset($this->data['book_id']) ):?> + <?php if(isset($this->data['bookId']) ):?> <h2>PREMIUM DETAILS</h2> - <div class="details-container"> - <!-- Book Title --> - <h3> <?=$this->data['title']?> </h3> + <?php + $bookId = $this->data['bookId']; + $raw_data = file_get_contents("http://host.docker.internal:8040/api/book-collection/$bookId"); + $data = json_decode($raw_data, true); + $book = $data['book']; - <!-- Author Genre Year--> - <h4> <?=$this->data['author']?></h4> - <h4> <?=$this->data['genre']?></h4> - <h4> <?=$this->data['year']?></h4> - - <!-- Text --> - <p> <?=$this->data['summary']?></p> - - <!-- todo: check ownership --> - <?php - if(isset($this->data['username'])): - if(isset($this->data['own'])): - - $bookIdToCheck = $this->data['book_id']; - $found = false; - - foreach ($this->data['own'] as $ownedBook) { - if (isset($ownedBook['book_id']) && $ownedBook['book_id'] == $bookIdToCheck) { - $found = true; - break; - } - } - if($found): + echo "<h3> Title: ". $book['title'] ."</h3>"; + echo "<h4> Author: ". $book['createdBy'] ."</h4>"; + echo "<h4> Year: ". $book['year'] ."</h4>"; + echo "<h4> Genre:". $book['genre'] ."</h4>"; + echo "<text>". $book['content'] ."</text>"; + echo "<h5>Duration: ". $book["duration"] ."</h5>"; ?> - <audio controls> - <source src="<?= BASE_URL ?>/<?= str_replace('/var/www/html/config/', '', $this->data['audio_path']) ?>" alt ="book-audio" type="audio/mp3"> - Your browser does not support the audio element. - </audio> - <?php endif; ?> - <?php endif; ?> - <?php endif; ?> - </div> <?php else : ?> <h2 class="info">Can't find the book you're looking for!</h2> <?php endif; ?>