function _autoassignrole_get_settings in Auto Assign Role 6.2
Same name and namespace in other branches
- 6 autoassignrole.module \_autoassignrole_get_settings()
API function that returns an array of AAR's settings.
8 calls to _autoassignrole_get_settings()
- AAR::validate in tests/
autoassignrole.test - Helper function that compares the edit array to AAR settings
- AutoassignroleAdminAllowUserChoiceTestCase::testAdminSettings in tests/
autoassignrole.test - AutoassignroleAdminAssignFromPathTestCase::testAdminSettings in tests/
autoassignrole.test - AutoassignroleAdminAutoRoleTestCase::testAdminSettings in tests/
autoassignrole.test - autoassignrole_admin_form in ./
autoassignrole-admin.inc - Admin form handler.
File
- ./
autoassignrole.module, line 264 - The main autoassignrole.module file
Code
function _autoassignrole_get_settings($value) {
// if we are dealing with a variable in the format of path_field_rid get
// variables from {autoassignrole_page}
if (preg_match('/^path_(\\D[^_]*)_(\\d*)/i', $value, $matches)) {
$result = db_fetch_array(db_query("SELECT rid, display, path, title, description, format, weight FROM {autoassignrole_page} WHERE rid = %d", $matches[2]));
if (count($result) > 1 && $matches[1] == 'active') {
return 1;
}
elseif (count($result) == 1 && $matches[1] == 'active') {
return 0;
}
else {
if (isset($result[$matches[1]])) {
return $result[$matches[1]];
}
else {
return FALSE;
}
}
}
if (preg_match('/^path_(\\d*)/i', $value, $matches)) {
$result = db_fetch_array(db_query("SELECT path FROM {autoassignrole_page} WHERE rid = %d", $matches[1]));
if (isset($result['path'])) {
return $result['path'];
}
else {
return FALSE;
}
}
// if we are not dealing with {autoassignrole_page} then get variables from
// {autoassignrole}
$settings = array();
$result = db_query("SELECT arid, value from {autoassignrole}");
while ($s = db_fetch_object($result)) {
$settings[$s->arid] = $s->value;
}
// break apart auto_roles[x] and user_roles[x]
if (preg_match('/^(\\D[^_]*_\\D[^_]*)\\[(\\d*)]/i', $value, $matches)) {
$values = unserialize($settings[$matches[1]]);
return $values[$matches[2]];
}
switch ($value) {
case 'auto_roles':
case 'user_roles':
// return all instances as an array
$roles = $settings[$value];
$roles = unserialize($roles);
if (!is_array($roles)) {
$roles = array();
}
foreach ($roles as $k => $r) {
if ($r == 0) {
unset($roles[$k]);
}
}
return $roles;
break;
default:
if (isset($settings[$value])) {
return $settings[$value];
}
else {
return FALSE;
}
break;
}
}