We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I'm not able to find any documentation on creating a user group and a resource group and linking them progammatically. Does anyone have experience doing this, or can point me to any documentation?
      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 docs are pretty thin on this, but here's my guess.

      /* Create User Group */
      $ugroup = $modx->newObject('modUserGroup');
      $ugroup->set('name', 'somename');
      $ugroup->set('description, 'something'); // optional
      $ugroup->set('parent', $parentId); // probably optional
      $ugroup->Set('rank', 0); // optional
      $ugroup->set('dashboard', $dashboardId'); // optional
      $ugroup->save();
      
      /* Create Resource Group */
      $rgroup = $modx->newObject('modResourceGroup');
      $rgroup->set('name', 'somename');
      $rgroup->save();
      
      /* Get the IDs of the User Group and Resource Group */
      $ugroup = $modx->getObject('modUserGroup', array('name' => 'User Group Name')); /* correct name */
      $ugroupId = $ugroup->get('id');
      
      $rgroup = $modx->getObject('modResourceGroup', array('name' => 'Resource Group Name')); /* correct name */
      $rgroupId = $rgroup->get('id');
      
      /* This part I'm not positive about, but I think it's right */
      /* Create ACL to connect the two */
      $arg = $modx->newObject('modAccessResourceGroup');
      $arg->fromArray(array(
          'principal' => $ugroupId,
          'principal_class' => 'modUserGroup',
          'target' => $rgroupId,
          'authority' => 9999, // some authority level
          'policy' => 12,  // some policy ID
          'context_key' => 'mgr',
      ));
      arg->save(); 


        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
          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
          Yep, my code above is based on that, but with some modifications and additional comments.

          I should have included a link.
            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