mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 04:58:59 +00:00
Can get from the API the list of targets where user can create posts
This commit is contained in:
parent
f8e6aa2d3c
commit
75940b53f3
@ -491,6 +491,29 @@ class PostsController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of targets (pages) where the current user can create
|
||||
* posts
|
||||
*
|
||||
* @url POST /posts/getAvailableTargets
|
||||
*/
|
||||
public function getAvailableTargets() {
|
||||
user_login_required();
|
||||
|
||||
// Get the list of friends of the user where the user
|
||||
// can create posts
|
||||
$friends = components()->friends->getListThatAllowPostsFromUser(userID);
|
||||
|
||||
// Get the list of groups where the user can create posts
|
||||
$groups = components()->groups->getListUserWhereCanCreatePosts(userID);
|
||||
|
||||
//Return result
|
||||
return array(
|
||||
"friends" => $friends,
|
||||
"groups" => $groups
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the visibility level specified in a POST request
|
||||
*
|
||||
|
@ -91,6 +91,32 @@ class GroupsComponent {
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of groups of a user where the users can create
|
||||
* posts
|
||||
*
|
||||
* @param int $userID The ID of the target user
|
||||
* @return array The list of the groups the user can participate to
|
||||
*/
|
||||
public function getListUserWhereCanCreatePosts(int $userID) : array {
|
||||
$list = db()->select(self::GROUPS_MEMBERS_TABLE." m, ".self::GROUPS_LIST_TABLE." g",
|
||||
"WHERE user_id = ?
|
||||
AND m.groups_id = g.id
|
||||
AND (
|
||||
level = ".GroupMember::ADMINISTRATOR." OR
|
||||
level = ".GroupMember::MODERATOR." OR
|
||||
(level = ".GroupMember::MEMBER." AND posts_level = ".GroupInfo::POSTS_LEVEL_ALL_MEMBERS.")
|
||||
)
|
||||
",
|
||||
array($userID),
|
||||
array("g.id"));
|
||||
|
||||
foreach($list as $num => $info)
|
||||
$list[$num] = (int)$info["id"];
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the visibility level of a group
|
||||
*
|
||||
|
@ -76,6 +76,28 @@ class friends {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of friends of a given user that allows him to
|
||||
* create posts on their page
|
||||
*
|
||||
* @param $userID The ID of the target user
|
||||
* @return array The list of friends of a user that allows him
|
||||
* to create posts
|
||||
*/
|
||||
public function getListThatAllowPostsFromUser(int $userID) : array {
|
||||
$list = db()->select(
|
||||
$this->friendsTable,
|
||||
"WHERE autoriser_post_page = 1 AND ID_amis = ?",
|
||||
array($userID),
|
||||
array("ID_personne")
|
||||
);
|
||||
|
||||
foreach($list as $num=>$info)
|
||||
$list[$num] = (int)$info["ID_personne"];
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to a friendship request
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user