Pagination with Elgg_get_entities?

Hi there, just wanted to ask around if it's possible to use Pagination with the GET rather than the LIST function of elgg entities.

 

Im trying to essentially list the groups, but using List voids the changes I want to make on them (where the links link to a different page, instead of groups per say)

 

Ive got the limit to show up, but I want to see if its possible to put in pagination as having around 1000 groups on a single page is a bit troublesome.

 

Code is as followed, if it helps.

        case 'newest':
        default:
        //turn it into clickable links which get to the report pages
            $GroupArray = elgg_get_entities(array(
                'type' => 'group',
                'limit' => 12,
                'offset' => 0,
                'pagination' => true,
            ));
            if (!$GroupArray) {
                $GroupArray = elgg_echo('groups:none');
            }
            
            foreach($GroupArray as $Reports) {
                elgg_echo($Reports -> guid);
                elgg_echo($Reports -> name);
                elgg_echo('<br />');    
                $HTMLinks = "<a href='reports/". $Reports -> guid ."' ". "><h1> " . $Reports -> name . "</h1></a>" . "<br />";
                $content .= $HTMLinks;
            }

 

            break

 

  • List functions accept item_view parameter, so you can just add a new group view with your modifications and tell the list to use it

  • I must apologize but I am having some issues thinking of how that works, since I currently link using a regular HTML, I assume the page its linking to is what you refer to as the group view?

        switch ($selected_tab) {
            case 'popular':
                $content = elgg_list_entities_from_relationship_count(array(
                    'type' => 'group',
                    'relationship_guid' => $group->guid,
                    'relationship' => 'member',
                    'full_view' => false,
                ));
                
                if (!$content) {
                    $content = elgg_echo('groups:none');
                }
                break;

    This is currently the list code I use for the other tab while I compare between them, im assuming something in here is what I would use so it being clicked would link back to the new view I created specifically for this plugin? 

  • // views/default/custom-view.php
    echo $vars['entity']->name;

    // some other place
    echo elgg_list_entities([
    'item_view' => 'custom-view',
    ]);

  • Hmm, Ive been messing around with this all day and I cant seem to make it quite work.

    Could it be my file structure? Im using a Page folder to house list with all of the names and links, and a page to where it links towards the view which is also a form. Is there any documentation related to this process so I can read more into it and figure out what I happen to be doing wrong?

  • Create a new view that will contain the list item view, let's say you want to have a custom display for a group:

    // my_plugin/views/default/groups/custom_view.php
    
    $group = elgg_extract('entity', $vars);
    
    echo elgg_view('output/url', [
    
       'text' => $group->getDisplayName(),
       'href' => $group->getURL(),
    
    });
    

    Now, anywhere in your Elgg application, you can tell elgg_list_* to use this view:
     

    echo elgg_list_entities([
       'types' => 'group',
       'item_view' => 'groups/custom_view',
       'limit' => 20,
    ]);

    Make sure you flush the caches after you add the view. It's mentioned in the docs somewhere, but this is really straightforward, and shouldn't require that much time to figure out.

     

  • I see now, thanks! 

    I must ask however, my team is using version 1.8 and we are still having issue making this work correctly, is this compatible with that version? Just want me to make sure before I spent the next few days trouble shooting it.

  • Hmm, I suppose I will have to get crafty then. I can see it link to the correct page, yet with no GUID. My goal for the time being then will be to make the item_view work so it will send these links to that at least.

     

    ...Or is that a later version as well?

  • item_view is available on Elgg 1.11 or later only (not sure if it's 1.11 but surely not avaiable in Elgg 1.8).

    In Elgg 1.8 you would have to use elgg_get_entities with 'offset' and 'limit', e.g.

    offset = (int)get_input('offset', 0);
    $limit = (int)get_input('limit', 16);
    
    $count = elgg_get_entities_from_relationship_count(array(
        'type' => 'group',
        'relationship_guid' => $group->guid,
        'relationship' => 'member',
        'full_view' => false,
    ));
    
    $content = '';
    
    if ($count && $count > 0) {
        $entities = elgg_get_entities_from_relationship(array(
            'type' => 'group',
            'relationship_guid' => $group->guid,
            'relationship' => 'member',
            'full_view' => false,
            'limit' => $limit,
            'offset' => $offset,
        ));
        
        foreach($entities as $entity) {
            $content .= "blabla content for this entity item";
        }
    } else {
        $content .= elgg_echo('groups:none');
    }
    
    $body = elgg_view_layout('content', array(
        'content' => $content,
        'title' => 'Your page title',
    ));
    
    // Draw it
    echo elgg_view_page(Your page title', $body);
    

    The core plugins of Elgg should give you some code examples, too, with regards to pagination of items. The only specific point here is the layout of the items as you want them in a custom way as opposed to the "default" layout.