Use switches instead of if/else in Module\Search\Acl
This commit is contained in:
parent
9e29321aaf
commit
908197cc70
|
@ -116,7 +116,9 @@ class Acl extends BaseModule
|
|||
$sql_extra2 .= ' ' . Widget::unavailableNetworks();
|
||||
|
||||
$contact_count = 0;
|
||||
if ($type == self::TYPE_MENTION_CONTACT_GROUP || $type == self::TYPE_MENTION_CONTACT) {
|
||||
switch ($type) {
|
||||
case self::TYPE_MENTION_CONTACT_GROUP:
|
||||
case self::TYPE_MENTION_CONTACT:
|
||||
// autocomplete for editor mentions
|
||||
$r = q("SELECT COUNT(*) AS c FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted`
|
||||
|
@ -125,7 +127,9 @@ class Acl extends BaseModule
|
|||
intval(local_user())
|
||||
);
|
||||
$contact_count = (int) $r[0]['c'];
|
||||
} elseif ($type == self::TYPE_MENTION_FORUM) {
|
||||
break;
|
||||
|
||||
case self::TYPE_MENTION_FORUM:
|
||||
// autocomplete for editor mentions of forums
|
||||
$r = q("SELECT COUNT(*) AS c FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted`
|
||||
|
@ -135,7 +139,9 @@ class Acl extends BaseModule
|
|||
intval(local_user())
|
||||
);
|
||||
$contact_count = (int) $r[0]['c'];
|
||||
} elseif ($type == self::TYPE_PRIVATE_MESSAGE) {
|
||||
break;
|
||||
|
||||
case self::TYPE_PRIVATE_MESSAGE:
|
||||
// autocomplete for Private Messages
|
||||
$r = q("SELECT COUNT(*) AS c FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted`
|
||||
|
@ -147,7 +153,10 @@ class Acl extends BaseModule
|
|||
DBA::escape(Protocol::DIASPORA)
|
||||
);
|
||||
$contact_count = (int) $r[0]['c'];
|
||||
} elseif ($type == self::TYPE_ANY_CONTACT) {
|
||||
break;
|
||||
|
||||
case self::TYPE_ANY_CONTACT:
|
||||
default:
|
||||
// autocomplete for Contacts
|
||||
$r = q("SELECT COUNT(*) AS c FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self`
|
||||
|
@ -155,6 +164,7 @@ class Acl extends BaseModule
|
|||
intval(local_user())
|
||||
);
|
||||
$contact_count = (int) $r[0]['c'];
|
||||
break;
|
||||
}
|
||||
|
||||
$tot = $group_count + $contact_count;
|
||||
|
@ -195,7 +205,8 @@ class Acl extends BaseModule
|
|||
}
|
||||
|
||||
$r = [];
|
||||
if ($type == self::TYPE_MENTION_CONTACT_GROUP) {
|
||||
switch ($type) {
|
||||
case self::TYPE_MENTION_CONTACT_GROUP:
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv`, (`prv` OR `forum`) AS `frm` FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
|
||||
AND NOT (`network` IN ('%s', '%s'))
|
||||
|
@ -205,7 +216,9 @@ class Acl extends BaseModule
|
|||
DBA::escape(Protocol::OSTATUS),
|
||||
DBA::escape(Protocol::STATUSNET)
|
||||
);
|
||||
} elseif ($type == self::TYPE_MENTION_CONTACT) {
|
||||
break;
|
||||
|
||||
case self::TYPE_MENTION_CONTACT:
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
|
||||
AND NOT (`network` IN ('%s'))
|
||||
|
@ -214,7 +227,9 @@ class Acl extends BaseModule
|
|||
intval(local_user()),
|
||||
DBA::escape(Protocol::STATUSNET)
|
||||
);
|
||||
} elseif ($type == self::TYPE_MENTION_FORUM) {
|
||||
break;
|
||||
|
||||
case self::TYPE_MENTION_FORUM:
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
|
||||
AND NOT (`network` IN ('%s'))
|
||||
|
@ -224,7 +239,9 @@ class Acl extends BaseModule
|
|||
intval(local_user()),
|
||||
DBA::escape(Protocol::STATUSNET)
|
||||
);
|
||||
} elseif ($type == self::TYPE_PRIVATE_MESSAGE) {
|
||||
break;
|
||||
|
||||
case self::TYPE_PRIVATE_MESSAGE:
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr` FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
|
||||
AND `network` IN ('%s', '%s', '%s')
|
||||
|
@ -235,13 +252,17 @@ class Acl extends BaseModule
|
|||
DBA::escape(Protocol::DFRN),
|
||||
DBA::escape(Protocol::DIASPORA)
|
||||
);
|
||||
} elseif ($type == self::TYPE_ANY_CONTACT) {
|
||||
break;
|
||||
|
||||
case self::TYPE_ANY_CONTACT:
|
||||
default:
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `deleted` AND NOT `pending` AND NOT `archive`
|
||||
$sql_extra2
|
||||
ORDER BY `name`",
|
||||
intval(local_user())
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (DBA::isResult($r)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user