use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Model\APContact;
+use Friendica\Model\Contact;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
public static function countFollows(int $cid, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
- ['`id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
- AND `follows`
-)', $cid]
+ ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
+ $cid]
);
return DI::dba()->count('contact', $condition);
* Returns a paginated list of contacts that are followed the provided public contact.
*
* @param int $cid Public contact id
+ * @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
* @return array
* @throws Exception
*/
- public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
+ public static function listFollows(int $cid, array $fields = [], 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`
-)', $cid]
+ ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
+ $cid]
);
- $follows = DI::dba()->selectToArray(
- 'contact',
- $condition,
- [
- 'limit' => [$offset, $count],
- 'order' => [$shuffle ? 'RAND()' : 'name']
- ]
+ return DI::dba()->selectToArray('contact', $fields, $condition,
+ ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
);
-
- return $follows;
}
/**
public static function countFollowers(int $cid, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
- ['`id` IN (
- SELECT `cid`
- FROM `contact-relation`
- WHERE `relation-cid` = ?
- AND `follows`
-)', $cid]
+ ['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)',
+ $cid]
);
return DI::dba()->count('contact', $condition);
* Returns a paginated list of contacts that follow the provided public contact.
*
* @param int $cid Public contact id
+ * @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
* @return array
* @throws Exception
*/
- public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
+ public static function listFollowers(int $cid, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
- ['`id` IN (
- SELECT `cid`
- FROM `contact-relation`
- WHERE `relation-cid` = ?
- AND `follows`
-)', $cid]
+ ['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $cid]
);
- $followers = DI::dba()->selectToArray(
- 'contact',
- $condition,
- [
- 'limit' => [$offset, $count],
- 'order' => [$shuffle ? 'RAND()' : 'name']
- ]
+ return DI::dba()->selectToArray('contact', $fields, $condition,
+ ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
);
-
- return $followers;
}
/**
public static function countCommon(int $sourceId, int $targetId, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
- ['`id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
-)
- AND `id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
-)', $sourceId, $targetId]
+ ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)
+ AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)',
+ $sourceId, $targetId]
);
- $total = DI::dba()->count('contact', $condition);
-
- return $total;
+ return DI::dba()->count('contact', $condition);
}
/**
*
* @param int $sourceId Public contact id
* @param int $targetId Public contact id
+ * @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
* @return array
* @throws Exception
*/
- public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
+ public static function listCommon(int $sourceId, int $targetId, array $fields = [], 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`
-)
- AND `id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
- AND `follows`
-)", $sourceId, $targetId]
+ ["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
+ AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
+ $sourceId, $targetId]
);
- $contacts = DI::dba()->selectToArray(
- 'contact',
- $condition,
- [
- 'limit' => [$offset, $count],
- 'order' => [$shuffle ? 'name' : 'RAND()'],
- ]
+ return DI::dba()->selectToArray('contact', $fields, $condition,
+ ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
);
-
- return $contacts;
}
public static function countCommonFollows(int $sourceId, int $targetId, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
- ['`id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
- AND `follows`
-)
- AND `id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
- AND `follows`
-)', $sourceId, $targetId]
+ ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
+ AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
+ $sourceId, $targetId]
);
- $total = DI::dba()->count('contact', $condition);
-
- return $total;
+ return DI::dba()->count('contact', $condition);
}
/**
*
* @param int $sourceId Public contact id
* @param int $targetId Public contact id
+ * @param array $field Field list
* @param array $condition Additional condition array on the contact table
* @param int $count
* @param int $offset
* @return array
* @throws Exception
*/
- public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
+ public static function listCommonFollows(int $sourceId, int $targetId, array $fields = [], 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`
-)
- AND `id` IN (
- SELECT `relation-cid`
- FROM `contact-relation`
- WHERE `cid` = ?
- AND `follows`
-)", $sourceId, $targetId]
+ ["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
+ AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
+ $sourceId, $targetId]
);
- $contacts = DI::dba()->selectToArray(
- 'contact',
- $condition,
- [
- 'limit' => [$offset, $count],
- 'order' => [$shuffle ? 'name' : 'RAND()'],
- ]
+ return DI::dba()->selectToArray('contact', $fields, $condition,
+ ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
);
-
- return $contacts;
}
/**
public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
- ['`id` IN (
- SELECT `cid`
- FROM `contact-relation`
- WHERE `relation-cid` = ?
- AND `follows`
-)
- AND `id` IN (
- SELECT `cid`
- FROM `contact-relation`
- WHERE `relation-cid` = ?
- AND `follows`
-)', $sourceId, $targetId]
+ ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
+ AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
+ $sourceId, $targetId]
);
- $total = DI::dba()->count('contact', $condition);
-
- return $total;
+ return DI::dba()->count('contact', $condition);
}
/**
*
* @param int $sourceId Public contact id
* @param int $targetId Public contact id
+ * @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
* @return array
* @throws Exception
*/
- public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
+ public static function listCommonFollowers(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
- ["`id` IN (
- SELECT `cid`
- FROM `contact-relation`
- WHERE `relation-cid` = ?
- AND `follows`
-)
- AND `id` IN (
- SELECT `cid`
- FROM `contact-relation`
- WHERE `relation-cid` = ?
- AND `follows`
-)", $sourceId, $targetId]
+ ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
+ AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
+ $sourceId, $targetId]
);
- $contacts = DI::dba()->selectToArray(
- 'contact',
- $condition,
- [
- 'limit' => [$offset, $count],
- 'order' => [$shuffle ? 'name' : 'RAND()'],
- ]
+ return DI::dba()->selectToArray('contact', $fields, $condition,
+ ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
);
-
- return $contacts;
}
}