Merge pull request #9401 from annando/accounttype
Filter for account type for contacts
This commit is contained in:
commit
e3cf708dd8
8 changed files with 333 additions and 312 deletions
|
@ -132,7 +132,7 @@ function network_init(App $a)
|
|||
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];
|
||||
} else {
|
||||
$accounttype = '';
|
||||
|
@ -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);
|
||||
|
|
|
@ -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('Account Types'), '',
|
||||
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)
|
||||
|
@ -536,7 +554,7 @@ class Widget
|
|||
public static function accounts(string $base, string $accounttype)
|
||||
{
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/accounts.tpl'), [
|
||||
'$title' => DI::l10n()->t('Accounts'),
|
||||
'$title' => DI::l10n()->t('Account Types'),
|
||||
'$content' => $base,
|
||||
'$accounttype' => ($accounttype ?? ''),
|
||||
'$all' => DI::l10n()->t('All'),
|
||||
|
|
|
@ -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']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,29 @@ class User
|
|||
|
||||
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
|
||||
*
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue