mirror of
https://github.com/friendica/friendica
synced 2025-04-27 18:30:12 +00:00
Merge pull request #11260 from mkljczk/develop
API: add list members editing
This commit is contained in:
commit
c86cc83524
2 changed files with 84 additions and 2 deletions
|
@ -310,6 +310,68 @@ class Group
|
|||
return DBA::delete('group_member', ['gid' => $gid, 'contact-id' => $cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds contacts to a group
|
||||
*
|
||||
* @param int $gid
|
||||
* @param array $contacts
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function addMembers(int $gid, array $contacts)
|
||||
{
|
||||
if (!$gid || !$contacts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// @TODO Backward compatibility with user contacts, remove by version 2022.03
|
||||
$group = DBA::selectFirst('group', ['uid'], ['id' => $gid]);
|
||||
if (empty($group)) {
|
||||
throw new HTTPException\NotFoundException('Group not found.');
|
||||
}
|
||||
|
||||
foreach ($contacts as $cid) {
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $group['uid']);
|
||||
if (empty($cdata['user'])) {
|
||||
throw new HTTPException\NotFoundException('Invalid contact.');
|
||||
}
|
||||
|
||||
DBA::insert('group_member', ['gid' => $gid, 'contact-id' => $cdata['user']], Database::INSERT_IGNORE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes contacts from a group
|
||||
*
|
||||
* @param int $gid
|
||||
* @param array $contacts
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function removeMembers(int $gid, array $contacts)
|
||||
{
|
||||
if (!$gid || !$contacts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// @TODO Backward compatibility with user contacts, remove by version 2022.03
|
||||
$group = DBA::selectFirst('group', ['uid'], ['id' => $gid]);
|
||||
if (empty($group)) {
|
||||
throw new HTTPException\NotFoundException('Group not found.');
|
||||
}
|
||||
|
||||
$contactIds = [];
|
||||
|
||||
foreach ($contacts as $cid) {
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $group['uid']);
|
||||
if (empty($cdata['user'])) {
|
||||
throw new HTTPException\NotFoundException('Invalid contact.');
|
||||
}
|
||||
|
||||
$contactIds[] = $cdata['user'];
|
||||
}
|
||||
|
||||
DBA::delete('group_member', ['gid' => $gid, 'contact-id' => $contactIds]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the combined list of contact ids from a group id list
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue