7

I need to expose OG memberships within API functions calls and wonder how to programmatically subscribe a user to a group (pending state) and then i need to approve him programmatically and change from pending to member. Im using OG 7.2.

function ask_membership($uid, $gid){
  ????
}

function approve_membership($uid, $gid){
  ????
}

Any help appreciated

0

1 Answer 1

4

Ok got it working, its still the og_group() function.

function group_membership($type, $gid, $uid){
  $group_type = 'node'; //All our/my groups are of type node
  $entity_type = 'user'; //All our/my members are type users
  $values = array(
    'entity_type' => 'user',
    'entity' => $uid,
    'field_name' => FALSE,
    'state' => 1,
  );
  $return = FALSE;

    switch ($type){
        case 'subscribe':
          $values['state'] = 2;
          og_group($group_type, $gid, $values);
        $return = 'SUBSCRIBED TO TEAM';
          break;
      case  'approve':
          $values['state'] = 1;
          og_group($group_type, $gid, $values);
        $return = 'APPROVED TO TEAM';
        break;
      case 'delete':
        og_ungroup($group_type, $gid, $entity_type, $uid);
        $return = 'REMOVED FROM TEAM';
        break;
      default:
        $return = 'FALSE TYPE';
        break;
    }

  print json_encode($return); 
}

Not that pretty but it works for now.

2
  • Thanks for sharing this, I think it's great overall. I don't understand the purpose of $url, so I'm going to try and run it without that param.
    – Jav
    May 6, 2014 at 17:39
  • Thx, think i removed some code that wasn't useful and it might be a left over :) Dec 2, 2014 at 15:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.