function services_client_process_roles_mapping in Services Client 7
Create mapping of roles from remote site
Parameters
$account: User account
$data: User object data
$mapping: Mapping of remote roles
$client: Connection client to remote site
$conn_name: Name of the remote connection
1 call to services_client_process_roles_mapping()
- services_client_make_user_call in ./
services_client.module - Make the actual user create/update call for each connection and task
File
- ./
services_client.module, line 1118 - Services client module allows to push different types of objects on different types of events such as node_save, user_save to remote masters.
Code
function services_client_process_roles_mapping($account, &$data, $mapping, &$client, $conn_name) {
// Build role mapping
$lines = explode("\n", trim($mapping));
$roles = array();
foreach ($lines as $line) {
if (!empty($line)) {
list($local, $remote) = explode("|", $line);
$roles[trim($local)] = trim($remote);
}
}
// If there is some mapping for roles
if (count($roles)) {
// Check if user has some role that needs to be mapped
if (count(array_intersect($account->roles, array_keys($roles)))) {
// Retrieve roles with role ids from remote site
$remote_roles = services_client_get_remote_roles($conn_name, $client);
// Prepare roles array that is going to be sent to remote site
$data->roles = isset($data->roles) ? $data->roles : array();
// Map roles
foreach ($roles as $local_role => $remote_role) {
// Check if local account has local role and if remote role exists
if (in_array($local_role, $account->roles) && ($key = array_search($remote_role, $remote_roles))) {
// Add role to data
$data->roles[$key] = $remote_role;
}
}
}
}
}