-
☆ 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?
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();
-
☆ A M B ☆
- 24,524 Posts
Yep, my code above is based on that, but with some modifications and additional comments.
I should have included a link.