We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49659
    • 86 Posts
    Hi Bob,

    For what it's worth, here is the contents of the target template. The <head> values are the same as the default template, and that works fine:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    [[$METATagChunk]]
    <title>[[*longtitle]]</title>
    <base href="[[++base_url]]" />
    [[!JS_CSS_to_HEAD]]
    </head>
    <body>
    [[*content]]
    <div class="closeWindow">
    <form>
    <input class="btn-CSS" type="button" value="Close Window" onClick="window.close()">
    </form>
    </div>
    </body>
    </html>


    Karl
      • 13428 ☆ A M B ☆
      • 1,031 Posts
      How does GetExtUsersCustom work? Is there any (example) code visible.
        • 49659
        • 86 Posts
        Hi Jako,

        Sure, here's the full code for 'GetExtUsersCustom'. I commented out Bob Ray's original code, and added START and STOP comments where I added my own replacement code. I'm not an experienced PHP programmer, so no doubt it could be more elegant, but at least it works. smiley

        <?php
        /**
         * GetExtUsers snippet for ClassExtender extra
         *
         * Copyright 2012-2014 by Bob Ray <http://bobsguides.com>
         * Created on 01-05-2014
         *
         * Customized by Karl Forsyth, 9/16/15
         * 
         * ClassExtender 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.
         *
         * ClassExtender 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
         * ClassExtender; if not, write to the Free Software Foundation, Inc., 59 Temple
         * Place, Suite 330, Boston, MA 02111-1307 USA
         *
         * @package classextender
         */
        
        /**
         * Description
         * -----------
         * Show user information
         *
         * Variables
         * ---------
         *
         * @var $modx modX
         * @var $scriptProperties array
         *
         * @package classextender
         **/
        
        /* The extendeduser package should be pre-loaded
           due to being registered in the extension_packages
           System Setting */
        
        $modx->lexicon->load('classextender:default');
        
        
        /* @var $scriptProperties array */
        $scriptProperties = isset($scriptProperties)
            ? $scriptProperties
            : array();
        $sp = $scriptProperties;
        
        $userClass = $modx->getOption('userDataClass', $sp, 'userData');
        
        $where = $modx->getOption('where', $sp, array());
        
        $where = !empty($where)
            ? $modx->fromJSON($where)
            : array();
        
        /** START added by Karl */
        $listGroupId = 0;
        foreach($where as $key => $element) {
            $keyName = 'UserGroupMembers.user_group';
            $pos = strpos($key, $keyName);
            if($pos !== false) {
                $listGroupId = $element;
                //$modx->log(modX::LOG_LEVEL_ERROR, '[GetExtUsersCustom] ' . $key . $element);
                break;
            }
        }
        $userGroupObj = $modx->GetObject('modUserGroup', array ('id'=>$element) );
        $userGroupName = $userGroupObj->get('name');
        //$modx->log(modX::LOG_LEVEL_ERROR, '[GetExtUsersCustom] Group name: ' . $userGroupName);
        $modx->toPlaceholder('groupName',$userGroupName,'');
        
        date_default_timezone_set("America/Los_Angeles");
        $datePrinted = date("m/d/Y, g:i a");
        $modx->toPlaceholder('datePrinted',$datePrinted,'');
        /** END added by Karl */
        
        $outerTpl = $modx->getOption('extUserOuterTpl', $sp, 'extUserOuterTpl');
        $innerTpl = $modx->getOption('extUserInnerTpl', $sp, 'extUserInnerTpl');
        $rowTpl = $modx->getOption('extUserRowTpl', $sp, 'extUserRowTpl');
        $sortBy = $modx->getOption('sortby', $sp, 'username');
        $sortDir = $modx->getOption('sortdir', $sp, 'ASC');
        
        //$c = $modx->newQuery($userClass);
        
        /** START added by Karl */
        $c = $modx->newQuery('modUser');
        $c->innerJoin('modUserProfile', 'Profile');
        $c->innerJoin('modUserGroupMember', 'UserGroupMembers');
        $c->innerJoin('userData', 'UD', 'UD.userdata_id = modUser.id');
        $c->select($modx->getSelectColumns('modUser', 'modUser', '', array('id', 'username')));
        $c->select($modx->getSelectColumns('userData', 'UD', 'data_'));
        $c->select($modx->getSelectColumns('modUserProfile', 'Profile', 'profile_',
            array('id', 'internalKey', 'fullname', 'email', 'extended')));
        $c->select($modx->getSelectColumns('modUserGroupMember', 'UserGroupMembers', 'group_',
            array('id', 'user_group', 'member')));
        /** END added by Karl */
        
        $c->sortby($sortBy, $sortDir);
        $c->where($where);
        
        //$users = $modx->getCollectionGraph($userClass, '{"Profile":{},"User":{}}', $c);
        
        /** START added by Karl */
        $users = $modx->getCollection('modUser', $c);
        /** END added by Karl */
        
        $count = count($users);
        
        //$modx->log(modX::LOG_LEVEL_ERROR, '[GetExtUsersCustom] count = ' . $count);
        
        if (!$count) {
            return $modx->lexicon('ce.no_users_found');
        
        }
        
        /* @var $user modUser */
        $i = 0;
        $outer = $modx->getChunk($outerTpl);
        
        $output = '';
        $innerOutput = '';
        foreach ($users as $user) {
            $fields = $user->toArray();
            unset($fields['password'], $fields['cachepwd'], $fields['salt'], $fields['hash_class']);
            /*
            if ($user->Profile) {
                $fields = array_merge($user->Profile->toArray(), $fields);
            }
            if ($user->User) {
                $fields = array_merge($user->User->toArray(), $fields);
            }
            */
            
            $inner = $modx->getChunk($innerTpl, $fields);
            $row = $modx->getChunk($rowTpl, $fields);
            $innerOutput .= str_replace('[[+extUserRow]]', $row, $inner);
            $i++;
        }
        
        $output = str_replace('[[+extUserInner]]', $innerOutput, $outer);
        
        return $output;
          • 13428 ☆ A M B ☆
          • 1,031 Posts
          Could you add the property set content to the snippet call please? Think it does not get the userDataClass. [ed. note: Jako last edited this post 11 years ago.]
            • 49659
            • 86 Posts
            Hi Jako,

            It turns out that I didn't need the custom property set. I created it early on when I was working on the 'GetExtUsers' customization, but didn't end up changing any properties. So the custom set and the default set are identical. I removed the custom property set call, and the snippet still works fine with the default template:
            [[!GetExtUsersCustom?
                &sortby=`lastName`
                &sortDir=`ASC`
                &extUserOuterTpl=`ExtUserOuterTplCustom`
                &extUserInnerTpl=`ExtUserInnerTplCustom` 
                &extUserRowTpl=`ExtUserRowTplCustom`
                &where=`{"UserGroupMembers.user_group:=":"6"}`
            ]]


            The value for the 'userDataClass' property is still 'userData', which is the unchanged default value. However, the 'userDataClass' property is not used at all in my customized snippet. It is commented out.

            Karl
              • 49659
              • 86 Posts
              Sorry, I meant that it's commented out at this point in the code:
              //$c = $modx->newQuery($userClass);
                • 49659
                • 86 Posts
                One other thing - giving credit where credit is due, the part of my 'GetExtUsers' customization with the innerjoin(...) and select(...) calls are 'borrowed' from code I got from Mark Hamstra. I'm not good enough at MODX programming to have sorted that part out myself. ;-)
                  • 13428 ☆ A M B ☆
                  • 1,031 Posts
                  Two things to check in the snippet code:
                  Is $users empty (maybe $modx->lexicon('ce.no_users_found') is empty so you don't see an error message)?
                  Does the content of ExtUserRowTplCustom break the output of the snippet (maybe the PeopleGroups snippet call)

                  And one thing in SwitchTemplate:
                  Have you tried the config uncached?
                    • 49659
                    • 86 Posts
                    Hi Jako,

                    I checked the $modx->lexicon('ce.no_users_found') entry, and it contains the prompt 'No Users Found'. I then uncommented the following modx log entry showing the user count:
                    $modx->log(modX::LOG_LEVEL_ERROR, '[GetExtUsersCustom] count = ' . $count);


                    For both the default template and the switched template, the user count is the same. So, the users are there in both cases (default and switched):
                    [2015-09-19 20:19:20] (ERROR @ /index-dev.php) [GetExtUsersCustom] count = 4
                    [2015-09-19 20:19:42] (ERROR @ /index-dev.php) [GetExtUsersCustom] count = 4


                    I also tried setting the SwitchTemplate config to uncached, and there was no change. I ran [Manage-Clear Cache] after making that change to the setting and before testing it.

                    Finally, I tried removing this code from the 'ExtUserRowTplCustom' chunk:
                    <ul>
                    [[PeopleGroups? &user=`[[+id]]` &limit=`0`]]
                    </ul>


                    ...and it had no effect. The users data still does not appear in the switched template.
                      • 13428 ☆ A M B ☆
                      • 1,031 Posts
                      Two last tries (I am out after this):
                      Does the switchTemplate output change, if you change the templates content (to detect output caching issues)?
                      Look if $inner is empty by putting die($inner) in the code. Look if $row is empty the same way.