Created User->canCreatePosts method

This commit is contained in:
Pierre 2018-01-06 18:26:02 +01:00
parent e4343b0ef4
commit 5a4918db39
2 changed files with 31 additions and 1 deletions

View File

@ -151,7 +151,7 @@ class userController
//If it is his page, yes by default
userID == $userID ? TRUE :
//Else check friendship status
CS::get()->components->friends->can_post_text(userID, $userID);
CS::get()->components->user->canCreatePosts(userID, $userID);
}
//Return user informations

View File

@ -437,6 +437,36 @@ class User{
}
/**
* Check if a user can create a post on another user page
*
* @param int $userID The ID of the user who could create post
* @param int $targetID The ID of the user who could receive new posts
* @return bool True if the user is allowed to create post / false else
*/
public function canCreatePosts(int $userID, int $targetID){
//If the user is signed out, the response is NO by default
if($userID == 0)
return FALSE;
//If the two user are friends, the response is yes by default
if($userID === $targetID)
return TRUE;
//Check if the user is allowed to access user page
if(!$this->userAllowed($userID, $targetID))
return FALSE;
//Check if the friendship of the users allow them to create posts
if(!CS::get()->components->friends->can_post_text($userID, $targetID))
return FALSE;
//Else the user is allowed
return TRUE;
}
/**
* Check whether a user allow comments on his page or not
*