3 * @copyright Copyright (C) 2020, Friendica
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;
27 * This class provides information about contact groups based on the "group_member" table.
32 * Returns a list of contacts belonging in a group
38 public static function getById(int $gid)
43 $stmt = DBA::p('SELECT `group_member`.`contact-id`, `contact`.*
45 INNER JOIN `group_member`
46 ON `contact`.`id` = `group_member`.`contact-id`
48 AND `contact`.`uid` = ?
49 AND NOT `contact`.`self`
50 AND NOT `contact`.`deleted`
51 AND NOT `contact`.`blocked`
52 AND NOT `contact`.`pending`
53 ORDER BY `contact`.`name` ASC',
58 if (DBA::isResult($stmt)) {
59 $return = DBA::toArray($stmt);
67 * Returns ungrouped contact count or list for user
69 * Returns either the total number of ungrouped contacts for the given user
70 * id or a paginated list of ungrouped contacts.
76 public static function listUngrouped(int $uid)
86 SELECT DISTINCT(`contact-id`)
88 INNER JOIN `group` ON `group`.`id` = `group_member`.`gid`
89 WHERE `group`.`uid` = %d
90 )", intval($uid), intval($uid));
94 * Remove a contact from all groups
96 * @param integer $contact_id
98 * @return boolean Success
100 public static function removeContact(int $contact_id)
102 return DBA::delete('group_member', ['contact-id' => $contact_id]);