findFollowersForProfile

Robert9

Well-known member
$userFollowRepo = $this->repository('XF:UserFollow');
$userFollowersFinder = $userFollowRepo->findFollowersForProfile($user)
->order('follow_date', 'desc')
->limitByPage($page, $perPage, 1);

$followers = $userFollowersFinder->fetch()->pluckNamed('User');


When i dump $userFollowersFinder
i have for example:
[user_id] => 28
[follow_user_id] => 1
[follow_date] => 1616792708

but how i bring this information into: $followers to show the date, when someone starts to follow me?
 
Code:
[XF\Entity\UserFollow] => Array
                        (
                            [28\x1E1] => XF\Entity\UserFollow Object
                                (
                                    [_uniqueEntityId:XF\Mvc\Entity\Entity:private] => 9
                                    [rootClass:protected] => XF\Entity\UserFollow
                                    [_useReplaceInto:protected] =>
                                    [_newValues:protected] => Array
                                        (
                                        )

                                    [_values:protected] => Array
                                        (
                                            [user_id] => 28
                                            [follow_user_id] => 1
                                            [follow_date] => 1616792708
                                        )

                                    [_relations:protected] => Array
                                        (
                                            [User] => SV\ReportImprovements\XF\Entity\User Object
                                                (
                                                    [wasCanBeAssignedReports:protected] =>
                                                    [_uniqueEntityId:XF\Mvc\Entity\Entity:private] => 8
                                                    [rootClass:protected] => XF\Entity\User
                                                    [_useReplaceInto:protected] =>
                                                    [_newValues:protected] => Array
                                                        (
                                                        )

                                                    [_values:protected] => Array
                                                        (
                                                            [user_id] => 28
                                                            [username] => Test
                                                            [username_date] => 0
                                                            [username_date_visible] => 0
 
From xf docs
We use the pluckNamed() method first to get a collection of threads followers, then again to get a collection of the posts users (keyed by the post userID) from the followers. ...

So where is the info about threads followers here?
 
Last edited:
You posted in the

Custom service/development requests​

forum, which means you are looking to hire someone.
 
Solved. Thank you. :)
If someone has equal problems:

Code:
        $userFollowers = $userFollowingFinder->fetch();

...

        $followers = $userFollowers->pluckNamed('FollowUser');

I have splitted

$followers = $userFollowersFinder->fetch()->pluckNamed('User');

to

$userFollowers = $userFollowingFinder->fetch();

and

$followers = $userFollowers->pluckNamed('FollowUser');

the index for the both arrays follower and following
is myUserID-otherID and otherID-myUserID

to come to the correct otherId a regex is needed.
 
Last edited:
Code:
$finder->keyedBy('follow_user_id')->fetch()->pluckNamed('FollowUser')

Or

Code:
$finder->fetch()->pluckNamed('FollowUser', 'follow_user_id')
 
Back
Top Bottom