diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 3fc35b8dfe..c3ec88fc91 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -13,6 +13,7 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\FileTag; use Friendica\Model\GContact; +use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Profile; use Friendica\Util\DateTimeFormat; @@ -174,6 +175,38 @@ class Widget ]); } + /** + * Return group membership widget + * + * @param string $baseurl + * @param string $selected + * @return string + * @throws \Exception + */ + public static function groups($baseurl, $selected = '') + { + if (!local_user()) { + return ''; + } + + $options = array_map(function ($group) { + return [ + 'ref' => $group['id'], + 'name' => $group['name'] + ]; + }, Group::getByUserId(local_user())); + + return self::filter( + 'group', + DI::l10n()->t('Groups'), + '', + DI::l10n()->t('Everyone'), + $baseurl, + $options, + $selected + ); + } + /** * Return contact relationship widget * diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 3fc679c53c..563adef74a 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -326,6 +326,12 @@ class Contact extends BaseModule $follow_widget = ''; $networks_widget = ''; $rel_widget = ''; + + if ($contact['uid'] != 0) { + $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id); + } else { + $groups_widget = ''; + } } else { $vcard_widget = ''; $findpeople_widget = Widget::findPeople(); @@ -337,12 +343,7 @@ class Contact extends BaseModule $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets); $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel); - } - - if ($contact['uid'] != 0) { - $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id); - } else { - $groups_widget = null; + $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group); } DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget; @@ -710,6 +711,11 @@ class Contact extends BaseModule break; } + if ($group) { + $sql_extra = " AND EXISTS(SELECT `id` FROM `group_member` WHERE `gid` = ? AND `contact`.`id` = `contact-id`)"; + $sql_values[] = $group; + } + $sql_extra .= Widget::unavailableNetworks(); $total = 0;