From 56611e64c28c87f1e177e93456d7877df26cfe85 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 16 Dec 2017 15:09:14 +0100 Subject: [PATCH] Get user visibility level --- classes/components/user.php | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/classes/components/user.php b/classes/components/user.php index c4a972a..5ae7136 100644 --- a/classes/components/user.php +++ b/classes/components/user.php @@ -327,6 +327,53 @@ class User{ } + /** + * Get a user page visibility level + * + * @param $id The ID of the user to fetch + * @return The visibility level of the user page + * - -1 : In case of failure (will make the protection level elevated) + * - 0 : The page is private (for user friends) + * - 1 : The page is public (for signed in users) + * - 2 : The page is open (for everyone) + */ + public function getUserVisibilty(int $userID) : int { + + //Perform a request on the database + $tableName = $this->userTable; + $condition = "WHERE ID = ?"; + $condValues = array($userID); + + $requiredFields = array( + "public", + "pageouverte" + ); + + //Perform the request + $result = CS::get()->db->select($tableName, $condition, $condValues, $requiredFields); + + if($result === false){ + return -1; + } + + //Check for a result + if(count($result) == 0){ + return -1; + } + + //Check if the page is public + if($result[0]["public"] == 0) + return 0; + + //Check if the page is open or not + if($result[0]["pageouverte"] == 1) + return 3; //Page open + else + return 2; //Public page + + } + + /** * Crypt user password *