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:
Marijn Jansen
2017-01-27 12:22:14 +01:00
7 changed files with 135 additions and 15 deletions

View 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"]);
}
}

View File

@@ -5,6 +5,8 @@ session_start();
require("../../queries/post.php"); require("../../queries/post.php");
require("../../queries/connect.php"); require("../../queries/connect.php");
require("../../queries/checkInput.php"); require("../../queries/checkInput.php");
print_r($_POST);
if ($_POST['button'] == 'reaction') {
if (empty($_POST['newcomment-content'])) { if (empty($_POST['newcomment-content'])) {
echo 0; echo 0;
} else { } else {
@@ -16,3 +18,12 @@ if (empty($_POST['newcomment-content'])) {
echo 0; echo 0;
} }
} }
} else if ($_POST['button'] == 'nietslecht') {
if (makeNietSlecht($_POST["postID"], $_SESSION["userID"])) {
echo 1;
} else {
echo 0;
}
} else {
echo 0;
}

View File

@@ -1,7 +1,9 @@
function postComment() { function postComment(buttonValue) {
formData = $("#newcommentform").serializeArray();
formData.push({name: "button", value: buttonValue});
$.post( $.post(
"API/postComment.php", "API/postComment.php",
$("#newcommentform").serialize() formData
); );
$("#newcomment").val(""); $("#newcomment").val("");
@@ -14,5 +16,3 @@ function postComment() {
$('#modal-response').html(data); $('#modal-response').html(data);
}); });
} }

View File

@@ -8,6 +8,7 @@
<style> <style>
@import url("styles/profile.css"); @import url("styles/profile.css");
@import url("styles/post-popup.css"); @import url("styles/post-popup.css");
@import url('https://fonts.googleapis.com/css?family=Anton');
</style> </style>
</head> </head>
<body> <body>

View File

@@ -70,3 +70,8 @@
margin: 5px auto; margin: 5px auto;
width: 95%; 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;
}

View File

@@ -75,7 +75,7 @@ function makePost($userID, $groupID, $title, $content) {
$stmt->execute(); $stmt->execute();
} }
function makeComment($postID, $userID, $content) { function makeComment($postID, $userID, $content) : int {
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
INSERT INTO INSERT INTO
`comment` ( `comment` (
@@ -94,4 +94,55 @@ function makeComment($postID, $userID, $content) {
$stmt->bindParam(':userID', $userID); $stmt->bindParam(':userID', $userID);
$stmt->bindParam(':content', $content); $stmt->bindParam(':content', $content);
$stmt->execute(); $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();
} }

View File

@@ -2,6 +2,7 @@
$postID = $_GET['postID']; $postID = $_GET['postID'];
$post = selectPostById($postID)->fetch(PDO::FETCH_ASSOC); $post = selectPostById($postID)->fetch(PDO::FETCH_ASSOC);
$fullname = $post['fname'] . " " . $post['lname'] . " (" . $post['username'] . ")"; $fullname = $post['fname'] . " " . $post['lname'] . " (" . $post['username'] . ")";
session_start();
echo(" echo("
<div class='post-header header'> <div class='post-header header'>
@@ -21,10 +22,20 @@ echo("
<div class='post-comments'> <div class='post-comments'>
<div class="commentfield"> <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 ?>"> <input type="hidden" id="newcomment-textarea" name="postID" value="<?= $postID ?>">
<textarea id="newcomment" name="newcomment-content" placeholder="Laat een reactie achter..."></textarea> <br> <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> </form>
</div> </div>