Added comments

This commit is contained in:
Lars van Hijfte
2017-02-03 12:12:16 +01:00
parent 1fd984cc02
commit 3aae884bb5
6 changed files with 211 additions and 8 deletions

View File

@@ -52,7 +52,7 @@ function updateGroupSettings(int $groupID)
}
/**
* Checks if an user is an admin for a page.
* Checks if a user is an admin for a page.
* @param int $groupID
* @param int $userID
* @return bool

View File

@@ -1,9 +1,16 @@
<?php
/**
* Return a relative dutch and readable text when given a datetime.
* @param $date
* @return string
*/
function nicetime($date) {
if(empty($date)) {
return "No date provided";
}
// Create dutch arrays so it has dutch words.
$single_periods = array("seconde", "minuut", "uur", "dag", "week", "maand", "jaar", "decennium");
$multiple_periods = array("seconden", "minuten", "uur", "dagen", "weken", "maanden", "jaar", "decennia");
$lengths = array("60", "60", "24", "7", "4.35", "12", "10", "0");
@@ -15,7 +22,8 @@ function nicetime($date) {
return "Bad date";
}
if($now > $unix_date) {
// Check if it is in the future or not.
if($now >= $unix_date) {
$difference = $now - $unix_date;
$tense = "geleden";
} else {
@@ -23,6 +31,7 @@ function nicetime($date) {
$tense = "vanaf nu";
}
// Get the nice time.
for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) {
$difference /= $lengths[$i];
}

View File

@@ -2,6 +2,12 @@
require_once("connect.php");
/**
* Select all posts on a user.
* @param $userID
* @param $groupID
* @return bool|PDOStatement
*/
function selectAllPosts($userID, $groupID) {
$stmt = prepareQuery("
SELECT
@@ -46,6 +52,14 @@ function selectAllPosts($userID, $groupID) {
}
/**
* Select $limit posts from $offset from a user or group.
* @param $userID
* @param $groupID
* @param $offset
* @param $limit
* @return bool|PDOStatement
*/
function selectSomePosts($userID, $groupID, $offset, $limit) {
$stmt = prepareQuery("
SELECT
@@ -94,9 +108,13 @@ function selectSomePosts($userID, $groupID, $offset, $limit) {
return False;
}
return $stmt;
}
/**
* Select all the post information from an postID.
* @param $postID
* @return PDOStatement
*/
function selectPostById($postID) {
$stmt = prepareQuery("
SELECT
@@ -122,6 +140,11 @@ function selectPostById($postID) {
return $stmt;
}
/**
* Get all the comments from a post.
* @param $postID
* @return PDOStatement
*/
function selectCommentsByPostId($postID) {
$stmt = prepareQuery("
SELECT
@@ -148,6 +171,13 @@ function selectCommentsByPostId($postID) {
return $stmt;
}
/**
* Insert a post to a group or user
* @param $userID
* @param $groupID
* @param $title
* @param $content
*/
function makePost($userID, $groupID, $title, $content) {
$stmt = prepareQuery("
INSERT INTO
@@ -172,6 +202,13 @@ function makePost($userID, $groupID, $title, $content) {
$stmt->execute();
}
/**
* Insert a comment by a post.
* @param $postID
* @param $userID
* @param $content
* @return int
*/
function makeComment($postID, $userID, $content) : int {
$stmt = prepareQuery("
INSERT INTO
@@ -194,6 +231,12 @@ function makeComment($postID, $userID, $content) : int {
return $stmt->rowCount();
}
/**
* If a post already is niet slechted.
* @param int $postID
* @param int $userID
* @return int
*/
function makeNietSlecht(int $postID, int $userID) : int {
if (checkNietSlecht($postID, $userID)) {
return deleteNietSlecht($postID, $userID);
@@ -202,6 +245,12 @@ function makeNietSlecht(int $postID, int $userID) : int {
}
}
/**
* Toggle a niet slecht of a post.
* @param int $postID
* @param int $userID
* @return int
*/
function checkNietSlecht(int $postID, int $userID) {
$stmt = prepareQuery("
SELECT
@@ -218,6 +267,12 @@ function checkNietSlecht(int $postID, int $userID) {
return $stmt->rowCount();
}
/**
* Add a niet slecht to a post.
* @param int $postID
* @param int $userID
* @return int
*/
function addNietSlecht(int $postID, int $userID) {
$stmt = prepareQuery("
INSERT INTO
@@ -230,6 +285,12 @@ function addNietSlecht(int $postID, int $userID) {
return $stmt->rowCount();
}
/**
* Delete a niet slecht.
* @param int $postID
* @param int $userID
* @return int
*/
function deleteNietSlecht(int $postID, int $userID) {
$stmt = prepareQuery("
DELETE FROM
@@ -244,6 +305,11 @@ function deleteNietSlecht(int $postID, int $userID) {
return $stmt->rowCount();
}
/**
* Delete a post
* @param int $postID
* @param int $userID
*/
function deletePost(int $postID, int $userID) {
if (checkPermissionOnPost($postID, $userID)) {
$stmt = prepareQuery("
@@ -257,6 +323,12 @@ function deletePost(int $postID, int $userID) {
}
}
/**
* Check if a user has premissions to delete a post.
* @param int $postID
* @param int $userID
* @return bool
*/
function checkPermissionOnPost(int $postID, int $userID) : bool {
$getGroupID = prepareQuery("
SELECT
@@ -282,10 +354,10 @@ function checkPermissionOnPost(int $postID, int $userID) : bool {
}
/**
* Returns role of an user.
* Returns role of a user.
* @param int $userID
* @param int $groupID
* @return mixed role of an user.
* @return mixed role of a user.
*/
function getRoleInGroup(int $userID, int $groupID) {
$stmt = prepareQuery("

View File

@@ -1,5 +1,10 @@
<?php
/**
* Get the the last 100 chat messages.
* @param $user2ID
* @return string
*/
function getOldChatMessages($user2ID) {
require_once ("friendship.php");
$user1ID = $_SESSION["userID"];
@@ -36,6 +41,12 @@ function getOldChatMessages($user2ID) {
}
}
/**
* Send a chat message.
* @param $destination
* @param $content
* @return bool
*/
function sendMessage($destination, $content) {
require_once("friendship.php");
if (getFriendshipStatus($destination) == 1) {
@@ -65,6 +76,12 @@ function sendMessage($destination, $content) {
}
}
/**
* Get all the chat messages after an messageID ($lastID).
* @param $lastID
* @param $destination
* @return string
*/
function getNewChatMessages($lastID, $destination) {
require_once("friendship.php");
if (getFriendshipStatus($destination) == 1) {
@@ -96,7 +113,10 @@ function getNewChatMessages($lastID, $destination) {
}
}
/**
* Get of every friend the first unread chat message.
* @return string
*/
function selectAllUnreadChat() {
$stmt = prepareQuery("
SELECT

View File

@@ -2,6 +2,10 @@
require_once ("connect.php");
/**
* This sets the last activity of the session user to now.
* @return bool, true is it ran correctly
*/
function updateLastActivity() {
$stmt = prepareQuery("
UPDATE
@@ -15,6 +19,11 @@ function updateLastActivity() {
return $stmt->execute();
}
/**
* This gets the userID from a username
* @param $username
* @return mixed
*/
function getUserID($username) {
$stmt = prepareQuery("
SELECT
@@ -30,6 +39,11 @@ function getUserID($username) {
return $stmt->fetch()["userID"];
}
/**
* This gets the username from a userID
* @param $userID
* @return mixed
*/
function getUsername($userID) {
$stmt = prepareQuery("
SELECT
@@ -45,6 +59,12 @@ function getUsername($userID) {
return $stmt->fetch()["username"];
}
/**
* This selects the information about the other user and the connection between the two.
* @param $me
* @param $other
* @return bool|mixed
*/
function selectUser($me, $other) {
$stmt = prepareQuery("
SELECT
@@ -107,6 +127,11 @@ function selectUser($me, $other) {
return $stmt->fetch();
}
/**
* Select all the users from a group.
* @param $userID
* @return PDOStatement
*/
function selectAllUserGroups($userID) {
$stmt = prepareQuery("
SELECT
@@ -130,6 +155,11 @@ function selectAllUserGroups($userID) {
return $stmt;
}
/**
* Selects 20 users from a given point in the table, ordered by role and name
* @param $n
* @return PDOStatement
*/
function select20UsersFromN($n) {
$q = prepareQuery("
SELECT
@@ -155,6 +185,12 @@ function select20UsersFromN($n) {
return $q;
}
/**
* Search 20 users from a given point in the table, ordered by role and name
* @param $n
* @param $keyword
* @return PDOStatement
*/
function search20UsersFromN($n, $keyword) {
$q = prepareQuery("
SELECT
@@ -183,6 +219,13 @@ function search20UsersFromN($n, $keyword) {
return $q;
}
/**
* Search 20 users from a given point in the database where the status @param $status
* @param $n
* @param $keyword
* @param $status
* @return PDOStatement
*/
function search20UsersFromNByStatus($n, $keyword, $status) {
$q = prepareQuery("
SELECT
@@ -215,6 +258,14 @@ function search20UsersFromNByStatus($n, $keyword, $status) {
return $q;
}
/**
* Search users from a given point in the database where the status @param $status
* @param $n
* @param $m
* @param $search
* @param $status
* @return PDOStatement
*/
function searchSomeUsersByStatus($n, $m, $search, $status) {
// parentheses not needed in where clause, for clarity as
// role search should override status filter.
@@ -252,6 +303,12 @@ function searchSomeUsersByStatus($n, $m, $search, $status) {
return $q;
}
/**
* Count the users with a name like $search and a $status
* @param $search
* @param $status
* @return PDOStatement
*/
function countSomeUsersByStatus($search, $status) {
$q = prepareQuery("
SELECT
@@ -276,7 +333,12 @@ function countSomeUsersByStatus($search, $status) {
return $q;
}
/**
* Change the user status
* @param $id
* @param $status
* @return PDOStatement
*/
function changeUserStatusByID($id, $status) {
$q = prepareQuery("
UPDATE
@@ -293,6 +355,12 @@ function changeUserStatusByID($id, $status) {
return $q;
}
/**
* Change multiple user statuses by an id array.
* @param $ids
* @param $status
* @return PDOStatement
*/
function changeMultipleUserStatusByID($ids, $status) {
$q = prepareQuery("
UPDATE
@@ -310,6 +378,13 @@ function changeMultipleUserStatusByID($ids, $status) {
return $q;
}
/**
* Change multiple user statuses by an id array.
* This excludes that admins and owners statuses can be changed.
* @param $ids
* @param $status
* @return PDOStatement
*/
function changeMultipleUserStatusByIDAdmin($ids, $status) {
$q = prepareQuery("
UPDATE
@@ -329,6 +404,11 @@ function changeMultipleUserStatusByIDAdmin($ids, $status) {
return $q;
}
/**
* Select a random user that is nog your friend.
* @param $userID
* @return mixed
*/
function selectRandomNotFriendUser($userID) {
$stmt = prepareQuery("
SELECT
@@ -357,6 +437,13 @@ function selectRandomNotFriendUser($userID) {
return $stmt->fetch();
}
/**
* Search users.
* @param $n
* @param $m
* @param $search
* @return string
*/
function searchSomeUsers($n, $m, $search) {
$stmt = prepareQuery("
SELECT
@@ -397,6 +484,11 @@ function searchSomeUsers($n, $m, $search) {
return json_encode($stmt->fetchAll());
}
/**
* Count the users that you get searching for a user with a keyword.
* @param $search
* @return PDOStatement
*/
function countSomeUsers($search) {
$q = prepareQuery("
SELECT
@@ -420,6 +512,11 @@ function countSomeUsers($search) {
return $q;
}
/**
* Get the role of a user by userID.
* @param $userID
* @return mixed
*/
function getRoleByID($userID) {
$stmt = prepareQuery("
SELECT
@@ -435,6 +532,11 @@ function getRoleByID($userID) {
return $stmt->fetch()["role"];
}
/**
* Edit the ban comment.
* @param $userID
* @param $comment
*/
function editBanCommentByID($userID, $comment) {
$stmt = prepareQuery("
UPDATE