]> git.mxchange.org Git - friendica.git/commitdiff
Add contact relationship filter to /contact module
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 18 May 2019 15:44:04 +0000 (11:44 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 20 May 2019 18:50:09 +0000 (14:50 -0400)
src/Content/Widget.php
src/Module/Contact.php

index b5f83a803e1e12ccdab0af78c0f7ef0dd4d3feaf..e89245cd2bc40b0c4ed012fc6595159dde61c827 100644 (file)
@@ -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 $desc
-        * @param string $all
-        * @param string $baseUrl
+        * @param string $all The no filter label
+        * @param string $baseUrl The full page request URI
         * @param array  $options
-        * @param string $selected
+        * @param string $selected The currently selected filter option value
         * @return string
         * @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);
                $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
         *
index 4429573ab78ec120385ab83ef6a6ece9f2a88b9f..a7f0176e53e6fe2df4385c51ce22590694b44f19 100644 (file)
@@ -266,6 +266,7 @@ class Contact extends BaseModule
                $a = self::getApp();
 
                $nets = defaults($_GET, 'nets', '');
+               $rel  = defaults($_GET, 'rel' , '');
 
                if (empty($a->page['aside'])) {
                        $a->page['aside'] = '';
@@ -321,6 +322,7 @@ class Contact extends BaseModule
                        $findpeople_widget = '';
                        $follow_widget = '';
                        $networks_widget = '';
+                       $rel_widget = '';
                } else {
                        $vcard_widget = '';
                        $findpeople_widget = Widget::findPeople();
@@ -331,6 +333,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) {
@@ -339,7 +342,7 @@ class Contact extends BaseModule
                        $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');
                $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
@@ -678,6 +681,7 @@ class Contact extends BaseModule
 
                $search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
                $nets   = Strings::escapeTags(trim(defaults($_GET, 'nets'  , '')));
+               $rel    = Strings::escapeTags(trim(defaults($_GET, 'rel'   , '')));
 
                $tabs = [
                        [
@@ -747,6 +751,12 @@ class Contact extends BaseModule
                        $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_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) {
                        case 'blocked':  $header .= ' - ' . L10n::t('Blocked'); break;
                        case 'hidden':   $header .= ' - ' . L10n::t('Hidden'); break;