1
1
Fork 0

Use switches instead of if/else in Module\Search\Acl

This commit is contained in:
Hypolite Petovan 2019-10-04 22:27:13 -04:00
parent 9e29321aaf
commit 908197cc70

View file

@ -116,7 +116,9 @@ class Acl extends BaseModule
$sql_extra2 .= ' ' . Widget::unavailableNetworks(); $sql_extra2 .= ' ' . Widget::unavailableNetworks();
$contact_count = 0; $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 // autocomplete for editor mentions
$r = q("SELECT COUNT(*) AS c FROM `contact` $r = q("SELECT COUNT(*) AS c FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` WHERE `uid` = %d AND NOT `self` AND NOT `deleted`
@ -125,7 +127,9 @@ class Acl extends BaseModule
intval(local_user()) intval(local_user())
); );
$contact_count = (int) $r[0]['c']; $contact_count = (int) $r[0]['c'];
} elseif ($type == self::TYPE_MENTION_FORUM) { break;
case self::TYPE_MENTION_FORUM:
// autocomplete for editor mentions of forums // autocomplete for editor mentions of forums
$r = q("SELECT COUNT(*) AS c FROM `contact` $r = q("SELECT COUNT(*) AS c FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` WHERE `uid` = %d AND NOT `self` AND NOT `deleted`
@ -135,7 +139,9 @@ class Acl extends BaseModule
intval(local_user()) intval(local_user())
); );
$contact_count = (int) $r[0]['c']; $contact_count = (int) $r[0]['c'];
} elseif ($type == self::TYPE_PRIVATE_MESSAGE) { break;
case self::TYPE_PRIVATE_MESSAGE:
// autocomplete for Private Messages // autocomplete for Private Messages
$r = q("SELECT COUNT(*) AS c FROM `contact` $r = q("SELECT COUNT(*) AS c FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `deleted` WHERE `uid` = %d AND NOT `self` AND NOT `deleted`
@ -147,7 +153,10 @@ class Acl extends BaseModule
DBA::escape(Protocol::DIASPORA) DBA::escape(Protocol::DIASPORA)
); );
$contact_count = (int) $r[0]['c']; $contact_count = (int) $r[0]['c'];
} elseif ($type == self::TYPE_ANY_CONTACT) { break;
case self::TYPE_ANY_CONTACT:
default:
// autocomplete for Contacts // autocomplete for Contacts
$r = q("SELECT COUNT(*) AS c FROM `contact` $r = q("SELECT COUNT(*) AS c FROM `contact`
WHERE `uid` = %d AND NOT `self` WHERE `uid` = %d AND NOT `self`
@ -155,6 +164,7 @@ class Acl extends BaseModule
intval(local_user()) intval(local_user())
); );
$contact_count = (int) $r[0]['c']; $contact_count = (int) $r[0]['c'];
break;
} }
$tot = $group_count + $contact_count; $tot = $group_count + $contact_count;
@ -195,7 +205,8 @@ class Acl extends BaseModule
} }
$r = []; $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` $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` != '' 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')) AND NOT (`network` IN ('%s', '%s'))
@ -205,7 +216,9 @@ class Acl extends BaseModule
DBA::escape(Protocol::OSTATUS), DBA::escape(Protocol::OSTATUS),
DBA::escape(Protocol::STATUSNET) 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` $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` != '' 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')) AND NOT (`network` IN ('%s'))
@ -214,7 +227,9 @@ class Acl extends BaseModule
intval(local_user()), intval(local_user()),
DBA::escape(Protocol::STATUSNET) 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` $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` != '' 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')) AND NOT (`network` IN ('%s'))
@ -224,7 +239,9 @@ class Acl extends BaseModule
intval(local_user()), intval(local_user()),
DBA::escape(Protocol::STATUSNET) 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` $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` WHERE `uid` = %d AND NOT `self` AND NOT `deleted` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
AND `network` IN ('%s', '%s', '%s') AND `network` IN ('%s', '%s', '%s')
@ -235,13 +252,17 @@ class Acl extends BaseModule
DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DFRN),
DBA::escape(Protocol::DIASPORA) 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` $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` WHERE `uid` = %d AND NOT `deleted` AND NOT `pending` AND NOT `archive`
$sql_extra2 $sql_extra2
ORDER BY `name`", ORDER BY `name`",
intval(local_user()) intval(local_user())
); );
break;
} }
if (DBA::isResult($r)) { if (DBA::isResult($r)) {