]> git.mxchange.org Git - friendica.git/commitdiff
Filter for account type for contacts
authorMichael <heluecht@pirati.ca>
Fri, 9 Oct 2020 19:08:50 +0000 (19:08 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 9 Oct 2020 19:08:50 +0000 (19:08 +0000)
mod/network.php
src/Content/Widget.php
src/Model/Contact/Relation.php
src/Model/User.php
src/Module/Contact.php
src/Module/Contact/Contacts.php
src/Module/Conversation/Community.php

index 4dfd39cd900b80419cae5da21823557834ad34c1..57e4a2ada25a36b52facd04aca883744001461ed 100644 (file)
@@ -300,23 +300,7 @@ function network_content(App $a, $update = 0, $parent = 0)
                $o = '';
        }
 
-       switch ($a->argv[1] ?? '') {
-               case 'person':
-                       $account = User::ACCOUNT_TYPE_PERSON;
-                       break;
-               case 'organisation':
-                       $account = User::ACCOUNT_TYPE_ORGANISATION;
-                       break;
-               case 'news':
-                       $account = User::ACCOUNT_TYPE_NEWS;
-                       break;
-               case 'community':
-                       $account = User::ACCOUNT_TYPE_COMMUNITY;
-                       break;
-               default:
-                       $account = null;
-               break;
-       }
+       $account = User::getAccountTypeByString($a->argv[1] ?? '');
 
        if (!empty($_GET['file'])) {
                $o .= networkFlatView($a, $update, $account);
index 3e5af2251f1cfc88db5dbe03b4de9e5edaf3a972..0078e82a53a05ad63460fe045ecae078a29b7e58 100644 (file)
@@ -24,17 +24,13 @@ namespace Friendica\Content;
 use Friendica\Core\Addon;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\Database\DBA;
 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;
-use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
 class Widget
@@ -526,8 +522,30 @@ class Widget
                return $o;
        }
 
