/**
  * Create a user with a given set of permissions. The permissions correspond to the
  * names given on the privileges page.
  *
  * @param $role
  *   Role for the user: admin, manager, user
  * @param $groups
  *   Optional: An array of group nids or group node objects to which the newly
  *   created account should be a member of.
  * @return
  *   A fully loaded user object with pass_raw property, or FALSE if account
  *   creation fails.
  */
 function atriumCreateUser($role = 'user', $groups = array())
 {
     // Abbreviate 'authenticated user' to just 'user'.
     $role = $role === 'user' ? 'authenticated user' : $role;
     $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role));
     if ($rid) {
         // Create a user assigned to that role.
         $edit = array();
         $edit['name'] = $this->randomName();
         $edit['mail'] = $edit['name'] . '@example.com';
         $edit['roles'] = array($rid => $rid);
         $edit['pass'] = user_password();
         $edit['status'] = 1;
         $account = user_save('', $edit);
         // Add groups.
         if (!empty($account->uid) && !empty($groups)) {
             foreach ($groups as $value) {
                 $gid = is_object($value) && !empty($value->nid) ? $value->nid : $value;
                 og_save_subscription($gid, $account->uid, array('is_active' => TRUE));
             }
             // Reload user account with OG associations.
             og_get_subscriptions($account->uid, 1, TRUE);
             // Reset static cache.
             $account = user_load($account->uid);
         }
         $this->assertTrue(!empty($account->uid), t('User created with name %name, pass %pass and mail %mail', array('%name' => $edit['name'], '%pass' => $edit['pass'], '%mail' => $edit['mail'])), t('User login'));
         if (!empty($account->uid)) {
             // Add the raw password so that we can log in as this user.
             $account->pass_raw = $edit['pass'];
             return $account;
         }
     }
     return FALSE;
 }
 static function groupContact($groupID, $contactIDs, $op)
 {
     require_once 'CRM/Bridge/OG/Utils.php';
     $ogID = CRM_Bridge_OG_Utils::ogID($groupID, false);
     if (!$ogID) {
         return;
     }
     require_once 'api/v2/UFGroup.php';
     foreach ($contactIDs as $contactID) {
         $drupalID = civicrm_uf_id_get($contactID);
         if ($drupalID) {
             if ($op == 'add') {
                 og_save_subscription($ogID, $drupalID, array('is_active' => 1));
             } else {
                 og_delete_subscription($ogID, $drupalID);
             }
         }
     }
 }
Exemple #3
0
 /**
  * Wrapper for og_membership creation.
  *
  * @param int $ogID
  *   Organic Group ID.
  * @param int $drupalID
  *   Drupal User ID.
  */
 public function og_membership_create($ogID, $drupalID)
 {
     og_save_subscription($ogID, $drupalID, array('is_active' => 1));
 }
}
$test = true;
// Don't actually move anything if true.
if ($test) {
    echo "----TESTING----\n\n\n";
}
// Get list of uids of members in origin group.
$results = db_query("SELECT uid FROM og_uid WHERE nid = %d", $origin_group);
$origin_uids = array();
while ($data = db_fetch_array($results)) {
    $origin_uids[] = $data['uid'];
}
echo "Moving uids to new group\n";
foreach ($origin_uids as $uid) {
    if (!$test) {
        og_save_subscription($dest_group, $uid, array("is_active" => 1));
    }
    echo "Added uid " . $uid . " to group: " . $dest_name . " from group: " . $origin_name . "\n";
}
foreach ($origin_uids as $uid) {
    if (!$test && !in_array($uid, $admins)) {
        og_delete_subscription($origin_group, $uid);
    }
    echo "Deleted uid " . $uid . " from group: " . $origin_name . "\n";
}
// Inform Group memebers of the Move.
$subject = "Moved your group subscription from " . $origin_name . " to " . $dest_name;
$body = "This message is to inform you that your group subscription in the " . $orgin_name . " group has been moved to the " . $dest_name . ". \n\n You may visit your new group at " . l($dest_name, "node/" . $dest_group);
echo $subject . "\n";
echo $body;
if (!$test) {
 public function groupActions($user_ids, $groups, $posts)
 {
     $gid = $groups[0];
     // - user ID 4 as pending member.
     og_save_subscription($gid, $user_ids[4], array('is_active' => 0));
     // - user ID 5 as active member.
     og_save_subscription($gid, $user_ids[5], array('is_active' => 1));
     // - user ID 6 as pending admin member.
     og_save_subscription($gid, $user_ids[6], array('is_active' => 0, 'is_admin' => 1));
     // - user ID 7 as active admin member.
     og_save_subscription($gid, $user_ids[7], array('is_active' => 1, 'is_admin' => 1));
 }