X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=2203b62162372e482e084e5eb0607a4a41b8720f;hb=0dbf7a2611a7c2471617b614903411876b9f3c06;hp=e790fd4843abd17e88058966edde8ec7c61b91fd;hpb=23ca4f92afc875de44e2663616f33ab6cc4e6d92;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index e790fd4843..2203b62162 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -27,6 +27,66 @@ require_once 'include/text.php'; */ class Contact extends BaseObject { + /** + * @brief Returns a list of contacts belonging in a group + * + * @param int $gid + * @return array + */ + public static function getByGroupId($gid) + { + $return = []; + if (intval($gid)) { + $stmt = dba::p('SELECT `group_member`.`contact-id`, `contact`.* + FROM `contact` + INNER JOIN `group_member` + ON `contact`.`id` = `group_member`.`contact-id` + WHERE `gid` = ? + AND `contact`.`uid` = ? + AND NOT `contact`.`self` + AND NOT `contact`.`blocked` + AND NOT `contact`.`pending` + ORDER BY `contact`.`name` ASC', + $gid, + local_user() + ); + if (DBM::is_result($stmt)) { + $return = dba::inArray($stmt); + } + } + + return $return; + } + + /** + * @brief Returns the count of OStatus contacts in a group + * + * @param int $gid + * @return int + */ + public static function getOStatusCountByGroupId($gid) + { + $return = 0; + if (intval($gid)) { + $contacts = dba::fetch_first('SELECT COUNT(*) AS `count` + FROM `contact` + INNER JOIN `group_member` + ON `contact`.`id` = `group_member`.`contact-id` + WHERE `gid` = ? + AND `contact`.`uid` = ? + AND `contact`.`network` = ? + AND `contact`.`notify` != ""', + $gid, + local_user(), + NETWORK_OSTATUS + ); + $return = $contacts['count']; + } + + return $return; + } + + /** * Creates the self-contact for the provided user id * @@ -36,11 +96,11 @@ class Contact extends BaseObject public static function createSelfFromUserId($uid) { // Only create the entry if it doesn't exist yet - if (dba::exists('contact', ['uid' => intval($uid), 'self'])) { + if (dba::exists('contact', ['uid' => $uid, 'self' => true])) { return true; } - $user = dba::select('user', ['uid', 'username', 'nickname'], ['uid' => intval($uid)], ['limit' => 1]); + $user = dba::select('user', ['uid', 'username', 'nickname'], ['uid' => $uid], ['limit' => 1]); if (!DBM::is_result($user)) { return false; } @@ -545,7 +605,9 @@ class Contact extends BaseObject AND NOT `pending` AND `id` NOT IN ( SELECT DISTINCT(`contact-id`) - FROM `group_member` WHERE `uid` = %d + FROM `group_member` + INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` + WHERE `group`.`uid` = %d ) LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count) );