Getting posts of logged in user and freinds in river

I need to display the feeds from logged in user and his friends only in River, how can I do that.

Following code displays the posts from friends only but not included the posts from logged in users ( RIVER)

elgg_get_entity_relationship_where_sql($options['subject_guid'], $options['relationship_guid'] = elgg_get_logged_in_user_guid()) ;

$options['relationship'] = 'friend';

 

Please help

  • I had tried this but it is not displaying.

    
    
      //Mine activity
    
             $optionsm['subject_guid'] = elgg_get_logged_in_user_guid();
            $activitym = elgg_get_river($optionsm);
           
    
    //Friends activity
            $optionsf['relationship_guid'] = elgg_get_logged_in_user_guid();
            $optionsf['relationship'] = 'friend';
                  
            $activityf = elgg_get_river($optionsf);    
            $rivitems = array_merge($activitym, $activityf);
            $activity = elgg_list_river($rivitems);

     

    Please suggest

    Else, if we are passing it through elgg_view array with setting order by

    elgg_view('page/components/list', $options);

    the feeds are not displaying in timely order as displaying the feeds of mine first and then friends.

    Please help.

  • Please help by someone ?

  • Remove/Overwrite filter_context

    Also, make your own layout w/o filter_context instead of elgg_view_layout('content', $params);

  • @RVR Thanks for your message.

    Sorry, I couldn't able to understand the concept. Would you please confirm I am following correct steps as you explained.

    A different layout is already using feed_view_layout('content',$params); and its files are inside , views/default/feeds and I have removed the filter.php file completely from layout/content/ directory, but still displaying as old.

     

    Once again explaining the issue, Mine and Friends posts are displaying correctly, but the only issue is river is displaying mine posts first then bottom of that displaying the friends post, then we can understand it is not displaying as timely manner desc. Hope you understand ? Iam looking for a solution on this.

  • Your clauses are incorrect, you will have to use a more complex query. The simpler (less efficient) version is to add all friend guids to the subject guids parameter:

    $user = elgg_get_logged_in_user();
    $subject_guids = [$user->guid];
    $friends = elgg_get_entities_from_relationship([
       'relationship_guid' => $user->guid,
       'relationship' => 'friend',
       'limit' => 0,
       'callback' => false,
       'batch' => true, // will only work in Elgg 2.3, use ElggBatch in earlier versions
    ]);
    
    foreach ($friends as $friend) {
       $subject_guids[] = $friend->guid;
    }
    
    echo elgg_list_river([
       'subject_guids' => $subject_guids,
    ]);
    

     

    More complex query:

    $user_guid = elgg_get_logged_in_user_guid();
    $dbprefix = elgg_get_config('dbprefix);
    
    $options['wheres'][] = "
       rv.subject_guid = $user->guid
       OR
       EXISTS (SELECT 1 FROM {$dbprefix}entity_relationships AS friend
                        WHERE friend.guid_one = rv.subject_guid
                        AND friend.relationship = 'friend'
                        AND friend.guid_two = $user->guid)
    ";
    
    // you may need to reverse guid_one and guid_two if your friends are not reciprocal
    // depending if you want friend with or friends of
    
    echo elgg_list_river($options);
    

    I haven't tested the queries though, just posting from top of my head.

     

  • Thank you very much but the error I am getting is but it is corrected when putting friend inside 'friend'

    #1054 - Unknown column 'friend' in 'where clause'

  • @Ismayil Khayredinov

    FANTASTIC !!  You are Truly Awesome :) Seems you have sound knowledge in core of elgg. Noted you :)

  • May I know the limit of post for this query, ? How set it as unlimited ?