From 69b7923df2beed71419bc38e61ca9755fad24b12 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 8 Apr 2022 06:04:50 +0000 Subject: [PATCH] Use centralized function to fetch query results --- src/Model/Contact.php | 2 +- src/Model/Post/Collection.php | 13 +++++++++++++ src/Module/Profile/Status.php | 2 +- src/Protocol/ActivityPub/Processor.php | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 439f9b34b..df1a25cd7 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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); } } diff --git a/src/Model/Post/Collection.php b/src/Model/Post/Collection.php index f7a1a996b..476e9d3b3 100644 --- a/src/Model/Post/Collection.php +++ b/src/Model/Post/Collection.php @@ -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]); + } } diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index 23b78d959..f3015692f 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -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); } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index d6bce87f4..e5653a554 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -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'); }