We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    I’m checking out the newest release of Rev and so far it’s looking damn sweet, complex as hell but I can already see the amount of work that’s been put in to it.

    I was wondering how I simply query the DB for a custom variable set against a user. I added an attribute called Token and gave it a value and it’s appearing in the DB, how do I now retrieve that using the new modx way? I checked some of the documentation and I couldn’t find where you would get custom things out the DB.

    Also how can I retrieve a specific users custom attribute using their internalKey?

    Thanks!
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 25551 ☆ A M B ☆
      • 1,231 Posts
      I have a custom var against a username in the manager and I don’t see how to extract the info anywhere in the rev docs.

      Under the user_attributes table there is an extended field and it has {"token":"1234","secret":"abcd"}

      Could someone tell me how I get these vars out of the DB in the correct way please?
        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
        AugmentBLU - MODX Partner

        BLUcart - MODX Revolution E-Commerce & Shopping Cart
        • 1778
        • 659 Posts
        Hello

        Have a look at

        http://rtfm.modx.com/display/revolution20/Users and its subpages

        http://bobsguides.com/revolution-objects.html is very helpful to understand objects in Revo...

        Cheers
          • 25551 ☆ A M B ☆
          • 1,231 Posts
          Thanks, I did check these pages out about 20 minutes ago laugh but unfortunately there’s no explanation on how to retrieve the custom options in the extended field. huh
            Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
            AugmentBLU - MODX Partner

            BLUcart - MODX Revolution E-Commerce & Shopping Cart
            • 25551 ☆ A M B ☆
            • 1,231 Posts
            Ok I tried the following which works.

            $profile = $modx->user->getOne(’Profile’);
            $feed = $profile ? $profile->get(’extended’) : ’’;

            foreach($feed as $key => $value){
            echo "
            ".$key."-".$value."
            ";
            }

            Now how do I change this to allow me to specify which user to actually search for? This display the extended params for the current user but I want to be able to display say, user ID 10. How do I do that?

            EDIT : Just copied the way you can get a resource title by id. $modx->user->getOne(’Profile’, 10) seems to work.
              Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
              AugmentBLU - MODX Partner

              BLUcart - MODX Revolution E-Commerce & Shopping Cart
              • 4041
              • 788 Posts
              You can also save extended attributes as an array:

              <?php
              $extProfileData = $modx->user->getOne('Profile')->get('extended');
              // single setting
              $extProfileData['color'] ='red';
              // array
              $extProfileData['userOptions'] = array(
                          'option1' => 'option 1 subvalue',
                          'option2' => 'option 2 subvalue'
                          );
              
              $modx->user->Profile->set('extended', $extProfileData);
              $modx->user->Profile->save();


              Then retrieve the values to use:
              <?php
              $user_ext_profile = $modx->user->getOne('Profile')->get('extended');
              
              if ($user_ext_profile) {
                  foreach ($user_ext_profile as $key => $value) {
                      if (is_array($value)) {
                          $extended_profile_data .=$key.':<br>';
                              foreach ($value as $key2 => $value2) {
                                  $output .='  '.$key2 .': '. $value2 .'<br>';
                              }
                      } else {
                          $output .=$key .': '. $value .'<br>';
                      }
                  }
              }
              return $output;
              


              Only problem is that the extended settings arrays cannot be modified by the user in the profile edit yet, you have to manage them via script. I attached a test file I was fiddling with, perhaps it could be useful.
                xforum
                http://frsbuilders.net (under construction) forum for evolution
                • 25551 ☆ A M B ☆
                • 1,231 Posts
                Thanks Breezer, will check that out.

                I’m actually trying to create a small site to keep track of the usage of some of my custom mootools scripts via a token. I want to see if I can do this using the new modx platform as it seems like it has a ton of options that will be needed, example is the custom user attributes. I can generate the tokens there and match them up to that users details including the domain that the script will be used on, limit the usage with the referring domain name as well so it can’t be simply hotlinked from any other site. I have started writing the script and it’s already working how I want it, using cURL.

                I’m simply using vars in the url with the token, userID and domain to check against the database on the site and if any of the options do not match up then the script is not available. I’ll need to think of a way to best encrypt or scramble the information in the url being passed, such as the userID, it’s just simply 1,2 or what ever. But the concept is working. Any ideas what would be the safest method to pass details through the domain url so it can be checked?

                Currently the link to a script will look similar to this...

                http://www.domain.co.uk/scrollerscript.js?domain=mysite.co.uk&token=wEJASwadrayAPH5dr8ratu&user=1


                The scrollerscript.js page is a blank modx javascript document with the snippet that checks the url information and matches it against the user_attributes table in modx via cURL. I’m not sure which is the best way to initiate the query as I don’t know REV at all so using user=1 knows to check the token and the domain against that users information. How safe this is, I don’t know but if I can somehow make this a little more secure then any ideas would be great.

                  Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                  AugmentBLU - MODX Partner

                  BLUcart - MODX Revolution E-Commerce & Shopping Cart