Use centralized function to fetch query results

This commit is contained in:
Michael 2022-04-08 06:04:50 +00:00
parent 2764859350
commit 69b7923df2
4 changed files with 16 additions and 3 deletions

View file

@ -1461,7 +1461,7 @@ class Contact
if ($pager->getStart() == 0) {
$cdata = Contact::getPublicAndUserContactID($cid, local_user());
if (!empty($cdata['public'])) {
$pinned = DBA::selectToArray('collection-view', ['uri-id'], ['cid' => $cdata['public'], 'type' => Post\Collection::FEATURED]);
$pinned = Post\Collection::selectToArrayForContact($cdata['public'], Post\Collection::FEATURED, ['uri-id']);
$items = array_merge($items, $pinned);
}
}

View file

@ -58,4 +58,17 @@ class Collection
DBA::delete('post-collection', ['uri-id' => $uri_id, 'type' => $type]);
}
/**
* Fetch collections for a given contact
*
* @param integer $cid
* @param [type] $type
* @param array $fields
* @return array
*/
public static function selectToArrayForContact(int $cid, int $type = self::FEATURED, array $fields = [])
{
return DBA::selectToArray('collection-view', $fields, ['cid' => $cid, 'type' => $type]);
}
}

View file

@ -209,7 +209,7 @@ class Status extends BaseProfile
if ($pager->getStart() == 0 && !empty($profile['uid'])) {
$pcid = Contact::getPublicIdByUserId($profile['uid']);
$pinned = DBA::selectToArray('collection-view', [], ['cid' => $pcid, 'type' => Post\Collection::FEATURED]);
$pinned = Post\Collection::selectToArrayForContact($pcid, Post\Collection::FEATURED);
$items = array_merge($items, $pinned);
}

View file

@ -999,7 +999,7 @@ class Processor
return;
}
$posts = DBA::selectToArray('collection-view', ['uri-id'], ['cid' => $pcid, 'type' => Post\Collection::FEATURED]);
$posts = Post\Collection::selectToArrayForContact($pcid, Post\Collection::FEATURED);
if (!empty($posts)) {
$old_featured = array_column($posts, 'uri-id');
}