Combine "mine" and "friend" into one river tab

I'm trying to figure out how to combine "mine" and "friends" into one river tab. This is what I got so far but it isn't working. Any suggestions?

pages/river.php

switch ($page_type) {
    case 'mine':
        $title = elgg_echo('river:mine');
        $page_filter = 'mine';
        $options['subject_guid'] = elgg_get_logged_in_user_guid();
        break;
    case 'friends':
        $title = elgg_echo('river:friends');
        $page_filter = 'friends';
        $options['relationship_guid'] = elgg_get_logged_in_user_guid();
        $options['relationship'] = 'friend';
        break;
    case 'combined':
        $title = elgg_echo('river:mine');
        $page_filter = 'combined';
        $options['relationship_guid' . 'subject_guid'] = elgg_get_logged_in_user_guid();
        $options['relationship'] = 'friend';
        break;
    default:
        $title = elgg_echo('river:all');
        $page_filter = 'all';
        break;
}
  • I don't see how that's supposed to work. You can't just change an array key, it will be ignored by elgg_get_river(), because such key is not supported.
    You need to add a custom join and where clauses, because by default the function generates AND statements, you need OR.

  • Yeah you are right I have no idea what I'm doing. Where are the other array keys supported?

  • How much do you think it would cost me to have someone customize my river to include both mine and friends? Maybe I should take this thread to professional services?

  • I'm kinda lost any help out there? Would this be a big or small job?

  • $user = elgg_get_logged_in_user_entity();
    $dbprefix = elgg_get_config('dbprefix');
    echo elgg_list_river([
       'wheres' => [
          "
          rv.subject_guid = $user->guid 
          OR 
          rv.subject_guid IN (
             SELECT guid_two FROM {$dbprefix}entity_relationships
             WHERE relationship = 'friend'
             AND guid_one = $user->guid
          )"
       ],
    ]);
    
  • @Ismayil thanks for posting the query. I also tried to come up with a solution but got stuck (not even close to the solution to be honest).

  • @Ismayil Khayredinov Seriously thank you so much! that worked perfectly! 

  • @Ismayil Khayredinov I may have spoke too soon. Now I'm having styling issues. I think its because I'm calling the echo inside of a page_filter. Here's the whole page. Also, how much would you charge to help me with this issue?  Are you on UpWork?

    <?php
    /**
     * Main activity stream list page
     */
    
    $options = array();
    
    $page_type = preg_replace('[\W]', '', get_input('page_type', 'all'));
    $type = preg_replace('[\W]', '', get_input('type', 'all'));
    $subtype = preg_replace('[\W]', '', get_input('subtype', ''));
    if ($subtype) {
        $selector = "type=$type&subtype=$subtype";
    } else {
        $selector = "type=$type";
    }
    
    if ($type != 'all') {
        $options['type'] = $type;
        if ($subtype) {
            $options['subtype'] = $subtype;
        }
    }
    
    switch ($page_type) {
        case 'mine':
            $title = elgg_echo('river:mine');
            $page_filter = 'mine';
            $options['subject_guid'] = elgg_get_logged_in_user_guid();
            break;
        case 'friends':
            $title = elgg_echo('river:friends');
            $page_filter = 'friends';
            $options['relationship_guid'] = elgg_get_logged_in_user_guid();
            $options['relationship'] = 'friend';
            break;
        case 'combined':
            $title = elgg_echo('river:mine');
            $page_filter = 'combined';
            $user = elgg_get_logged_in_user_entity();
            $dbprefix = elgg_get_config('dbprefix');
            echo elgg_list_river([
                'wheres' => [
                    "
                    rv.subject_guid = $user->guid 
                    OR 
                    rv.subject_guid IN (
                    SELECT guid_two FROM {$dbprefix}entity_relationships
                    WHERE relationship = 'friend'
                    AND guid_one = $user->guid
                    )"
                ],
            ]);
            break;
        default:    
            $title = elgg_echo('river:all');
            $page_filter = 'all';
            break;
    }
    
    $options['count'] = true;
    $count = elgg_get_river($options);
    $options['count'] = false;
    
    $options['pagination'] = false;
    $options['offset'] = 0;
    if(elgg_get_config('default_limit'))
        $options['limit'] = elgg_get_config('default_limit');
    else
        $options['limit'] = 5;
    
    $script_text = '<script type="text/javascript"> 
            var options = ' . json_encode($options) . '; 
            var numactivities = ' . $count . '; 
            </script>';
    
    $activity = '<div id="river_auto_update_activity">';
    $activity .= elgg_list_river($options);
    if (!$activity) {
        $activity = elgg_echo('river:none');
    }
    $activity .= '</div>';
    if ($count > $options['limit']) {
        // show load more button
        $activity .= '<center id="river_auto_update_load_more_button"><button style="padding:0 50px;" onClick="loadMore()">Load More</button></center>';
        
        $script_text .= '<script type="text/javascript"> var istheremore = true; </script>';
    } else {
        $script_text .= '<script type="text/javascript"> var istheremore = false; </script>';
    }
    // show the loading gif
    $activity .= '<img id="river_auto_update_loading" src="' . elgg_get_site_url() . '/mod/time_theme/graphics/loading.gif" height="25px;" style="display:none; margin-left:auto; margin-right:auto;">';
    
    $content = elgg_view('core/river/filter', array('selector' => $selector));
    
    $sidebar = elgg_view('core/river/sidebar');
    
    $script_text .= '<script type="text/javascript">
    
     $(window).scroll(function() {   
       if($(window).scrollTop() + $(window).height() == $(document).height()) {            
            loadMore();        
       }
    });
    
    </script>';
    
    $params = array(
        'title' => $title,
        'content' =>  $content . $activity . $script_text,
        'sidebar' => $sidebar,
        'filter_context' => $page_filter,
        'class' => 'elgg-river-layout',
    );
    
    $body = elgg_view_layout('content', $params);
    
    echo elgg_view_page($title, $body);
    
    ?>
  • @Ismayil Khayredinov, I am using another code to extract only the "Group" activity. How can I club my code with yours so that I can have "Mine"+"Friends"+"Groups Activity" in one go.

    My Code:

    $db_prefix = elgg_get_config('dbprefix');
    $user = elgg_get_logged_in_user_entity();
    
    $groups = $user->getGroups('', false);
    $group_guids = array();
    foreach ($groups as $group) {
     $group_guids[] = $group->getGUID();
    }
    $guids_in = implode(',', array_unique(array_filter($group_guids)));
    
    echo elgg_list_river(array(
        'pagination' => true,
        'joins' => array("JOIN {$db_prefix}entities e ON e.guid = rv.object_guid"),
        'wheres' => array("e.container_guid IN({$guids_in})"),
        'order_by' => 'e.time_created desc'
     ));