Merge branch 'marijn-nietslecht' into 'master'
Marijn nietslecht See merge request !136
This commit was merged in pull request #140.
This commit is contained in:
41
website/public/API/nietSlecht.php
Normal file
41
website/public/API/nietSlecht.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
require_once ("../queries/connect.php");
|
||||
require_once ("../queries/checkInput.php");
|
||||
|
||||
function getNietSlechtCountForPost(int $postID) : int {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`
|
||||
FROM
|
||||
`niet_slecht`
|
||||
WHERE
|
||||
`postID` = :postID
|
||||
");
|
||||
$stmt->bindParam(":postID", $postID);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
function getNietSlechtUsersForPost(int $postID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`fname`,
|
||||
`lname`,
|
||||
CONCAT(`user`.`fname`, ' ', `user`.`lname`) as `fullname`
|
||||
FROM
|
||||
`user`
|
||||
INNER JOIN
|
||||
`niet_slecht`
|
||||
WHERE
|
||||
`user`.`userID` = `niet_slecht`.`userID` AND
|
||||
`niet_slecht`.`postID` = :postID
|
||||
");
|
||||
$stmt->bindParam(":postID", $postID);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll();
|
||||
foreach ($rows as $row) {
|
||||
print($row["fullname"]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ session_start();
|
||||
require("../../queries/post.php");
|
||||
require("../../queries/connect.php");
|
||||
require("../../queries/checkInput.php");
|
||||
print_r($_POST);
|
||||
if ($_POST['button'] == 'reaction') {
|
||||
if (empty($_POST['newcomment-content'])) {
|
||||
echo 0;
|
||||
} else {
|
||||
@@ -16,3 +18,12 @@ if (empty($_POST['newcomment-content'])) {
|
||||
echo 0;
|
||||
}
|
||||
}
|
||||
} else if ($_POST['button'] == 'nietslecht') {
|
||||
if (makeNietSlecht($_POST["postID"], $_SESSION["userID"])) {
|
||||
echo 1;
|
||||
} else {
|
||||
echo 0;
|
||||
}
|
||||
} else {
|
||||
echo 0;
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
function postComment() {
|
||||
function postComment(buttonValue) {
|
||||
formData = $("#newcommentform").serializeArray();
|
||||
formData.push({name: "button", value: buttonValue});
|
||||
$.post(
|
||||
"API/postComment.php",
|
||||
$("#newcommentform").serialize()
|
||||
formData
|
||||
);
|
||||
|
||||
$("#newcomment").val("");
|
||||
@@ -14,5 +16,3 @@ function postComment() {
|
||||
$('#modal-response').html(data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<style>
|
||||
@import url("styles/profile.css");
|
||||
@import url("styles/post-popup.css");
|
||||
@import url('https://fonts.googleapis.com/css?family=Anton');
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -70,3 +70,8 @@
|
||||
margin: 5px auto;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.nietslecht {
|
||||
font-family: Impact, Anton, sans-serif;
|
||||
text-shadow: -1.5px 0 1px black, 0 1.5px 1px black, 1px 0 1.5px black, 0 -1.5px 1px black;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ function makePost($userID, $groupID, $title, $content) {
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function makeComment($postID, $userID, $content) {
|
||||
function makeComment($postID, $userID, $content) : int {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
INSERT INTO
|
||||
`comment` (
|
||||
@@ -94,4 +94,55 @@ function makeComment($postID, $userID, $content) {
|
||||
$stmt->bindParam(':userID', $userID);
|
||||
$stmt->bindParam(':content', $content);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
function makeNietSlecht(int $postID, int $userID) : int {
|
||||
if (checkNietSlecht($postID, $userID)) {
|
||||
return deleteNietSlecht($postID, $userID);
|
||||
} else {
|
||||
return addNietSlecht($postID, $userID);
|
||||
}
|
||||
}
|
||||
|
||||
function checkNietSlecht(int $postID, int $userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
`niet_slecht`
|
||||
WHERE
|
||||
`userID` = :userID AND
|
||||
`postID` = :postID
|
||||
");
|
||||
$stmt->bindParam(":userID", $userID);
|
||||
$stmt->bindParam(":postID", $postID);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
function addNietSlecht(int $postID, int $userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
INSERT INTO
|
||||
`niet_slecht` (`userID`, `postID`)
|
||||
VALUES (:userID, :postID)
|
||||
");
|
||||
$stmt->bindParam(":userID", $userID);
|
||||
$stmt->bindParam(":postID", $postID);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
function deleteNietSlecht(int $postID, int $userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
DELETE FROM
|
||||
`niet_slecht`
|
||||
WHERE
|
||||
`userID` = :userID AND
|
||||
`postID` = :postID
|
||||
");
|
||||
$stmt->bindParam(":userID", $userID);
|
||||
$stmt->bindParam(":postID", $postID);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
$postID = $_GET['postID'];
|
||||
$post = selectPostById($postID)->fetch(PDO::FETCH_ASSOC);
|
||||
$fullname = $post['fname'] . " " . $post['lname'] . " (" . $post['username'] . ")";
|
||||
session_start();
|
||||
|
||||
echo("
|
||||
<div class='post-header header'>
|
||||
@@ -21,10 +22,20 @@ echo("
|
||||
|
||||
<div class='post-comments'>
|
||||
<div class="commentfield">
|
||||
<form id="newcommentform" action="javascript:postComment();">
|
||||
<form id="newcommentform" onsubmit="return false;">
|
||||
<input type="hidden" id="newcomment-textarea" name="postID" value="<?= $postID ?>">
|
||||
<textarea id="newcomment" name="newcomment-content" placeholder="Laat een reactie achter..."></textarea> <br>
|
||||
<input type="submit" value="Reageer!">
|
||||
<button onclick="postComment('reaction')" name="button" value="reaction">Reageer!</button>
|
||||
<!-- TODO: if/else op "niet slecht." button voor like/unlike-->
|
||||
<button onclick="postComment('nietslecht')" name="button" value="nietslecht">
|
||||
<?php
|
||||
if (checkNietSlecht($postID, $_SESSION["userID"])) {
|
||||
echo 'Vind ik <span class="nietslecht">"Niet slecht."</span>';
|
||||
} else {
|
||||
echo 'Trek <span class="nietslecht">"Niet slecht."</span> terug';
|
||||
}
|
||||
?>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user