function do_modify_slice_membership($selections, $slice_id, $slice_members_by_role)
{
    global $sa_url;
    global $user;
    $members_to_add = array();
    $members_to_change_role = array();
    $members_to_remove = array();
    //  error_log("Selections = " . print_r($selections, true));
    //  error_log("SMBR = " . print_r($slice_members_by_role, true));
    foreach ($selections as $member_id => $selection_id) {
        $is_member = array_key_exists($member_id, $slice_members_by_role);
        if ($is_member) {
            $role = $slice_members_by_role[$member_id];
            if ($selection_id == 0) {
                // Remove this member from this slice
                $members_to_remove[] = $member_id;
            } else {
                if ($selection_id != $role) {
                    // Change the role of this member on this slice
                    $members_to_change_role[$member_id] = $selection_id;
                }
            }
        } else {
            if ($selection_id > 0) {
                // Add member to slice
                $members_to_add[$member_id] = $selection_id;
            }
        }
    }
    // Publish changes atomically to SA
    $result = modify_slice_membership($sa_url, $user, $slice_id, $members_to_add, $members_to_change_role, $members_to_remove);
    return $result;
}
Beispiel #2
0
function change_slice_member_role($sa_url, $signer, $slice_id, $member_id, $role)
{
    $member_roles = array($member_id => $role);
    $result = modify_slice_membership($sa_url, $signer, $slice_id, array(), $member_roles, array());
    return $result;
}