This question has been answered by sottwell. See the first response.
That's definitely a "to-do" item. Unfortunately for now it's just not available.
That's definitely a "to-do" item. Unfortunately for now it's just not available.
<?php
/* UserSettings snippet */
/* Create user settings for a particular user group */
$groupName = 'MyGroup';
$namespace = 'user_setting';
/* Set the right-hand side of the 'key' and 'value' fields. */
/* Those are the only parts of the array that are used */
$settings = array(
'setting1' => array(
'key' => 'key_1',
'value' => 'value_1',
),
'setting2' => array(
'key' => 'key_2',
'value' => 'value_2',
),
/* etc. */
);
$namespace = $modx->getObject('modNamspace', array('name' => $namespace));
if (!$namespace) {
$namespace = $modx->newObject('modNamespace');
$namespace->set('name', $namespace);
$namespace->set('path','{core_path}components/usersetting/');
$namespace->set('assets_path', '');
$namespace->save();
}
$userGroup = $modx->getObject('modUserGroup', array('name' => $groupName));
if ($userGroup) {
$ugms = $userGroup->getMany('UserGroupMembers');
foreach ($ugms as $userGroupMember) {
$id = $userGroupMember->get('member');
foreach ($settings as $setting) {
$newSetting = $modx->newObject('modUserSetting');
$newSetting->set('key', $setting['key']);
$newSetting->set('value', $setting['value']);
$newSetting->set('namespace', $namespace);
$newSetting->save();
}
}
}
