3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model\Contact;
24 use Friendica\Database\DBA;
25 use Friendica\Model\Contact;
28 * This class provides information about contact groups based on the "group_member" table.
33 * Returns a list of contacts belonging in a group
39 public static function getById(int $gid)
44 $stmt = DBA::p('SELECT `group_member`.`contact-id`, `contact`.*
46 INNER JOIN `group_member`
47 ON `contact`.`id` = `group_member`.`contact-id`
49 AND `contact`.`uid` = ?
50 AND NOT `contact`.`self`
51 AND NOT `contact`.`deleted`
52 AND NOT `contact`.`blocked`
53 AND NOT `contact`.`pending`
54 ORDER BY `contact`.`name` ASC',
59 if (DBA::isResult($stmt)) {
60 $return = DBA::toArray($stmt);
68 * Returns ungrouped contact count or list for user
70 * Returns either the total number of ungrouped contacts for the given user
71 * id or a paginated list of ungrouped contacts.
77 public static function listUngrouped(int $uid)
79 return Contact::selectToArray([], ["`uid` = ? AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `failed`
80 AND `id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` INNER JOIN `group` ON `group`.`id` = `group_member`.`gid`
81 WHERE `group`.`uid` = ?)", $uid, $uid]);
85 * Remove a contact from all groups
87 * @param integer $contact_id
89 * @return boolean Success
91 public static function removeContact(int $contact_id)
93 return DBA::delete('group_member', ['contact-id' => $contact_id]);