Skip to content

Commit

Permalink
list videos from db in user dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kuldp18 committed Mar 28, 2024
1 parent 12653fa commit edb5a0f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 73 deletions.
33 changes: 27 additions & 6 deletions css/user_dashboard.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.user_dashboard {
border: 1px solid red;
/* border: 1px solid red; */
min-height: calc(100vh - 70px);
display: flex;
flex-direction: column;
Expand All @@ -13,22 +13,28 @@

.upload__videos {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 2rem;
border: 1px solid yellow;
/* border: 1px solid yellow; */
width: 100%;
}

.video {
border: 1px solid red;
border: 2px solid whitesmoke;
display: flex;
flex-direction: column;
gap: 0.5rem;
padding: 1rem;
padding: 0.5rem;
min-height: 400px;
}

.video__item {
flex-grow: 1;
}

.btn__form {
display: flex;
align-items: center;
gap: 1rem;
}

Expand All @@ -49,6 +55,21 @@
}

.video__views,
.video__ratings {
.video__ratings,
.video__title {
font-size: 1.25rem;
}

.video__title {
line-height: 1.35rem;
}

.subheading--larger {
font-size: 2rem;
}

.video__thumbnail__img {
object-fit: cover;
width: 100%;
height: 100%;
}
11 changes: 11 additions & 0 deletions models/videos.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,14 @@ function is_user_subscribed_to_creator(object $pdo, int $user_id, int $creator_i

return true;
}

// fetch uploaded videos using user id
function fetch_uploaded_videos(object $pdo, int $user_id): array
{
$query = "SELECT * FROM videos WHERE user_id = :user_id ORDER BY created_at DESC";
$stmt = $pdo->prepare($query);
$stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}
123 changes: 56 additions & 67 deletions pages/user_dashboard.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
require_once "../includes/db_handler.inc.php";
require_once "../includes/config_session.inc.php";
require_once "../models/videos.inc.php";
?>
<!DOCTYPE html>
<html lang="en">
Expand All @@ -17,91 +19,78 @@
<body>
<?php include_once('../includes/components/navbar.inc.php') ?>
<?php
// check is user is not logged in
// check if user is not logged in
if (!isset($_SESSION['user_id']) || !isset($_SESSION['user_role'])) {
// if not, redirect to home page
header('Location: ../index.php');
exit();
}
$user_name = $_SESSION['user_username'];
$user_id = $_SESSION['user_id'];

// fetch user uploads
if (isset($user_id)) {
$uploads = fetch_uploaded_videos($pdo, $user_id);
}
?>

<main class="user_dashboard">
<h1 class="heading">Your Dashboard</h1>
<section class="upload">
<h2 class="subheading">Uploaded Videos</h2>
<h2 class="subheading subheading--larger">Your uploads</h2>
<section class="upload__videos">
<article class="video">
<div class="video__left">
<div class="video__thumbnail">
<img src="../uploads/thumbnails/65f56ebd4a58e6.94540096.png" alt="video_thumbnail">
</div>
<div class="video__views">
Views: 5
</div>
<div class="video__ratings">
Ratings: 10
</div>
</div>

<div class="video__right">
<form action="">
<button type="submit" name="edit">Edit</button>
<button type="submit" name="delete">Delete</button>
</form>
</div>

</article>


<article class="video">
<div class="video__left">
<div class="video__thumbnail">
<img src="../uploads/thumbnails/65f56ebd4a58e6.94540096.png" alt="video_thumbnail">
<?php foreach ($uploads as $video) { ?>
<article class="video">
<div class="video__thumbnail video__item">
<?php
$thumbnail = $video['video_thumbnail'] ? "../uploads/thumbnails/" . $video['video_thumbnail'] : "https://placehold.co/1280x720/black/white?text=No+Thumbnail&font=monsterrat";
?>
<img src="<?php echo $thumbnail; ?>" alt="No thumbnail found" class="video__thumbnail__img" width="300" height="200">
</div>
<div class="video__views">
Views: 5
<div class="video__info video__item">
<div class="video__title">
Title: <?php echo $video['video_title']; ?>
</div>
<?php
$video_id = $video['video_id'];
$views = fetch_video_views($pdo, $video_id);
$average_rating = fetch_average_rating($pdo, $video_id);
?>
<div class="video__ratings">
Rating: <?php echo $average_rating; ?>
</div>
<div class="video__views">
Views: <?php echo $views; ?>
</div>
</div>
<div class="video__ratings">
Ratings: 10
</div>
</div>

<div class="video__right">
<form action="">
<button type="submit" name="edit">Edit</button>
<button type="submit" name="delete">Delete</button>
<form action="" class="btn__form video__item">
<button type="submit" name="edit" class="video__btn video__btn--edit">
<i class="fa-solid fa-pen"></i>
</button>
<button type="submit" name="delete" class="video__btn video__btn--delete">
<i class="fa-solid fa-trash"></i>
</button>
</form>
</div>

</article>


<article class="video">
<div class="video__thumbnail">
<img src="../uploads/thumbnails/65f56ebd4a58e6.94540096.png" alt="video_thumbnail">
</div>
<div>
<div class="video__views">
Views: 5
</div>
<div class="video__ratings">
Ratings: 10
</div>
</div>
<form action="" class="btn__form">
<button type="submit" name="edit" class="video__btn video__btn--edit">
<i class="fa-solid fa-pen"></i>
</button>
<button type="submit" name="delete" class="video__btn video__btn--delete">
<i class="fa-solid fa-trash"></i>
</button>
</form>
</article>
</article>
<?php } ?>
</section>
</section>
</main>


<script>
function truncateVideoTitle(titleElement, maxLength) {
let truncatedText = titleElement.textContent.slice(0, maxLength) + "...";
titleElement.textContent = truncatedText;
}

const videoTitles = document.querySelectorAll(".video__title");
videoTitles.forEach((title) => {
if (title.textContent.trim().length > 110) {
truncateVideoTitle(title, 110);
}
});
</script>

</body>

</html>

0 comments on commit edb5a0f

Please sign in to comment.