We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I'm using the dob field to time a trial period.

    I need to use getCollection() (or getCollectionGraph() ) to get the username, fullname, and email address of users who are more than 14-days old. I'll also need a reference to the user object for those users.

    I could just get the modProfiles of users that meet the criteria and get the user objects with getObject(), then pull the fields directly with get(), but I suspect that a single query would be much faster.

      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
      • 3548
      • 102 Posts
      Hi,

      this should do it:

          $criteria=$modx->newQuery('modUser');
          $criteria->innerJoin('modUserProfile','Profile');  
          $criteria->where(array(
               'Profile.city' => 'Zagreb',
          ));
          $users=$modx->getCollectionGraph('modUser', '{ "modUserProfile":{} }',$criteria);
          foreach ($users as $user) {
            echo $user->username;
            $profile=$user->getOne('Profile');
            echo $profile->city;    	
          }
      
      


      P.S. I used city for criteria from modUserProfile, but you got idea.
      Feel free to ask if you have additional questions.
        Antonio Zdilar
        linearvector.com
        • 3749
        • 24,544 Posts
        Thanks. I ended up using getIterator() because I needed to filter by user group as well.

        Don't know my post got double-posted.


        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODx info for everyone: http://bobsguides.com/modx.html
          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