modified masonry and posts, masonry is now reusable on group pages.

This commit is contained in:
K. Nobel
2017-01-30 15:28:54 +01:00
parent f3df682af5
commit 1acad8e765
7 changed files with 101 additions and 50 deletions

View File

@@ -1,13 +1,17 @@
<?php <?php
if(empty($_POST["usr"])) { if(empty($_POST["usr"]) and empty($_POST["grp"])) {
header('HTTP/1.1 500 Non enough arguments'); header('HTTP/1.1 500 Non enough arguments');
} }
require_once ("../../queries/user.php"); require_once ("../../queries/post.php");
require_once ("../../queries/nicetime.php"); require_once ("../../queries/nicetime.php");
$posts = selectAllUserPosts($_POST["usr"]); if(empty($_POST["usr"])) {
$posts = selectAllPosts(0, $_POST["grp"]);
} else {
$posts = selectAllPosts($_POST["usr"], 0);
}
if(!$posts) { if(!$posts) {
header('HTTP/1.1 500 Query failed'); header('HTTP/1.1 500 Query failed');
@@ -19,6 +23,4 @@ for($i = 0; $i < sizeof($results); $i++) {
$results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]); $results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]);
} }
//$results[0]["niceTime"] = nicetime($results[0]["creationdate"]);
echo json_encode($results); echo json_encode($results);

View File

@@ -3,7 +3,7 @@
session_start(); session_start();
require("../../queries/post.php"); require("../../queries/post.php");
require("../../queries/connect.php"); require_once("../../queries/connect.php");
require("../../queries/checkInput.php"); require("../../queries/checkInput.php");
print_r($_POST); print_r($_POST);
if ($_POST['button'] == 'reaction') { if ($_POST['button'] == 'reaction') {

View File

@@ -90,7 +90,7 @@ function masonry(mode) {
/* /*
* Get the posts from the server. * Get the posts from the server.
*/ */
$.post("API/getPosts.php", { usr : userID }) $.post("API/getPosts.php", { usr : userID, grp : groupID })
.done(function(data) { .done(function(data) {
posts = JSON.parse(data); posts = JSON.parse(data);

View File

@@ -4,7 +4,9 @@ function postComment(buttonValue) {
$.post( $.post(
"API/postComment.php", "API/postComment.php",
formData formData
); ).done(function(data) {
console.log(data);
});
$("#newcomment").val(""); $("#newcomment").val("");

View File

@@ -1,10 +1,11 @@
<?php <?php
require("connect.php"); require_once("connect.php");
function selectGroupByName($name) { function selectGroupByName($name) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT
`group_page`.`groupID`,
`group_page`.`groupID`, `group_page`.`groupID`,
`name`, `name`,
`description`, `description`,

View File

@@ -1,5 +1,51 @@
<?php <?php
require_once("connect.php");
function selectAllPosts($userID, $groupID) {
$stmt = prepareQuery("
SELECT
`post`.`postID`,
`post`.`author`,
`title`,
CASE LENGTH(`post`.`content`) >= 150 AND `post`.`content` NOT LIKE '<img%'
WHEN TRUE THEN
CONCAT(LEFT(`post`.`content`, 150), '...')
WHEN FALSE THEN
`post`.`content`
END
AS `content`,
`post`.`creationdate`,
COUNT(DISTINCT `commentID`) AS `comments`,
COUNT(DISTINCT `niet_slecht`.`postID`) AS `niet_slechts`
FROM
`post`
LEFT JOIN
`niet_slecht`
ON
`post`.`postID` = `niet_slecht`.`postID`
LEFT JOIN
`comment`
ON
`post`.`postID` = `comment`.`postID`
WHERE
`post`.`author` = :userID AND
`groupID` IS NULL OR
`groupID` = :groupID
GROUP BY
`post`.`postID`
ORDER BY
`post`.`creationdate` DESC
");
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
$stmt->bindParam(':groupID', $groupID , PDO::PARAM_INT);
if(!$stmt->execute()) {
return False;
}
return $stmt;
}
function selectPostById($postID) { function selectPostById($postID) {
$stmt = prepareQuery(" $stmt = prepareQuery("
SELECT SELECT

View File

@@ -103,47 +103,47 @@ function selectAllUserGroups($userID) {
return $stmt; return $stmt;
} }
function selectAllUserPosts($userID) { //function selectAllUserPosts($userID) {
$stmt = prepareQuery(" // $stmt = prepareQuery("
SELECT // SELECT
`post`.`postID`, // `post`.`postID`,
`post`.`author`, // `post`.`author`,
`title`, // `title`,
CASE LENGTH(`post`.`content`) >= 150 AND `post`.`content` NOT LIKE '<img%' // CASE LENGTH(`post`.`content`) >= 150 AND `post`.`content` NOT LIKE '<img%'
WHEN TRUE THEN // WHEN TRUE THEN
CONCAT(LEFT(`post`.`content`, 150), '...') // CONCAT(LEFT(`post`.`content`, 150), '...')
WHEN FALSE THEN // WHEN FALSE THEN
`post`.`content` // `post`.`content`
END // END
AS `content`, // AS `content`,
`post`.`creationdate`, // `post`.`creationdate`,
COUNT(`commentID`) AS `comments`, // COUNT(`commentID`) AS `comments`,
COUNT(`niet_slecht`.`postID`) AS `niet_slechts` // COUNT(`niet_slecht`.`postID`) AS `niet_slechts`
FROM // FROM
`post` // `post`
LEFT JOIN // LEFT JOIN
`niet_slecht` // `niet_slecht`
ON // ON
`post`.`postID` = `niet_slecht`.`postID` // `post`.`postID` = `niet_slecht`.`postID`
LEFT JOIN // LEFT JOIN
`comment` // `comment`
ON // ON
`post`.`postID` = `comment`.`postID` // `post`.`postID` = `comment`.`postID`
WHERE // WHERE
`post`.`author` = :userID AND // `post`.`author` = :userID AND
`groupID` IS NULL // `groupID` IS NULL
GROUP BY // GROUP BY
`post`.`postID` // `post`.`postID`
ORDER BY // ORDER BY
`post`.`creationdate` DESC // `post`.`creationdate` DESC
"); // ");
//
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT); // $stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
if(!$stmt->execute()) { // if(!$stmt->execute()) {
return False; // return False;
} // }
return $stmt; // return $stmt;
} //}
function select20UsersFromN($n) { function select20UsersFromN($n) {
$q = prepareQuery(" $q = prepareQuery("