We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38666
    • 98 Posts
    I have extended my users following Bob Ray's ClassExtender. I would now like to include the extended fields in a query listing our users by state. This code works to a point, but what is the correct syntax to include the extended Data fields. Any suggestions,hints, or not so gentle prompting would be most welcome at this point.
    $csaacP = "AB"; 
    $csaacmember = $modx->getCollection('modUserProfile',array('state'=>$csaacP));
    
    foreach($csaacmember as $Pmembers) {
        $fields = $Pmembers->toArray();
        $output .= $modx->getChunk('UsersProvTpl', $fields);
    }
    return $output;
    


    Thanks
    Jim

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

      Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
    • Have you looked at the GetExtUsers snippet that is part of the ClassExtender package?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 38666
        • 98 Posts
        Quote from: sottwell at Dec 19, 2014, 04:29 PM
        Have you looked at the GetExtUsers snippet that is part of the ClassExtender package?
        Thanks Susan. I tried that even though it is designed to search on the extended (Data) fields rather than the user profile. Searching on and extended field "LastName" for example returns all entries in the database. Can't for the life of me see how to search the profile by state and pick up the extended fields for each user. Problby have been trying too hard and too long.
          Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
        • You should be able to use the "where" property. This looks like it works pretty much the same way that getResources' "where" property works, it takes a JSON string of key: value pairs, so something like
          &where=`{"state:=":"AB"}`

          That should give you placeholders like [[+user.username]], [[+profile.email]] and [[+customfield]] (no prefix).
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            The main point of extending the modUser object is to *avoid* using the user extended fields altogether. You create Data fields based on them, then write a quick utility snippet to move the existing values to the data table.

            That said, you could try the Profile snippet with &useExtended. The Peoples extra might also be an option.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
            • Bob, we're talking about an extended user class, and how to use the getExtUser snippet that comes with it, using its &where= property.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 3749
                • 24,544 Posts
                Sorry, I was temporarily brain-dead.

                Here's one way to do it (not the fastest, but probably fast enough):

                $output = '';
                $csaacP = "AB";
                $csaacmember = $modx->getCollection('modUserProfile',array('state'=>$csaacP));
                 
                foreach($csaacmember as $Pmembers) {
                    /* get user ID from profile object */
                    $userId = $Pmembers->get('internalKey');
                
                    /* get extended fields */
                    $data = $modx->getObject('userData', array('userdata_id' => $userId);
                
                    $fields = array_merge ($Pmembers->toArray(), $data->toArray() );
                
                    /* Set $fields['id'] to true user ID */
                    $fields['id'] = $userId;
                
                    $output .= $modx->getChunk('UsersProvTpl', $fields);
                }
                return $output;
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                • discuss.answer
                  • 4172
                  • 5,888 Posts
                  another way with migxLoopCollection - snippet could be:

                  [[migxLoopCollection?
                  &classname=`modUserProfile`
                  &joins=`[{"alias":"Data","classname":"userData","on":"Data.userdata_id=modUserProfile.internalKey"}]`
                  &where=`{"modUserProfile.state":"AB"}`
                  &tpl=`UsersProvTpl`
                  ]]


                  In your chunk, you would have all UserProfile - fields and and all userdata-fields prefixed with 'Data_' in this case.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 3749
                    • 24,544 Posts
                    That's really nice Bruno. It should be much faster than my version since yours will make one query to the DB and mine will make one for each user.

                    I was considering doing something similar with getCollectionGraph() but was too lazy to work it out. wink

                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 38666
                      • 98 Posts
                      Thanks guys! Once again you have saved the day. I knew if anyone could help it would be one of you.

                      Cheers
                        Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.