+       /**
+        * Display the account types sidebar
+        * The account type value is added as a parameter to the url
+        * 
+        * @param string $base        Basepath
+        * @param int    $accounttype Acount type
+        * @return string
+        */
+       public static function accounttypes(string $base, $accounttype)
+       {
+               $accounts = [
+                       ['ref' => 'person', 'name' => DI::l10n()->t('Persons')],
+                       ['ref' => 'organisation', 'name' => DI::l10n()->t('Organisations')],
+                       ['ref' => 'news', 'name' => DI::l10n()->t('News')],
+                       ['ref' => 'community', 'name' => DI::l10n()->t('Forums')],
+               ];
+
+               return self::filter('accounttype', DI::l10n()->t('Accounts'), '',
+                       DI::l10n()->t('All'), $base, $accounts, $accounttype);
+       }
+
        /**
         * Display the accounts sidebar
+        * The account type is added to the path
         *
         * @param string $base        Basepath
         * @param string $accounttype Acount type (person, organisation, news, community)
index e6926df85b52123f5baf1375ab696987b15488fa..3c95973238e1e9d43aae474927db3c2e35519529 100644 (file)
@@ -469,7 +469,7 @@ class Relation
                );
 
                return DI::dba()->selectToArray('contact', [], $condition,
-                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
+                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
                );
        }
 
@@ -485,8 +485,8 @@ class Relation
        public static function countAll(int $cid, array $condition = [])
        {
                $condition = DBA::mergeConditions($condition,
-                       ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) 
-                       OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)',
+                       ['(`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) 
+                       OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))',
                                $cid, $cid]
                );
 
@@ -507,13 +507,13 @@ class Relation
        public static function listAll(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
        {
                $condition = DBA::mergeConditions($condition,
-                       ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) 
-                       OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)',
+                       ['(`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) 
+                       OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))',
                                $cid, $cid]
                );
 
                return DI::dba()->selectToArray('contact', [], $condition,
-                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
+                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
                );
        }
 
@@ -560,7 +560,7 @@ class Relation
                );
 
                return DI::dba()->selectToArray('contact', [], $condition,
-                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
+                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
                );
        }
 
@@ -605,7 +605,7 @@ class Relation
                );
 
                return DI::dba()->selectToArray('contact', [], $condition,
-                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
+                       ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
                );
        }
 
@@ -650,7 +650,7 @@ class Relation
                );
 
                return DI::dba()->selectToArray('contact', [], $condition,
-                       ['limit' => [$offset, $count],  'order' => [$shuffle ? 'name' : 'RAND()']]
+                       ['limit' => [$offset, $count],  'order' => [$shuffle ? 'RAND()' : 'name']]
                );
        }
 }
index ee5c35af8470d4e8208b1c1ab38d4681b3a20376..af70c420e6b2b3baf49f7134fcca1769391c49cc 100644 (file)
@@ -102,6 +102,29 @@ class User
 
        private static $owner;
 
+       /**
+        * Returns the numeric account type by their string
+        *
+        * @param string $accounttype as string constant
+        * @return void
+        */
+       public static function getAccountTypeByString(string $accounttype)
+       {
+               switch ($accounttype) {
+                       case 'person':
+                               return User::ACCOUNT_TYPE_PERSON;
+                       case 'organisation':
+                               return User::ACCOUNT_TYPE_ORGANISATION;
+                       case 'news':
+                               return User::ACCOUNT_TYPE_NEWS;
+                       case 'community':
+                               return User::ACCOUNT_TYPE_COMMUNITY;
+                       default:
+                               return null;
+                       break;
+               }
+       }
+
        /**
         * Fetch the system account
         *
index 85b3bb423937f3b582c999725a0b0fed751c29bf..8a7be5c893741d31b332e6987588ecfe992a64a8 100644 (file)
@@ -37,6 +37,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model;
+use Friendica\Model\User;
 use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Network\HTTPException\NotFoundException;
@@ -260,6 +261,9 @@ class Contact extends BaseModule
                $rel    = Strings::escapeTags(trim($_GET['rel']    ?? ''));
                $group  = Strings::escapeTags(trim($_GET['group']  ?? ''));
 
+               $accounttype = $_GET['accounttype'] ?? '';
+               $accounttypeid = User::getAccountTypeByString($accounttype);
+
                $page = DI::page();
 
                $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
@@ -339,6 +343,7 @@ class Contact extends BaseModule
 
                        $findpeople_widget = '';
                        $follow_widget = '';
+                       $account_widget = '';
                        $networks_widget = '';
                        $rel_widget = '';
 
@@ -356,12 +361,13 @@ class Contact extends BaseModule
                                $follow_widget = Widget::follow();
                        }
 
+                       $account_widget = Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
                        $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
                        $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
                        $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group);
                }
 
-               DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget;
+               DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $account_widget . $groups_widget . $networks_widget . $rel_widget;
 
                $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
                DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
@@ -664,6 +670,11 @@ class Contact extends BaseModule
                                break;
                }
 
+               if (isset($accounttypeid)) {
+                       $sql_extra .= " AND `contact-type` = ?";
+                       $sql_values[] = $accounttypeid;
+               }
+
                $searching = false;
                $search_hdr = null;
                if ($search) {
index e328b978ce2b0b2aecbd2b32516a2febb97212fe..e38d7acfce942a9c7f2bfb83c571491a59ac17d5 100644 (file)
@@ -4,10 +4,11 @@ namespace Friendica\Module\Contact;
 
 use Friendica\BaseModule;
 use Friendica\Content\Pager;
+use Friendica\Content\Widget;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\DI;
 use Friendica\Model;
+use Friendica\Model\User;
 use Friendica\Module;
 use Friendica\Network\HTTPException;
 
@@ -23,6 +24,8 @@ class Contacts extends BaseModule
 
                $cid = $parameters['id'];
                $type = $parameters['type'] ?? 'all';
+               $accounttype = $_GET['accounttype'] ?? '';
+               $accounttypeid = User::getAccountTypeByString($accounttype);
 
                if (!$cid) {
                        throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
@@ -44,6 +47,10 @@ class Contacts extends BaseModule
                        'failed' => false,
                ];
 
+               if (isset($accounttypeid)) {
+                       $condition['contact-type'] = $accounttypeid;
+               }
+
                $noresult_label = DI::l10n()->t('No known contacts.');
 
                switch ($type) {
@@ -57,10 +64,6 @@ class Contacts extends BaseModule
                                $total = Model\Contact\Relation::countMutuals($cid, $condition);
                                break;
                        case 'common':
-                               $condition = [
-                                       'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
-                                       $localContactId,
-                               ];
                                $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
                                $noresult_label = DI::l10n()->t('No common contacts.');
                                break;
@@ -119,6 +122,8 @@ class Contacts extends BaseModule
                        '$paginate' => $pager->renderFull($total),
                ]);
 
+               DI::page()['aside'] .= Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
+
                return $o;
        }
 }
index ae108dd918d719f3b769caf1c5789920cea1f7d5..f9eeaa6fd944e0bcc40af4d99916865893204083 100644 (file)
@@ -192,23 +192,7 @@ class Community extends BaseModule
                        throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
                }
 
-               switch ($parameters['accounttype'] ?? '') {
-                       case 'person':
-                               self::$accounttype = User::ACCOUNT_TYPE_PERSON;
-                               break;
-                       case 'organisation':
-                               self::$accounttype = User::ACCOUNT_TYPE_ORGANISATION;
-                               break;
-                       case 'news':
-                               self::$accounttype = User::ACCOUNT_TYPE_NEWS;
-                               break;
-                       case 'community':
-                               self::$accounttype = User::ACCOUNT_TYPE_COMMUNITY;
-                               break;
-                       default:
-                               self::$accounttype = null;
-                               break;
-               }
+               self::$accounttype = User::getAccountTypeByString($parameters['accounttype'] ?? '');
 
                self::$content = $parameters['content'] ?? '';
                if (!self::$content) {