We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42239
    • 73 Posts
    Anyone know how to call an extended field using the Rowboat snippet?

    stored in extended field in user attributes as:
    {"directoryinclude":"yes"}

    This is my attempt.

    [[!Rowboat?
    &table=`modx_user_attributes`
    &tpl=`membershipDirectory`
    &limit=`0`
    &columns=`{"fullname":"","email":""}`
    &where=`{"extended.directoryinclude:=":"yes"}`
    &sortBy=`fullname`
    ]]

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

      • 3749
      • 24,544 Posts
      Have you looked at the Peoples package? I think that would be better for what you're trying to do.

      RowBoat is mainly for non-MODX tables and it doesn't handle extended fields.
        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
        • 42239
        • 73 Posts
        Quote from: BobRay at Mar 27, 2013, 07:30 PM
        Have you looked at the Peoples package? I think that would be better for what you're trying to do.

        RowBoat is mainly for non-MODX tables and it doesn't handle extended fields.

        I checked Peoples out, thanks for the suggestion.
        Doesn't Peoples still give me the same problem? Peoples allows me to output the extended data I need with a placeholder, but I really need something that will parse the extended field. Does Peoples do this and I missed it in the wiki instructions? Looks like this may require something custom. Unless I can get login.UpdateProfile to write a value to a field instead of creating a json key and value in the extended field. Is that possible? That would solve my problem as well I could just use rowboat in that case.
        Unfortunately I can't just loop the people based on their user-group which would be pretty straight forward. They have to select that they want to be listed and they could be in one of 13 user-groups.
        • discuss.answer
          • 3749
          • 24,544 Posts
          There's no easy way that I know of to create a query that will select by extended fields. What I usually do in cases like yours is re-purpose an unused field of the User Profile like 'comment' or 'fax'. That method has less of an advantage for you because you don't really need the User object, just the User Profile.


          I think you want something like this (untested):

          <?php
          /* ShowUsers snippet */
          $output = '';
          
          /* get all User Profiles */
          $profiles = $modx->getCollection('modUserProfile');
          
          
          foreach ($profiles as $profile) {
          
            $extended = $profile->get('extended');
          
            if ($extended['directoryinclude'] == 'Yes') {
                /* found one -- add to output */
                $fields = $profile->toArray();
                $output .= $modx->getChunk('MembershipDirectory', $fields);
            }
          }
          
          return $output;


          Note that the extended fields won't be available in the Tpl chunk, but if you need them, you can add them to the $fields array with:

          $fields = array_merge($fields, $extended);
          [ed. note: BobRay last edited this post 13 years, 6 months ago.]
            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
            • 42239
            • 73 Posts
            Quote from: BobRay at Mar 28, 2013, 02:02 PM
            There's no easy way that I know of to create a query that will select by extended fields. What I usually do in cases like yours is re-purpose an unused field of the User Profile like 'comment' or 'fax'. That method has less of an advantage for you because you don't really need the User object, just the User Profile.


            I think you want something like this (untested):

            <!--?php
            /* ShowUsers snippet */
            $output = '';
            
            /* get all User Profiles */
            $profiles = $modx--->getCollection('modUserProfile');
            
            
            foreach ($profile as $profile) {
            
              $extended = $profile->get('extended');
            
              if ($extended['directoryinclude'] == 'Yes') {
                  /* found one -- add to output */
                  $fields = $profile->toArray();
                  $output .= $modx->getChunk('MembershipDirectory', $fields);
              }
            }
            
            return $output;


            YES!!!! Thank You! This worked exactly how I needed it too! only change '$profiles =' to '$profile =' to match but yes worked great. I attempted this but I'm not that great with the MODX api i'm a noobie.

            I can't say enough about how great the MODX community is!
              • 3749
              • 24,544 Posts
              Should be the other way around -- change just the one in the foreach(). I corrected it in my post above.

              Glad it works for you. smiley

                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
                • 42239
                • 73 Posts
                Quote from: BobRay at Mar 28, 2013, 02:33 PM
                Should be the other way around -- change just the one in the foreach(). I corrected it in my post above.

                Glad it works for you. smiley


                Yup, thats it! Thanks again, BobRay saved the day.