Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Get all users
- */
- $query = db_select('users', 'u')->condition('u.uid', 0, '<>')->fields('u', array('uid'));
- $result = $query->execute();
- /**
- * Loop trough all the users
- */
- foreach ($result as $user) {
- /**
- * Load a user
- */
- $user = user_load($user->uid);
- /**
- * Double check/safe
- */
- if ($user) {
- /**
- * Check if user has value in local group id field
- */
- if (isset($user->field_local_group_id[LANGUAGE_NONE][0]['value']) && !empty($user->field_local_group_id[LANGUAGE_NONE][0]['value'])) {
- /**
- * Get local groups node
- */
- $localGroup = node_load($user->field_local_group_id[LANGUAGE_NONE][0]['value']);
- /**
- * Double check/safe
- */
- if ($localGroup) {
- $values = array(
- 'entity_type' => 'user',
- 'entity' => $user,
- 'state' => OG_STATE_ACTIVE,
- 'membership_type' => OG_MEMBERSHIP_TYPE_DEFAULT
- );
- /**
- * Setup a group
- */
- og_group('node', $localGroup->nid, $values);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement