Skip to content

Commit

Permalink
マイページから非表示にした動画一覧を確認できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
ue8d committed Nov 20, 2020
1 parent 6fd34cc commit 291ab96
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 3 deletions.
65 changes: 62 additions & 3 deletions function.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,73 @@ function get_user_video_list($userId) {
return $returnVideoList;
}

function hide_video($hiddenvideo): void {

function get_user_hidden_video_list($userId) {
$dbh = get_pdo();
// ビデオ一覧の取得
$videoListSql = 'select * from thumb';
$videoListPrepare = $dbh->prepare($videoListSql);
$videoListPrepare->execute();
$videoListResult = $videoListPrepare->fetchAll(PDO::FETCH_ASSOC);
$videoListResultId = array_column($videoListResult, "id");
$videoListResultVideoName = array_column($videoListResult, "videoName");
$videoListResultVideoPath = array_column($videoListResult, "videoPath");
$videoListResultThumbPath = array_column($videoListResult, "thumbPath");

$dbh = get_pdo();
// 非表示にしたビデオ一覧の取得
$hiddenVideoSql = 'select * from alreadySeenList where userId = :id and flag = true';
$hiddenVideoPrepare = $dbh->prepare($hiddenVideoSql);
$hiddenVideoPrepare->bindValue(':id', $userId, PDO::PARAM_STR);
$hiddenVideoPrepare->execute();
$hiddenVideoResult = $hiddenVideoPrepare->fetchAll(PDO::FETCH_ASSOC);
$hiddenVideoResultThumbId = array_column($hiddenVideoResult, "thumbId");

// リターン用配列の用意
$returnVideoList = array();
// 配列の添え字
$suffix = 0;

for ($i=0; $i < count($videoListResultId); $i++) {
$flag = false;
for ($j=0; $j < count($hiddenVideoResultThumbId); $j++) {
if ($videoListResultId[$i] == $hiddenVideoResultThumbId[$j]) {
$flag = true;
break;
}
}
if ($flag) {
$returnVideoList[$suffix]['id'] = $videoListResultId[$i];
$returnVideoList[$suffix]['videoName'] = $videoListResultVideoName[$i];
$returnVideoList[$suffix]['videoPath'] = $videoListResultVideoPath[$i];
$returnVideoList[$suffix]['thumbPath'] = $videoListResultThumbPath[$i];
$suffix++;
}
}

return $returnVideoList;
}

function hide_video($hiddenVideo): void {
//DB接続
$dbh = get_pdo();
// SQL
$sql = "INSERT INTO alreadySeenList (thumbId,userId,flag) VALUES (:thumbId,:userId,:flag)";
$sql = "INSERT INTO alreadySeenList (thumbId,userId,flag) VALUES (:thumbId,:userId,:flag) ON DUPLICATE KEY UPDATE flag = VALUES (flag);";
$prepare = $dbh->prepare($sql);
$prepare->bindValue(':thumbId', $hiddenvideo, PDO::PARAM_STR);
$prepare->bindValue(':thumbId', $hiddenVideo, PDO::PARAM_STR);
$prepare->bindValue(':userId', $_SESSION["id"], PDO::PARAM_STR);
$prepare->bindValue(':flag', '1', PDO::PARAM_STR);
$prepare->execute();
}

function restore_hidden_video($restoreHiddenVideo): void {
//DB接続
$dbh = get_pdo();
// SQL
$sql = "UPDATE alreadySeenList SET flag = :flag WHERE thumbId = :thumbId AND userId = :userId";
$prepare = $dbh->prepare($sql);
$prepare->bindValue(':thumbId', $restoreHiddenVideo, PDO::PARAM_STR);
$prepare->bindValue(':userId', $_SESSION["id"], PDO::PARAM_STR);
$prepare->bindValue(':flag', '0', PDO::PARAM_STR);
$prepare->execute();
}
60 changes: 60 additions & 0 deletions mypage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
require "function.php";
if (!(isset($_SESSION['id']))) {
header('Location: login.php');
}
# ビデオの非表示取り消し処理
if(isset($_POST['restoreHiddenVideo'])) {
$restoreHiddenVideo = htmlspecialchars($_POST['restoreHiddenVideo']);
restore_hidden_video($restoreHiddenVideo);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>MyPage | ue8d's Videos</title>
<link rel="stylesheet" type="text/css" href="./CSS/index.css">
</head>
<body style="background-color:white">
<!-- ヘッダー読み込み -->
<?php include_once "./header.php" ?>

<div class="main">
<p><h2>ユーザー情報</h2></p>
<p>ユーザー名:<?php echo $_SESSION['userName'] ?></p>
<p>ユーザーランク:<?php echo $msg = ($_SESSION['role'] == 999) ? '管理者' : '一般ユーザー' ?></p>
<p>非表示にしたVOD一覧</p>
<div class="container">
<?php
// ログインユーザー判定
$result = get_user_hidden_video_list($_SESSION['id']);

$id = array_column($result, "id");
$videoName = array_column($result, "videoName");
$videoPath = array_column($result, "videoPath");
$thumbPath = array_column($result, "thumbPath");

for ($i=0; $i < count($id); $i++) {
?>
<div class="item">
<p class="title">
<a href="./02/vod.php?videoPass=<?php echo $videoPath[$i]; ?>&videoName=<?php echo $videoName[$i]; ?>"><?php echo $videoName[$i]; ?><br>
<img src="<?php echo $thumbPath[$i]; ?>" alt="<?php echo $videoName[$i]." サムネ"; ?>"></a>
<?php
echo '<form method="post" action="./mypage.php">';
echo '<input type="hidden" name="restoreHiddenVideo" value="'. $id[$i] .'">';
echo '<input type="submit" value="元に戻す">';
echo '</form>';
echo '</p>';
echo '</div>';
}
echo '</div>';
?>
</div>

<footer class="index">
<p>© All rights reserved by ue8d.</p>
</footer>
</body>
</html>

0 comments on commit 291ab96

Please sign in to comment.