From 3aae884bb56c26221aee97f649d9cb91a1c6f049 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Fri, 3 Feb 2017 12:12:16 +0100 Subject: [PATCH] Added comments --- website/queries/groupAdmin.php | 2 +- website/queries/nicetime.php | 11 ++- website/queries/post.php | 78 ++++++++++++++++++++- website/queries/private_message.php | 22 +++++- website/queries/user.php | 104 +++++++++++++++++++++++++++- website/views/homeLoginRegister.php | 2 +- 6 files changed, 211 insertions(+), 8 deletions(-) diff --git a/website/queries/groupAdmin.php b/website/queries/groupAdmin.php index 8cefb9b..6240009 100644 --- a/website/queries/groupAdmin.php +++ b/website/queries/groupAdmin.php @@ -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 diff --git a/website/queries/nicetime.php b/website/queries/nicetime.php index e2e509e..3881cc7 100644 --- a/website/queries/nicetime.php +++ b/website/queries/nicetime.php @@ -1,9 +1,16 @@ $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]; } diff --git a/website/queries/post.php b/website/queries/post.php index dc41b49..5cd6354 100644 --- a/website/queries/post.php +++ b/website/queries/post.php @@ -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(" diff --git a/website/queries/private_message.php b/website/queries/private_message.php index f2df887..de18144 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -1,5 +1,10 @@ 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 diff --git a/website/views/homeLoginRegister.php b/website/views/homeLoginRegister.php index 2e00905..95b6c53 100644 --- a/website/views/homeLoginRegister.php +++ b/website/views/homeLoginRegister.php @@ -1,7 +1,7 @@ window.onload=checkLoggedIn();