We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m at a loss to figure out what runProcessor wants in the resource_groups property.

    It clearly wants a JSON version of some array, but I hate to experiment when writing to the DB.

    Couldn’t it just be a comma-delimited list of resource group names or IDs (preferably both using is_numeric).








      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
      • 3749
      • 24,544 Posts
      El Bumpo.

      Still need an answer to this one.
        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
        • 28215
        • 4,149 Posts
        Do a save the modx manager where you change the Resource Groups on a Resource. Then use firebug/console/whatever to inspect the POST array sent. I’m not exactly sure on the format atm. tongue
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 3749
          • 24,544 Posts
          I couldn’t get anything from the $_POST for some reason, but I got it by writing the de-JSON’s array to the error log in the processor.

          Array
          (
              [1] => Array
                  (
                      [id] => 1
                      [name] => HiddenTvs
                      [access] => 1
                      [menu] => 
                  )
          
              [3] => Array
                  (
                      [id] => 3
                      [name] => NewPrivate
                      [access] => 
                      [menu] => 
                  )
          
              [4] => Array
                  (
                      [id] => 4
                      [name] => NewPrivateTwo
                      [access] => 
                      [menu] => 
                  )
          
              [2] => Array
                  (
                      [id] => 2
                      [name] => Private
                      [access] => 1
                      [menu] => 
                  )
          
          )


          Do you know if it’s necessary to include all the groups from the template and to have the outer array keys match the group ID? If so, it might be easier to just create/modify the resourceGroupResources myself rather than having the processor do it.
            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
            • 28215
            • 4,149 Posts
            No, it is not. It refers to it as $resourceGroupAccess[’id’], so you should be fine just putting the ID in the array.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 3749
              • 24,544 Posts
              Quote from: splittingred at Dec 16, 2010, 08:58 AM

              No, it is not. It refers to it as $resourceGroupAccess[’id’], so you should be fine just putting the ID in the array.

              Thanks.

              It looks like I just need to send the ones I want to change.

              BTW, it looks to me like if you send the ID of a non-existent group in the JSON string, the create and update processors will create resourceGroupResource objects for groups that don’t exist, without creating the resource groups themselves. In that case the resourceGroupResource will point to a nonexistent group with no name.

              <?php
              if (!empty($resourceGroupAccess['access'])) {
              
                    // Should probably check for existence of modResourceGroup here first, and if it doesn't exist,
                    // create it using $resourceGroupAccess['name'] and then get its ID for the next step.
                    // ( or else just skip the group assignment altogether for nonexistent groups).
              
                   $resourceGroupResource = $modx->getObject('modResourceGroupResource',array(
                          'document_group' => $resourceGroupAccess['id'],
                          'document' => $resource->get('id'),
                          ));
                   if (empty($resourceGroupResource)) {
                        $resourceGroupResource = $modx->newObject('modResourceGroupResource');
                   }
                   $resourceGroupResource->set('document_group',$resourceGroupAccess['id']);
                   $resourceGroupResource->set('document',$resource->get('id'));
                   $resourceGroupResource->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
                • 28215
                • 4,149 Posts
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 3749
                  • 24,544 Posts
                    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