We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36686
    • 165 Posts
    I'm trying to split the results from my PeopleGroup call into multiple pages using getPage. The first page is fine – the first 10 results are shown and the page navigation shows as i should. On the 2nd and consecutive pages however, no results are shown.

    [[!getPage?
         &limit=`10`
         &element=`PeopleGroup` 
         &usergroup=`Intresserad1` 
         &toPlaceholder=`users` 
         &userTpl=`fiberUserTpl` 
         &getProfile=`1` 
         &sortBy=`id` 
         &sortDir=`DESC` 
         &altCls=`alt`
    ]]
    
    <table>
    [[+users]]
    </table>
    
    [[+page]] of [[+pageCount]]
    <nav class="blog-navigation">
    <div class="paging">
    <ul class="pageList">
    [[!+page.nav]]
    </ul>
    </div>
    </nav>


    The chunk fiberUserTpl looks like this:

    <tr>
    <td class="[[+cls]]">[[+id]]</td>
    <td class="[[+cls]]">[[+extended.firstname]] [[+fullname]]</td>
    <td class="[[+cls]]" style="white-space:nowrap;">[[+extended.code]]</td>
    <td class="[[+cls]]">[[+phone]]</td>
    <td class="[[+cls]]">[[+email]]</td>
    <td class="[[+cls]]" style="white-space:nowrap;">[[+address]]</td>
    <td class="[[+cls]]" style="white-space:nowrap;">[[+city]]</td>
    </tr>
    <tr>
    <td class="[[+cls]]"></td>
    <td class="[[+cls]]" colspan="4"><em><strong>[[+comment]]</strong></em></td>
    <td class="[[+cls]]" colspan="2"><em><strong>[[+extended.altaddress]] [[+extended.altcity]]</strong></em></td>
    </tr>


    What am I missing?

    This question has been answered by labr1005. See the first response.

      • 16551 ☆ A M B ☆
      • 54 Posts
      1. What happens, if you set "&cache=`false`" for getPage?

      2. What happens, if you don't pass the output to a placeholder but let getPage return it?
        • 36686
        • 165 Posts
        Thanks for your reply labr1005!

        1. Tried adding &cache=`false` now but it made no difference unfortunately.

        2. When I remove &toPlaceholder=`users` I get the following error:

        Warning: implode() [function.implode]: Invalid arguments passed in /var/www/vhosts/xxxxxx.com/httpdocs/core/cache/includes/elements/modsnippet/38.include.cache.php on line 123
          • 16551 ☆ A M B ☆
          • 54 Posts
          Sorry. This of course creates an error... Hm. Can you post the contents of "PeopleGroup"? [ed. note: labr1005 last edited this post 13 years, 1 month ago.]
            • 36686
            • 165 Posts
            Sure, here's the PeopleGroup snippet:

            <?php
            /**
             * PeopleGroups
             *
             * Copyright 2010 by Shaun McCormick <[email protected]>
             *
             * Peoples is free software; you can redistribute it and/or modify it under the
             * terms of the GNU General Public License as published by the Free Software
             * Foundation; either version 2 of the License, or (at your option) any later
             * version.
             *
             * Peoples is distributed in the hope that it will be useful, but WITHOUT ANY
             * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
             * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
             *
             * You should have received a copy of the GNU General Public License along with
             * Peoples; if not, write to the Free Software Foundation, Inc., 59 Temple
             * Place, Suite 330, Boston, MA 02111-1307 USA
             *
             * @package peoples
             */
            /**
             * Displays a list of Users in a User Group, as well as user group name/info
             *
             * @package peoples
             */
            $peoples = $modx->getService('peoples','Peoples',$modx->getOption('peoples.core_path',null,$modx->getOption('core_path').'components/peoples/').'model/peoples/',$scriptProperties);
            if (!($peoples instanceof Peoples)) return '';
            $modx->lexicon->load('peoples:default');
            
            /* get usergroup */
            $usergroup = $modx->getOption('usergroup',$scriptProperties,false);
            if (empty($usergroup)) return '';
            $c = intval($usergroup);
            $c = is_int($c) && !empty($c) ? $usergroup : array('name' => $usergroup);
            $usergroup = $modx->getObject('modUserGroup',$c);
            if (empty($usergroup)) return $modx->lexicon('peoples.usergroup_err_nf');
            
            /* get default properties */
            $userTpl = $modx->getOption('userTpl',$scriptProperties,'pplGroupUser');
            $sortBy = $modx->getOption('sortBy',$scriptProperties,'username');
            $sortByAlias = $modx->getOption('sortByAlias',$scriptProperties,'modUser');
            $sortDir = $modx->getOption('sortDir',$scriptProperties,'ASC');
            $cls = $modx->getOption('cls',$scriptProperties,'ppl-user');
            $altCls = $modx->getOption('altCls',$scriptProperties,'');
            $firstCls = $modx->getOption('firstCls',$scriptProperties,'');
            $lastCls = $modx->getOption('lastCls',$scriptProperties,'');
            $placeholderPrefix = $modx->getOption('placeholderPrefix',$scriptProperties,'peoplegroup.');
            $userClass = $modx->getOption('userClass',$scriptProperties,'modUser');
            $getProfile = $modx->getOption('getProfile',$scriptProperties,false);
            $profileAlias = $modx->getOption('profileAlias',$scriptProperties,'Profile');
            $limit = (int)$modx->getOption('limit',$_REQUEST,$modx->getOption('limit',$scriptProperties,0));
            $start = (int)$modx->getOption('start',$modx->getOption('offset',$_REQUEST,$modx->getOption('offset',$scriptProperties,0)));
            
            /* define initial placeholders from usergroup data */
            $phs = $usergroup->toArray();
            
            /* get users */
            $c = $modx->newQuery($userClass);
            $c->innerJoin('modUserGroupMember','UserGroupMembers');
            $c->innerJoin('modUserGroupRole','UserGroupRole','UserGroupMembers.role = UserGroupRole.id');
            $c->where(array(
                'UserGroupMembers.user_group' => $usergroup->get('id'),
            ));
            $total = $modx->getCount($userClass,$c);
            $c->select($modx->getSelectColumns($userClass,$userClass));
            $c->select(array(
                'UserGroupRole.name AS role',
                'UserGroupRole.id AS role_id',
            ));
            $c->sortby($modx->escape($sortByAlias).'.'.$modx->escape($sortBy),$sortDir);
            if (!empty($limit)) {
                $c->limit($limit,$start);
            }
            $users = $modx->getCollection($userClass,$c);
            $phs['userCount'] = $total;
            /* iterate */
            $list = array();
            $idx = 0;
            $alt = false;
            $iterativeCount = count($users);
            $output = '';
            foreach ($users as $user) {
                $userArray = $user->toArray();
                unset($userArray['cachepwd'],$userArray['password']);
                if ($getProfile) {
                    $profile = $user->getOne($profileAlias);
                    if ($profile) $userArray = array_merge($profile->toArray(),$userArray);
                }
            
                $userArray['cls'] = array();
                $userArray['cls'][] = $cls;
                if ($alt && !empty($altCls)) $userArray['cls'][] = $altCls;
                if (!empty($firstCls) && $idx == 0) {
                    $userArray['cls'][] = $firstCls;
                }
                if (!empty($lastCls) && $idx == $iterativeCount-1) {
                    $userArray['cls'][] = $lastCls;
                }
                $userArray['cls'] = implode(' ',$userArray['cls']);
            
                $list[] = $peoples->getChunk($userTpl,$userArray);
                $peoples->clearPlaceholders($userArray,'extended');
                $peoples->clearPlaceholders($userArray,'remote_data');
                $alt = !$alt;
                $idx++;
            }
            $outputSeparator = $modx->getOption('outputSeparator',$scriptProperties,"\n");
            if (count($list) > 0) {
                /* pagination handling in conjunction with getPage */
                if (!empty($limit)) {
                    $pageVarKey = $modx->getOption('pageVarKey',$scriptProperties,'page');
                    $page = (int)$modx->getOption($pageVarKey,$scriptProperties,$modx->getOption($pageVarKey,$_REQUEST,1));
                    $offset = (int)$modx->getOption('offset',$scriptProperties,0);
                    /* cut the list of file into blocks */
                    $list = array_chunk($list,$limit,true);
                    /* output the current listing block */
                    $output = implode($outputSeparator,$list[$page - 1]);
                    /* need to make the total available without placeholder prefix for getPage */
            
                    $modx->setPlaceholder('total',$total);
                } else {
                    /* no pagination so display all results */
                    $output = implode($outputSeparator,$list);
                }
            } else {
              /* no people so display nothing */
              $output = '';
            }
            
            /* set placeholders and output */
            $modx->setPlaceholders($phs,$placeholderPrefix);
            $toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
            if (!empty($toPlaceholder)) {
                $modx->setPlaceholder($toPlaceholder,$output);
                return '';
            }
            return $output;
            • discuss.answer
              • 16551 ☆ A M B ☆
              • 54 Posts
              Ok, this really seems to be a bug for the combination "getPage" with "PeopleGroup".

              Can you try this:

              1. Create a copy of "PeopleGroup" - name it "PeopleGroupGetPage" for example.

              2. In this new snippet change

              line 53
              $start = (int)$modx->getOption('start',$modx->getOption('offset',$_REQUEST,$modx->getOption('offset',$scriptProperties,0)));

              to
              $start = (int)$modx->getOption('start',$_REQUEST,$modx->getOption('offset',$_REQUEST,$modx->getOption('offset',$scriptProperties,0)));


              line 118
              $output = implode($outputSeparator,$list[$page - 1]);

              to
              $output = implode($outputSeparator,$list[0]);


              3. In your getPage call set "&element=`PeopleGroupGetPage`".
                • 36686
                • 165 Posts
                Yup, works perfectly! Brilliant, thanks labr1005 smiley