Add group membership filter widget in contact list

This commit is contained in:
Hypolite Petovan 2020-01-23 17:49:55 -05:00
parent ed3ac36621
commit 4da90b9378
2 changed files with 45 additions and 6 deletions

View file

@ -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
*

View file

@ -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;