2

I have a function that allows me to create users from the data of an external database:

  function _loginuser_authenticate_validate($form, &$form_state) {
    global $user;

    // Use external database.
    db_set_active('external_database');
    // … 
  }

Now I want to create, for each user from the external database, two groups (each group with four Drupal users, a group administrator, and three normal members).
I can create a group with og_insert_group($node);. I can also create an admin for this group with og_save_subscription($node->nest, $node->uid, array ('is_active' => 1, 'is_admin' => 1));.

I don't know how to create multiple groups, and add members to these groups. I also do not know where to put the code to create groups in the LoginUser module, or in another module.

2 Answers 2

0

Your explanation seems a little bit confused. Creation of an OG is as simply as creating a node.

So from what I understood you wish :

  1. Get a user data from external source (how you perform this ? by cron ?)
  2. Create a group for each user
  3. Assign that user as group admin ?

Is it what you want to perform ?

Also take a look here :

http://drupalcontrib.org/api/drupal/contributions%21og%21og.module/7

0

You can definitely use the Rules module to auto-create the groups when the users are registered. If you already have the users you want to add to the groups created you should be able to also add an action to add the group members using a rule as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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