We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18174
    • 116 Posts
    I tried this
    <?php
    foreach($modx->resource->getGroupsList() as $resourcegroups){  
      if(is_array($resourcegroups)) {
        foreach ($resourcegroups as $resourcegroup) {
          if ($resourcegroup->get('access')==='1') {
         	foreach ($resourcegroup->getUserGroups() as $usergroups) {
        	  var_dump($usergroups->toArray());
    	}
          }
        }
      }
    }

    but the result isn't as expected. $resourcegroup->getUserGroups() still returns akind of a resourcegroup object.
    Any ideas?
    Best regard
    manu
      • 4172
      • 5,888 Posts
      does this work?

      <?php
      
      if ($resourcegroups = $modx->resource->getGroupsList()) {
          foreach ($resourcegroups as $resourcegroup) {
              if ($resourcegroup->get('access') === '1') {
                  if ($usergroups = $resourcegroup->getUserGroups())
                  foreach ($usergroups as $usergroup) {
                      var_dump($usergroup->toArray());
                  }
              }
          }
      }
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        As far as I can tell getUserGroups returns an array of id => string where the second is a modUserGroup name (I don't have any user group ACLs in my local install so I can't be sure).

        Calling toArray() on it shouldn't work. echo $userGroup should.


        This might be another way to go:

        $resource->getMany('ResourceGroupResources')
        [ed. note: BobRay last edited this post 13 years, 7 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
          • 18174
          • 116 Posts
          @Bruno: Unfortunately no. getGroupsList() returns an array with two entries: the first is the resourceGroup Collection, the second the total of resourceGroups. What's a bit strange to me, it seems to return all the resourcegroups available in the system, with access ==='1' in the resourceGroups actually linked to.

          @Bob: This could be (the hard) way. Via 'ResourceGroup' I come to 'modResourceGroup'. But out of the schema I don't find the linkage from 'modResourceGroup' to 'modUserGroup'.
            • 3749
            • 24,544 Posts
            modResourceGroup->getMany('Acls') will get you all the modAccessResourceGroup objects, but you're right, it's obscure and your original method should be better since they would, in theory, be organized.
              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