This is what I came up with, I dont know if theres another solution.
Also im completely lost how to paginate this.

        function getMyFriends($user_id, $status = 'approved', $limit = 5) {
                $friends = $this->find('all', array(
                        'fields' => array('Friend.*'),
                        'recursive' => -1,
                        'conditions' => array(
                                'Friend.status' => $status,
                                'OR' => array(
                                        'Friend.user_id' => $user_id,
                                        'Friend.friend_id' => $user_id
                                )
                        ),
                        'order' => 'Friend.requestTime ASC',
                        'limit' => $limit
                ));

                $cleanFriends = array();
                if (!empty($friends)) {
                        foreach ($friends as $friend) {
                                if ($friend['Friend']['friend_id'] != $user_id) 
{
                                        $friend_id = 
$friend['Friend']['friend_id'];
                                } else {
                                        $friend_id = 
$friend['Friend']['user_id'];
                                }

                                $userObj = $this->User->find('first', array(
                                        'fields' => array('User.id', 
'User.username', 'User.avatar',
'User.handle', 'User.country_id', 'User.signupDate'),
                                        'recursive' => -1,
                                        'conditions' => array('User.id' => 
$friend_id)
                                ));

                                if (!empty($userObj)) {
                                        $cleanFriends[] = array_merge($friend, 
$userObj);
                                }
                        }
                }

                return $cleanFriends;
        }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to