1
0
Fork 0

Merge pull request #9401 from annando/accounttype

Filter for account type for contacts
This commit is contained in:
Hypolite Petovan 2020-10-10 07:16:32 -04:00 committed by GitHub
commit e3cf708dd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 333 additions and 312 deletions

View file

@ -132,7 +132,7 @@ function network_init(App $a)
DI::page()['aside'] = ''; DI::page()['aside'] = '';
} }
if (!empty($a->argv[1]) && in_array($a->argv[1], ['person', 'organisation', 'news', 'community'])) { if (!empty(User::getAccountTypeByString($a->argv[1] ?? ''))) {
$accounttype = $a->argv[1]; $accounttype = $a->argv[1];
} else { } else {
$accounttype = ''; $accounttype = '';
@ -300,23 +300,7 @@ function network_content(App $a, $update = 0, $parent = 0)
$o = ''; $o = '';
} }
switch ($a->argv[1] ?? '') { $account = User::getAccountTypeByString($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;
}
if (!empty($_GET['file'])) { if (!empty($_GET['file'])) {
$o .= networkFlatView($a, $update, $account); $o .= networkFlatView($a, $update, $account);

View file

@ -24,17 +24,13 @@ namespace Friendica\Content;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\FileTag; use Friendica\Model\FileTag;
use Friendica\Model\GContact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
class Widget class Widget
@ -526,8 +522,30 @@ class Widget
return $o; 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('Account Types'), '',
DI::l10n()->t('All'), $base, $accounts, $accounttype);
}
/** /**
* Display the accounts sidebar * Display the accounts sidebar
* The account type is added to the path
* *
* @param string $base Basepath * @param string $base Basepath
* @param string $accounttype Acount type (person, organisation, news, community) * @param string $accounttype Acount type (person, organisation, news, community)
@ -536,7 +554,7 @@ class Widget
public static function accounts(string $base, string $accounttype) public static function accounts(string $base, string $accounttype)
{ {
return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/accounts.tpl'), [ return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/accounts.tpl'), [
'$title' => DI::l10n()->t('Accounts'), '$title' => DI::l10n()->t('Account Types'),
'$content' => $base, '$content' => $base,
'$accounttype' => ($accounttype ?? ''), '$accounttype' => ($accounttype ?? ''),
'$all' => DI::l10n()->t('All'), '$all' => DI::l10n()->t('All'),

View file

@ -469,7 +469,7 @@ class Relation
); );
return DI::dba()->selectToArray('contact', [], $condition, 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 = []) public static function countAll(int $cid, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `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`)', OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))',
$cid, $cid] $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) public static function listAll(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `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`)', OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))',
$cid, $cid] $cid, $cid]
); );
return DI::dba()->selectToArray('contact', [], $condition, 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, 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, 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, return DI::dba()->selectToArray('contact', [], $condition,
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']] ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
); );
} }
} }

View file

@ -102,6 +102,29 @@ class User
private static $owner; private static $owner;
/**
* Returns the numeric account type by their string
*
* @param string $accounttype as string constant
* @return int|null Numeric account type - or null when not set
*/
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 * Fetch the system account
* *

View file

@ -37,6 +37,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model; use Friendica\Model;
use Friendica\Model\User;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\NotFoundException; use Friendica\Network\HTTPException\NotFoundException;
@ -260,6 +261,9 @@ class Contact extends BaseModule
$rel = Strings::escapeTags(trim($_GET['rel'] ?? '')); $rel = Strings::escapeTags(trim($_GET['rel'] ?? ''));
$group = Strings::escapeTags(trim($_GET['group'] ?? '')); $group = Strings::escapeTags(trim($_GET['group'] ?? ''));
$accounttype = $_GET['accounttype'] ?? '';
$accounttypeid = User::getAccountTypeByString($accounttype);
$page = DI::page(); $page = DI::page();
$page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js')); $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
@ -339,6 +343,7 @@ class Contact extends BaseModule
$findpeople_widget = ''; $findpeople_widget = '';
$follow_widget = ''; $follow_widget = '';
$account_widget = '';
$networks_widget = ''; $networks_widget = '';
$rel_widget = ''; $rel_widget = '';
@ -356,12 +361,13 @@ class Contact extends BaseModule
$follow_widget = Widget::follow(); $follow_widget = Widget::follow();
} }
$account_widget = Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
$networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets); $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
$rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel); $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
$groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group); $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'); $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [ DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
@ -664,6 +670,11 @@ class Contact extends BaseModule
break; break;
} }
if (isset($accounttypeid)) {
$sql_extra .= " AND `contact-type` = ?";
$sql_values[] = $accounttypeid;
}
$searching = false; $searching = false;
$search_hdr = null; $search_hdr = null;
if ($search) { if ($search) {

View file

@ -4,10 +4,11 @@ namespace Friendica\Module\Contact;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI; use Friendica\DI;
use Friendica\Model; use Friendica\Model;
use Friendica\Model\User;
use Friendica\Module; use Friendica\Module;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -23,6 +24,8 @@ class Contacts extends BaseModule
$cid = $parameters['id']; $cid = $parameters['id'];
$type = $parameters['type'] ?? 'all'; $type = $parameters['type'] ?? 'all';
$accounttype = $_GET['accounttype'] ?? '';
$accounttypeid = User::getAccountTypeByString($accounttype);
if (!$cid) { if (!$cid) {
throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.')); throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
@ -44,6 +47,10 @@ class Contacts extends BaseModule
'failed' => false, 'failed' => false,
]; ];
if (isset($accounttypeid)) {
$condition['contact-type'] = $accounttypeid;
}
$noresult_label = DI::l10n()->t('No known contacts.'); $noresult_label = DI::l10n()->t('No known contacts.');
switch ($type) { switch ($type) {
@ -57,10 +64,6 @@ class Contacts extends BaseModule
$total = Model\Contact\Relation::countMutuals($cid, $condition); $total = Model\Contact\Relation::countMutuals($cid, $condition);
break; break;
case 'common': case 'common':
$condition = [
'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
$localContactId,
];
$total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition); $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
$noresult_label = DI::l10n()->t('No common contacts.'); $noresult_label = DI::l10n()->t('No common contacts.');
break; break;
@ -119,6 +122,8 @@ class Contacts extends BaseModule
'$paginate' => $pager->renderFull($total), '$paginate' => $pager->renderFull($total),
]); ]);
DI::page()['aside'] .= Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
return $o; return $o;
} }
} }

View file

@ -192,23 +192,7 @@ class Community extends BaseModule
throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.'));
} }
switch ($parameters['accounttype'] ?? '') { self::$accounttype = User::getAccountTypeByString($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::$content = $parameters['content'] ?? ''; self::$content = $parameters['content'] ?? '';
if (!self::$content) { if (!self::$content) {

File diff suppressed because it is too large Load diff