3 * @copyright Copyright (C) 2010-2023, 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\Content\Widget;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Contact;
30 * This class provides information about contact circles based on the "group_member" table.
35 * Returns a list of contacts belonging in a circle
41 public static function getById(int $gid): array
46 $networks = Widget::unavailableNetworks();
47 $sql_values = array_merge([$gid, DI::userSession()->getLocalUserId()], $networks);
49 $stmt = DBA::p('SELECT `circle_member`.`contact-id`, `contact`.*
51 INNER JOIN `group_member` AS `circle_member`
52 ON `contact`.`id` = `circle_member`.`contact-id`
54 AND `contact`.`uid` = ?
55 AND NOT `contact`.`self`
56 AND NOT `contact`.`deleted`
57 AND NOT `contact`.`blocked`
58 AND NOT `contact`.`pending`
59 AND NOT `contact`.`network` IN (' . substr(str_repeat('?, ', count($networks)), 0, -2) . ')
60 ORDER BY `contact`.`name` ASC',
64 if (DBA::isResult($stmt)) {
65 $return = DBA::toArray($stmt);
73 * Returns uncircled contact count or list for user
75 * Returns either the total number of uncircled contacts for the given user
76 * id or a paginated list of uncircled contacts.
82 public static function listUncircled(int $uid)
84 $networks = Widget::unavailableNetworks();
85 $query = "`uid` = ? AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `failed`
86 AND NOT `network` IN (" . substr(str_repeat('?, ', count($networks)), 0, -2) . ")
87 AND `id` NOT IN (SELECT DISTINCT(`contact-id`) FROM `group_member` AS `circle_member` INNER JOIN `group` AS `circle` ON `circle`.`id` = `circle_member`.`gid`
88 WHERE `circle`.`uid` = ? AND `contact-id` = `contact`.`id`)";
89 $condition = array_merge([$query], [$uid], $networks, [$uid]);
91 return Contact::selectToArray([], $condition);
95 * Remove a contact from all circles
97 * @param integer $contact_id
99 * @return boolean Success
101 public static function removeContact(int $contact_id)
103 return DBA::delete('group_member', ['contact-id' => $contact_id]);