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!