Add contact relationship filter to /contact module
This commit is contained in:
parent
862159c712
commit
e6742af65c
2 changed files with 65 additions and 6 deletions
|
@ -121,17 +121,28 @@ class Widget
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $type
|
* Display a generic filter widget based on a list of options
|
||||||
|
*
|
||||||
|
* The options array must be the following format:
|
||||||
|
* [
|
||||||
|
* [
|
||||||
|
* 'ref' => {filter value},
|
||||||
|
* 'name' => {option name}
|
||||||
|
* ],
|
||||||
|
* ...
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @param string $type The filter query string key
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $desc
|
* @param string $desc
|
||||||
* @param string $all
|
* @param string $all The no filter label
|
||||||
* @param string $baseUrl
|
* @param string $baseUrl The full page request URI
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @param string $selected
|
* @param string $selected The currently selected filter option value
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function filter($type, $title, $desc, $all, $baseUrl, array $options, $selected = null)
|
private static function filter($type, $title, $desc, $all, $baseUrl, array $options, $selected = null)
|
||||||
{
|
{
|
||||||
$queryString = parse_url($baseUrl, PHP_URL_QUERY);
|
$queryString = parse_url($baseUrl, PHP_URL_QUERY);
|
||||||
$queryArray = [];
|
$queryArray = [];
|
||||||
|
@ -160,6 +171,37 @@ class Widget
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return networks widget
|
||||||
|
*
|
||||||
|
* @param string $baseurl baseurl
|
||||||
|
* @param string $selected optional, default empty
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function contactRels($baseurl, $selected = '')
|
||||||
|
{
|
||||||
|
if (!local_user()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
['ref' => 'followers', 'name' => L10n::t('Followers')],
|
||||||
|
['ref' => 'following', 'name' => L10n::t('Following')],
|
||||||
|
['ref' => 'mutuals', 'name' => L10n::t('Mutual friends')],
|
||||||
|
];
|
||||||
|
|
||||||
|
return self::filter(
|
||||||
|
'rel',
|
||||||
|
L10n::t('Relationships'),
|
||||||
|
'',
|
||||||
|
L10n::t('All Contacts'),
|
||||||
|
$baseurl,
|
||||||
|
$options,
|
||||||
|
$selected
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return networks widget
|
* Return networks widget
|
||||||
*
|
*
|
||||||
|
|
|
@ -266,6 +266,7 @@ class Contact extends BaseModule
|
||||||
$a = self::getApp();
|
$a = self::getApp();
|
||||||
|
|
||||||
$nets = defaults($_GET, 'nets', '');
|
$nets = defaults($_GET, 'nets', '');
|
||||||
|
$rel = defaults($_GET, 'rel' , '');
|
||||||
|
|
||||||
if (empty($a->page['aside'])) {
|
if (empty($a->page['aside'])) {
|
||||||
$a->page['aside'] = '';
|
$a->page['aside'] = '';
|
||||||
|
@ -321,6 +322,7 @@ class Contact extends BaseModule
|
||||||
$findpeople_widget = '';
|
$findpeople_widget = '';
|
||||||
$follow_widget = '';
|
$follow_widget = '';
|
||||||
$networks_widget = '';
|
$networks_widget = '';
|
||||||
|
$rel_widget = '';
|
||||||
} else {
|
} else {
|
||||||
$vcard_widget = '';
|
$vcard_widget = '';
|
||||||
$findpeople_widget = Widget::findPeople();
|
$findpeople_widget = Widget::findPeople();
|
||||||
|
@ -331,6 +333,7 @@ class Contact extends BaseModule
|
||||||
}
|
}
|
||||||
|
|
||||||
$networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
|
$networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
|
||||||
|
$rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($contact['uid'] != 0) {
|
if ($contact['uid'] != 0) {
|
||||||
|
@ -339,7 +342,7 @@ class Contact extends BaseModule
|
||||||
$groups_widget = null;
|
$groups_widget = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget;
|
$a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget;
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
|
$tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
|
||||||
$a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
|
$a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
|
||||||
|
@ -678,6 +681,7 @@ class Contact extends BaseModule
|
||||||
|
|
||||||
$search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
|
$search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
|
||||||
$nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , '')));
|
$nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , '')));
|
||||||
|
$rel = Strings::escapeTags(trim(defaults($_GET, 'rel' , '')));
|
||||||
|
|
||||||
$tabs = [
|
$tabs = [
|
||||||
[
|
[
|
||||||
|
@ -747,6 +751,12 @@ class Contact extends BaseModule
|
||||||
$sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
|
$sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($rel) {
|
||||||
|
case 'followers': $sql_extra .= " AND `rel` IN (1, 3)"; break;
|
||||||
|
case 'following': $sql_extra .= " AND `rel` IN (2, 3)"; break;
|
||||||
|
case 'mutuals': $sql_extra .= " AND `rel` = 3"; break;
|
||||||
|
}
|
||||||
|
|
||||||
$sql_extra .= " AND NOT `deleted` ";
|
$sql_extra .= " AND NOT `deleted` ";
|
||||||
|
|
||||||
$sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
|
$sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
|
||||||
|
@ -777,6 +787,13 @@ class Contact extends BaseModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($rel) {
|
||||||
|
case 'followers': $header = L10n::t('Followers'); break;
|
||||||
|
case 'following': $header = L10n::t('Following'); break;
|
||||||
|
case 'mutuals': $header = L10n::t('Mutual friends'); break;
|
||||||
|
default: $header = L10n::t('Contacts');
|
||||||
|
}
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break;
|
case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break;
|
||||||
case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break;
|
case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break;
|
||||||
|
|
Loading…
Reference in a new issue