Skip to content
Snippets Groups Projects
Commit cfa3a7db authored by Rava Maulana's avatar Rava Maulana
Browse files
parents d34cf7e7 4141c164
No related merge requests found
Pipeline #59321 failed with stages
Showing
with 311 additions and 97 deletions
......@@ -15,6 +15,6 @@
</div>
<?php else : ?>
<h5>
no results found.
you don't have any playlist.
</h5>
<?php endif;?>
\ No newline at end of file
......@@ -7,6 +7,8 @@
<link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/globals.css">
<!-- Page-specific CSS -->
<link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/library/library.css">
<script type="module" src="<?= BASE_URL ?>/javascript/library/library.js" defer> </script>
<title>Playlist</title>
</head>
<body>
......@@ -15,7 +17,7 @@
<main>
<div class="playlist-container">
<div class="playlist-container" data-id="<?=$_GET["playlist_id"]?>">
<?php include(dirname(__DIR__) . "/playlist/playlist_content.php")?>
</div>
</main>
......
<link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/library/library.css">
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
<?php if (!empty($this->data)): ?>
<div class="user-playlist">
......@@ -10,6 +11,7 @@
<div class="info">
<div class="sh5"><?=$podcast['title']?> </div>
</div>
<i class='bx bx-trash' data-id="<?=$podcast["id_podcast"]?>"></i>
</div>
<?php endforeach; ?>
</div>
......@@ -17,4 +19,6 @@
<h5>
your playlist is empty.
</h5>
<?php endif;?>
\ No newline at end of file
<?php endif;?>
<script type="module" src="<?= BASE_URL ?>/javascript/library/library.js" defer> </script>
......@@ -7,7 +7,7 @@
<link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/globals.css">
<link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/podcast/style.css">
<script type="text/javascript" src="<?= BASE_URL ?>/javascript/podcast/script.js" defer>
<script type="module" src="<?= BASE_URL ?>/javascript/podcast/script.js" defer>
</script>
<title>Main Dashboard</title>
</head>
......@@ -38,11 +38,13 @@
<p>Add To Library</p>
</button>
<ul id="library-choices" class="hidden">
<ul id="library-choices" class="hidden" data-id-podcast="<?=$this->data["podcast"]->id_podcast ?>">
<?php foreach ($this->data["libraries"] as $library) : ?>
<!-- Ini sekarang pake li tapi ntar kalo mau diganti jadi button atau a bisa juga -->
<li>
<p class="b3"><?= $library ?></p>
<p class="b3 playlist"
data-id="<?= $library->id_playlist?>">
<?= $library->title ?></p>
</li>
<?php endforeach; ?>
</ul>
......
......@@ -5,7 +5,6 @@ class GetLibraryController
public function call()
{
require_once __DIR__ . "/../../views/library/library_view.php";
require_once __DIR__ . "/../../models/playlist.php";
$data = [];
session_start();
......@@ -22,7 +21,7 @@ class GetLibraryController
$view = new LibraryView($data);
$view->render();
}else{
header("Location: ");
header("Location: " . BASE_URL . "/login");
}
}
......
......@@ -10,7 +10,8 @@ class GetLoginController
if(isset($_SESSION['user_id'])){
header("Location: http://localhost:8080/public/home?user_id=" . $_SESSION['user_id']);
header("Location: " . BASE_URL . "/home?user_id=" . $_SESSION["user_id"]);
}else{
$data = [];
$view = new LoginView($data);
......
......@@ -4,8 +4,7 @@ class PostLoginController
{
public function call()
{
require_once __DIR__ . "/../../views/login/login.php";
require_once __DIR__ . "/../../models/user.php";
// require_once __DIR__ . "/../../views/login/login.php";
session_start();
if(isset($_POST['username']) && isset($_POST['password'])){
......@@ -15,7 +14,7 @@ class PostLoginController
$model = new UserModel();
try{
$user = $model->getUser($_POST['username']);
$user = $model->getUser($username);
$user = json_decode(json_encode($user), true);
if(!$user){
......
<?php
class PostPlaylistController
{
public function call()
{
session_start();
if(!isset($_SESSION["user_id"])){
header("Location: " . BASE_URL . "/login");
return;
}
$idPodcast = "";
$idPlaylist = "";
if(isset($_POST["id_playlist"]) && isset($_POST["id_podcast"])){
$idPlaylist = $_POST["id_playlist"];
$idPodcast = $_POST["id_podcast"];
}
$model = new PlaylistModel();
try{
$model->removePodcastFromPlaylist($idPodcast, $idPlaylist);
http_response_code(201);
exit;
}catch(PDOException $e){
$e->getMessage();
http_response_code(200);
exit;
}
}
}
......@@ -4,6 +4,7 @@ class GetPodcastPageController
{
public function call()
{
session_start();
if (!isset($_SESSION["user_id"])) {
http_response_code(403);
......@@ -24,14 +25,17 @@ class GetPodcastPageController
$podcastModel = new PodcastModel();
$episodeModel = new EpisodeModel();
$playlistModel = new PlaylistModel();
$podcast = $podcastModel->getById($idPodcast);
$episodes = $episodeModel->getByPodcastId($idPodcast);
$playlists = $playlistModel->getUserPlaylist($_SESSION["user_id"]);
$data = [
"podcast" => $podcast,
"episodes" => $episodes,
"libraries" => ["Contoh Library 1", "Contoh Library 2", "Contoh Library 3"]
"libraries" => $playlists,
];
$view = new PodcastPageView($data);
......
<?php
class PostPodcastPageController
{
public function call()
{
session_start();
if(!isset($_SESSION["user_id"])){
header("Location: " . BASE_URL . "/login");
return;
}
$idPodcast = "";
$idPlaylist = "";
if(isset($_POST["id_playlist"]) && isset($_POST["id_podcast"])){
$idPlaylist = $_POST["id_playlist"];
$idPodcast = $_POST["id_podcast"];
}
$model = new PlaylistModel();
try{
$model->addPodcastToPlaylist($idPlaylist, $idPodcast);
http_response_code(201);
exit;
}catch(PDOException $e){
// duplicate entries, violate integrity constraint (SQL code 23000)
if($e->getCode() === 23000){
http_response_code(203);
}else{ // other type of error causing failure
http_response_code(200);
};
exit;
}
}
}
......@@ -4,6 +4,8 @@ class GetSignupController
{
public function call()
{
session_start();
if(!isset($_SESSION['user_id'])){
require_once __DIR__ . "/../../views/signup/signup.php";
......@@ -11,7 +13,7 @@ class GetSignupController
$view = new SignupView($data);
$view->render();
}else{
header("Location: " . BASE_URL . "/home");
header("Location: " . BASE_URL . "/home?user_id=" . $_SESSION["user_id"]);
}
}
......
......@@ -5,7 +5,6 @@ class PostSignupController
public function call()
{
require_once __DIR__ . "/../../views/signup/signup.php";
require_once __DIR__ . "/../../models/user.php";
session_start();
if(!isset($_SESSION['user_id'])){
......
......@@ -29,6 +29,8 @@ class App
$router->get("public/podcast", new GetPodcastPageController());
$router->post("public/episode/play", new PostPlayEpisodeController());
$router->post("public/podcast", new PostPodcastPageController());
$router->post("public/logout", new LogoutController());
......@@ -40,6 +42,7 @@ class App
$router->post("public/signup", new PostSignupController());
$router->get("public/library", new GetLibraryController());
$router->get("public/playlist", new GetPlaylistController());
$router->post("public/playlist", new PostPlaylistController());
$router->directRequest($url);
}
......
......@@ -23,6 +23,8 @@ require_once __DIR__ . "/controllers/dashboard/delete_podcast.php";
require_once __DIR__ . "/controllers/podcast/get_page.php";
require_once __DIR__ . "/controllers/episode/post_play_episode.php";
require_once __DIR__ . "/controllers/podcast/post_page.php";
require_once __DIR__ . "/controllers/logout/logout.php";
......@@ -32,6 +34,7 @@ require_once __DIR__ . "/controllers/login/post_login.php";
require_once __DIR__ . "/controllers/library/get_library.php";
require_once __DIR__ . "/controllers/playlist/get_playlist.php";
require_once __DIR__ . "/controllers/playlist/post_playlist.php";
require_once __DIR__ . "/controllers/library/get_library.php";
require_once __DIR__ . "/controllers/signup/get_signup.php";
require_once __DIR__ . "/controllers/signup/post_signup.php";
......@@ -40,3 +43,4 @@ require_once __DIR__ . "/controllers/search/get_search.php";
require_once __DIR__ . "/models/podcast.php";
require_once __DIR__ . "/models/episode.php";
require_once __DIR__ . "/models/user.php";
require_once __DIR__ . "/models/playlist.php";
......@@ -37,4 +37,61 @@ class PlaylistModel
return $playlistPodcast;
}
public function addPlaylist($id_user, $title, $id_playlist)
{
$query = "
INSERT INTO playlist (id_playlist, title, id_user)
VALUES(:id_playlist, :title, :id_user)
";
$this->db->query($query);
$this->db->bind("id_user", $id_user);
$this->db->bind("title", $title);
$this->db->bind("id_playlist", $id_playlist);
$this->db->execute();
}
public function addPodcastToPlaylist($id_playlist, $id_podcast)
{
$query = "
INSERT INTO podcast_x_playlist (id_playlist, id_podcast)
VALUES(:id_playlist, :id_podcast)
";
$this->db->query($query);
$this->db->bind("id_playlist", $id_playlist);
$this->db->bind("id_podcast", $id_podcast);
$this->db->execute();
}
public function deletePlaylist($id_playlist)
{
$query = "
DELETE FROM playlist
WHERE id_playlist = :id_playlist
";
$this->db->query($query);
$this->db->bind("id_playlist", $id_playlist);
$this->db->execute();
}
public function removePodcastFromPlaylist($id_podcast, $id_playlist)
{
$query = "
DELETE FROM podcast_x_playlist
WHERE id_playlist = :id_playlist AND id_podcast = :id_podcast
";
$this->db->query($query);
$this->db->bind("id_playlist", $id_playlist);
$this->db->bind("id_podcast", $id_podcast);
$this->db->execute();
}
}
......@@ -11,94 +11,85 @@ class PodcastModel
public function getAllPodcast($keyword, $genre, $eps, $sort, $isAsc)
{
$eps_new = "";
$epsMin = "";
$epsMax = "";
switch ($eps) {
case "eps-cat-1":
$eps_new = "COUNT(e) < 20";
case "Less than 20 episodes":
$epsMin = "-1";
$epsMax = "20";
break;
case "eps-cat-2":
$eps_new = "COUNT(e) BETWEEN 20 AND 50";
case "20-50 episodes":
$epsMin = "20";
$epsMax = "50";
break;
case "eps-cat-3":
$eps_new = "COUNT(e) BETWEEN 50 AND 100";
case "50-100 episodes":
$epsMin = "50";
$epsMax = "100";
break;
case "eps-cat-4":
$eps_new = "COUNT(e) > 100";
case "More than 100 episodes":
$epsMin = "100";
$epsMax = "999999999";
break;
default:
$eps_new = "COUNT(e) > -1";
$epsMin = "-1";
$epsMax = "999999999";
break;
};
$sort_new = "";
//sort
switch ($sort) {
case "alphabet":
$sort_new = "p.title";
break;
case "sort":
$sort_new = "p.id";
break;
default:
$sort_new = "p.description";
break;
};
$isAsc_new = "";
//isAsc
switch ($isAsc) {
case "true":
$isAsc_new = "ASC";
case "alphabetical":
$query =
"SELECT p.title, p.category, p.url_thumbnail, p.description, u.name
FROM podcast AS p
NATURAL JOIN user AS u
LEFT JOIN episode AS e ON p.id_podcast = e.id_podcast
WHERE (p.title LIKE :search_value
OR u.name LIKE :search_value)
AND p.category LIKE :genre
GROUP BY p.id_podcast
HAVING COUNT(e.id_episode) BETWEEN :epsMin AND :epsMax
ORDER BY p.title
";
break;
case "false":
$isAsc_new = "DESC";
case "date joined":
$query =
"SELECT p.title, p.category, p.url_thumbnail, p.description, u.name
FROM podcast AS p
NATURAL JOIN user AS u
LEFT JOIN episode AS e ON p.id_podcast = e.id_podcast
WHERE (p.title LIKE :search_value
OR u.name LIKE :search_value)
AND p.category LIKE :genre
GROUP BY p.id_podcast
HAVING COUNT(e.id_episode) BETWEEN :epsMin AND :epsMax
ORDER BY p.id_podcast
";
break;
default:
$isAsc_new = "ASC";
$query =
"SELECT p.title, p.category, p.url_thumbnail, p.description, u.name
FROM podcast AS p
NATURAL JOIN user AS u
LEFT JOIN episode e ON e.id_podcast=p.id_podcast
WHERE (p.title LIKE :search_value
OR u.name LIKE :search_value)
AND p.category LIKE :genre
GROUP BY p.id_podcast
HAVING COUNT(e.id_episode) BETWEEN :epsMin AND :epsMax
ORDER BY p.description
";
break;
};
$query =
"SELECT p.title, p.category, p.url_thumbnail, p.description, u.name
FROM podcast AS p
NATURAL JOIN user AS u
INNER JOIN episode AS e ON p.id_podcast = e.id_podcast
WHERE (p.title LIKE :search_value
OR u.name LIKE :search_value)
GROUP BY p.title
HAVING :epsCount
ORDER BY :sort
";
$queryByGenre =
"SELECT p.title, p.category, p.url_thumbnail, p.description, u.name
FROM podcast p
NATURAL JOIN user u
INNER JOIN episode e ON p.id_podcast = e.id_podcast
WHERE (p.title LIKE :search_value
OR u.name LIKE :search_value
AND p.category = :genre)
GROUP BY p.title
HAVING :epsCount
ORDER BY :sort
";
$this->db->query($query);
if ($genre == "") {
$this->db->query($query);
} else {
$this->db->query($queryByGenre);
}
$this->db->bind("search_value", '%' . $keyword . '%');
$this->db->bind("sort", $sort_new . $isAsc_new);
$this->db->bind("epsCount", $eps_new);
$this->db->bind("genre", $genre);
$this->db->bind("epsMin", $epsMin);
$this->db->bind("epsMax", $epsMax);
$this->db->bind("genre", $genre==""?'%':$genre);
$podcasts = $this->db->fetchAll();
// var_dump($keyword);
// var_dump($genre);
// var_dump($eps);
// var_dump($sort);
// var_dump($isAsc);
return $podcasts;
}
......@@ -148,18 +139,18 @@ class PodcastModel
return $podcasts;
}
public function getPodcast($id_podcast) {
$query = "
SELECT * FROM podcast
WHERE id_podcast = :id_podcast
";
// public function getPodcast($id_podcast) {
// $query = "
// SELECT * FROM podcast
// WHERE id_podcast = :id_podcast
// ";
$this->db->query($query);
$this->db->bind("id_podcast", $id_podcast);
$podcast = $this->db->fetchAll();
// $this->db->query($query);
// $this->db->bind("id_podcast", $id_podcast);
// $podcast = $this->db->fetchAll();
return $podcast;
}
// return $podcast;
// }
public function getById($idPodcast)
{
......
"use strict"
import { showErrorToast, showSuccessToast } from "../toast.mjs";
document.addEventListener("DOMContentLoaded", (e) =>{
const trashEl = document.querySelectorAll('.bx-trash');
const playlistContainer = document.querySelector('.playlist-container')
if(trashEl.length !== 0){
trashEl.forEach(function(trash){
trash.addEventListener("click", (e) => {
e.preventDefault();
const data = new FormData();
const xhr = new XMLHttpRequest();
data.append("id_podcast", trash.dataset.id);
data.append("id_playlist", playlistContainer.dataset.id);
xhr.open("POST", "/public/playlist", true);
xhr.onload = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 201) {
showSuccessToast("Podcast berhasil dihapus dari playlist!");
}else{ // status code 200, some error
showErrorToast("Podcast gagal dihapus dari playlist!");
}
}
}
xhr.send(data);
})
})
}
});
\ No newline at end of file
"use strict";
import { showSuccessToast, showErrorToast, showInformationToast } from "../toast.mjs";
// Get DOM elements
const playButtonsEl = document.querySelectorAll(".play-button");
const addLibraryButtonEl = document.getElementById("add-library-btn");
const libraryChoicesEl = document.getElementById("library-choices");
const overlayEl = document.getElementById("overlay-library");
const addLibraryButtonEl = document.getElementById("add-library-btn")
const libraryChoicesEl = document.getElementById("library-choices")
const overlayEl = document.getElementById("overlay-library")
const playlists = document.querySelectorAll(".playlist");
// Handle play episode
Array.from(playButtonsEl).forEach((el) => {
......@@ -42,3 +45,35 @@ overlayEl.addEventListener("click", (e) => {
libraryChoicesEl.classList.toggle("hidden");
overlayEl.classList.toggle("hidden");
});
if(playlists.length !== 0){
playlists.forEach(function(playlist){
playlist.addEventListener("click", (e) => {
e.preventDefault();
const data = new FormData();
const xhr = new XMLHttpRequest();
xhr.open("POST", "/public/podcast", true);
data.append("id_playlist", playlist.dataset.id);
data.append("id_podcast", libraryChoicesEl.dataset.idPodcast);
xhr.onload = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 201) {
showSuccessToast("Podcast berhasil ditambahkan ke playlist!");
}else if(xhr.status === 203){
showInformationToast("Podcast sudah ada dalam playlist!")
}
else{ // status code 200, some other error
showErrorToast("Podcast gagal ditambahkan ke playlist!");
}
}
}
xhr.send(data);
})
})
}
\ 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