We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31837
    • 59 Posts
    Hi all,
    I'm having trouble trying to find out how to get the values from a User's Group.

    Basically, I'd like to be able to get a custom API key that is stored with the User's Group. This is the beginning of creating an admin interface to be able to send push notifications for clients.

    For example: (2 groups)

    Group: Steve's Cars
    Users: Steve, Andrew
    OneSignalAPIkey: 123456789
    GoogleAPIKey: AAAAAA123
    
    
    Group: John's Phones
    Users: John
    OneSignalAPIkey: 111111129
    GoogleAPIKey: BBBBBB123



    I looked at the getOption() examples and Mark's ClientConfig, but maybe I'm doing it wrong or I'm using the wrong tools.

    I'd like to be able to set up a call, where my code can just go and get the correct value OneSignalAPIkey, when a user asks for it.

    If client "Steve" needs to send a push notication, then modx would need get the correct OneSignalAPIkey value stored in the relevant group settings.

    I have a snippet (originally copied from the internet) like this, which is returning "No Key"

    $key = $modx->getOption('OneSignalAPIkey', $scriptProperties, '', true);
    if (!empty($key)) {
        $setting = $modx->getObject('modUserSetting', array('key' => $key), false);
        if ($setting) {
            $output = $setting->get('value');
        } else {
            $output = 'Could not get setting object';
        }
    } else {
        $output = 'No Key';
    }
    echo $key;
    echo $output;


    Thanks.
      • 31837
      • 59 Posts
      I think it's going to be faster to do a native solution.
      Sorry for wasting your time.
        • 3749
        • 24,544 Posts

        It sounds like the setting is a group setting, not a user setting. If so, try this:

        $setting = $modx->getObject('modUserGroupSetting', array('key' => $key), false);


        If there is more than one user group with that key, you'll also need to specify the user group ID in your criteria array.

          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