We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37777
    • 2 Posts
    Please tell me how to assign resources by adding a group, and group permissions?

    Try to do so [I am guessing]:

    transport.resources.php
    $tmp = array(
        array(
            'id' => 2,
            'pagetitle' => 'First',
            'parent' => 0,
            'alias' => 'First',
            'published' => 1,
     
            'setup_file_content' => 'fitst' /*file containing the content for this resource*/
        ),
        array(
            'id' => 3,
            'pagetitle' => 'Second',
            'parent' => 2,
            'alias' => 'Second',
            'published' => 1,
        ),
    );
    $i = 0;
    foreach($tmp as $res){
        $temp_obj = $modx->newObject('modResource');
        $temp_obj->fromArray($res, '', true, true);
        if(!empty($res['setup_file_content'])){
            $temp_obj->setContent(file_get_contents($sources['resources'].$res['setup_file_content'].'.tpl'));
        }
     
        $resources[$i] = $temp_obj;
        $i++;
    }
    unset($tmp, $temp_obj);
    return $resources;
    


    build.transport.php
    ...
     
    /* @var modResourceGroup*/
    $modx->log(xPDO::LOG_LEVEL_INFO,'Created Resource Group.');
    $ResGroup = $modx->newObject('modResourceGroup');
    $ResGroup->fromArray(array(
        'name' => 'MyGroup',
        'private_memgroup' => 0,
        'private_webgroup' => 0,
    ), '', true, true);
    $ResGroupRes = $modx->newObject('modResourceGroupResource');
     
    ...
     
    /* add resources */
    if (defined('BUILD_RESOURCE_UPDATE')) {
        $resources = include_once $sources['data'].'transport.resources.php';
        if (empty($resources)) { $modx->log(modX::LOG_LEVEL_ERROR,'... no resources to add to package.');}
        if (is_array($resources)) {
            $ResGroupRes->addMany($resources);
            $ResGroup->addMany($ResGroupRes);
        }
    }
     
    ...
     
    ///*create Resource Group vehicle*/
    $attr = array(
        xPDOTransport::UNIQUE_KEY => 'id',
        xPDOTransport::PRESERVE_KEYS => false,
        xPDOTransport::UPDATE_OBJECT => true,
        xPDOTransport::RELATED_OBJECTS => true,
        xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
            'ResourceGroupResources' => array(
                xPDOTransport::UNIQUE_KEY => array('document_group', 'document'),
                xPDOTransport::PRESERVE_KEYS => false,
                xPDOTransport::UPDATE_OBJECT => true,
                xPDOTransport::RELATED_OBJECTS => true,
                xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array(
                    'Resources' => array(
                        xPDOTransport::UNIQUE_KEY => 'id',
                        xPDOTransport::PRESERVE_KEYS => false,
                        xPDOTransport::UPDATE_OBJECT => true,
                    ),
                ),
            ),
        ),
    );
    $vehicle = $builder->createVehicle($ResGroup, $attr);
    unset($ResGroup, $attr);
    


    Thanks you!
      • 3749
      • 24,544 Posts
      This should do it by itself. It should create the resourceGroupResources for you, assuming that the group already exists at that point.

      $ResGroup->addMany($Resources);


      You might want to take a look at MyComponent, which will do much of this for you and some other things as well.
        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
        • 37777
        • 2 Posts
        Quote from: BobRay at Jul 08, 2014, 07:15 PM
        This should do it by itself. It should create the resourceGroupResources for you, assuming that the group already exists at that point.

        $ResGroup->addMany($Resources);


        You might want to take a look at MyComponent, which will do much of this for you and some other things as well.

        Thank you. Looked MyComponent, found a lot of interesting solutions. But to create a package failed - some files are missing.
        For example: config/categories.php
        As I understand it in this file is formed by an array with the names of the categories. Is supported it nesting?

        Interesting to know exactly how to create nested categories without reference to a specific id.

        Also wondering how to create nested resources and apply the newly created template.
          • 3749
          • 24,544 Posts
          Did you run both Bootstrap and ExportObjects before running the build step?

          Nested categories look like this in the config file:

          'categories' => array(
                  'Example' => array(
                      'category' => 'Example',
                      'parent' => '',  /* top level category */
                  ),
                  'category2' => array(
                      'category' => 'Category2',
                      'parent' => 'Example', /* nested under Example */
                  )
              ),


          Nested resources with specified templates look like this:

          'resources' => array(
                  'Resource1' => array( /* minimal example */
                      'pagetitle' => 'Resource1',
                      'alias' => 'resource1',
                      'context_key' => 'example',
                  ),
                  'Resource2' => array( /* example with other fields */
                      'pagetitle' => 'Resource2',
                      'alias' => 'resource2',
                      'context_key' => 'example',
                      'parent' => 'Resource1',
                      'template' => 'Template2',
                      'richtext' => false,
                      'published' => true,
                      'tvValues' => array(
                          'Tv1' => 'SomeValue',
                          'Tv2' => 'SomeOtherValue',
                      ),
                  ),
              ),
          
            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