OG CiviCRM (og_civicrm) is a module that was written by Killes that torenware updated to 4.6 but does not have an active maintainer currently. I understand that Alan Dixon may willing / interested in becoming maintainer for the module, and I am as well.

I have an update to Drupal 5.1 / CiviCRM 1.6 that I can make available to people if they so wish -- it's not possible to submit a patch at the moment because there's no maintainer. Since attaching files here in the forum is not enabled, here are the contents of the new 5.1 .info and .install files, and a patch file against the 4.6 version of the other files.

og_civicrm.info:
; $Id$
name = OG CiviCRM
description = Provides basic integration between Drupal's organic groups and CiviCRM.
dependencies = og civicrm
package = Organic groups
version = VERSION

og_civicrm.install:

// ; $Id$

// og_civicrm.install

/**
* Implementation of hook_install().
*/
function og_civicrm_install() {
    switch($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
            db_query("CREATE TABLE {og_civicrm} (
                nid INT(11) NOT NULL,
                gid INT(11) NOT NULL,
                did INT(11) NOT NULL,
                PRIMARY KEY  (nid, gid, did)
                ) TYPE=MyISAM
                /*!40100 DEFAULT CHARACTER SET utf8 */;");
            break;
        case 'pgsqql':
            db_query("CREATE TABLE {og_civicrm} (
                nid NUMERIC(11) NOT NULL,
                gid NUMERIC(11) NOT NULL,
                did NUMERIC(11) NOT NULL,
                PRIMARY KEY  (nid, gid, did)
                );");
            break;
    }
}

/**
* Implementation of hook_enable().
*/

function og_civicrm_enable() {
    /* TO DO: 
        - create a CiviCRM group for each Drupal organic group
        - add corresponding CiviCRM users to CiviCRM groups for each og
        - create a CiviCRM user for each Drupal user in a Drupal group if it does not exist
    */
    
}

/**
* Implementation of hook_uninstall().
*/
function og_civicrm_uninstall() {
  db_query('DROP TABLE {og_civicrm}');
  // remove all CRM groups and group memberships that were created by og_civicrm
  civicrm_initialize(TRUE);   
  $params = array('source' => 'og_civicrm');
  $return_properties = array('id');
  $myGroups =& crm_get_groups($params, $return_properties);
  foreach ($myGroups as $group) {
    crm_delete_group($group);
  }
}

patch file against 4.6 (http://cvs.drupal.org/viewcvs/drupal/contributions/modules/og_civicrm/?o...):

? og_civicrm.info
? og_civicrm.install
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_civicrm/README.txt,v
retrieving revision 1.1
diff -u -r1.1 README.txt
--- README.txt 28 Oct 2005 11:14:54 -0000 1.1
+++ README.txt 15 Feb 2007 20:45:05 -0000
@@ -1,2 +1,2 @@
-og_civicrm.module is a small module that integrates Drupal's organic groups
-with CiviCRM. For more information about CiviCRM see: http://openngo.org/
+og_civicrm.module integrates Drupal's organic groups with CiviCRM.
+For more information about CiviCRM see: http://civicrm.org/
Index: og_civicrm.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_civicrm/og_civicrm.module,v
retrieving revision 1.8
diff -u -r1.8 og_civicrm.module
--- og_civicrm.module 30 Mar 2006 01:54:42 -0000 1.8
+++ og_civicrm.module 15 Feb 2007 21:03:40 -0000
@@ -4,34 +4,20 @@
/**
*
* CiviCRM integration support for Organic Groups
+ * mirrors organic groups and organic group memberships in CiviCRM groups and group memberships
*
- * Note: this version should work with Drupal 4.6 and
- * CiviCRM 1.4 beta or more recent. This code may work
- * with Drupal 4.7, but has not yet been tested on that
- * release.
+ * Note: this version has been tested against Drupal 5.1 and
+ * CiviCRM 1.6.
*
*/
-
-
-
-/**
- * Implementation of hook_help().
- *
- */
-function og_civicrm_help($section) {
- switch ($section) {
- case 'admin/modules#description':
- return t('Organic groups for CiviCRM');
- }
-}
-
+
/**
* Implementation of hook_nodeapi().
*
* We create a new CiviCRM group for each new OG and use the og_civicrm module to keep track.
*/
function og_civicrm_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
- if ($node->type == 'og') {
+ if (og_is_group_type($node->type)) {
civicrm_initialize(TRUE);
switch ($op) {
case 'insert':
@@ -41,12 +27,28 @@
// new OG, create CiviCRM group
$count = db_result(db_query('SELECT COUNT(*) FROM {og_civicrm} WHERE nid = %d AND did = %d', $node->nid, CIVICRM_DOMAIN_ID));
if (!$count) {
- if (!isset($node->civicrm)) { // loop protection
- $group = array('title' => $node->title, 'name' => $node->title, 'description' => $node->description, 'source' => 'og_civicrm', 'is_active' => 1, 'domain_id' => CIVICRM_DOMAIN_ID);
+ if (!isset($node->civicrm)) { // loop protection
+ $group = array('title' => $node->title, 'name' => $node->title, 'description' => $node->og_description, 'source' => 'og_civicrm', 'is_active' => 1, 'domain_id' => CIVICRM_DOMAIN_ID);
$group = crm_create_group($group);
}
$group_id = isset($group->id) ? $group->id : $node->civicrm;
db_query('INSERT INTO {og_civicrm} (nid, gid, did) VALUES (%d, %d, %d)', $node->nid, $group_id, CIVICRM_DOMAIN_ID);
+ // since the user is added by og to the group before og_civicrm creates its group,
+ // we need to add the initial user to the group here as a work-around
+ // to do: get og to implement module_invoke_all for group insert and group update events
+ $contact_id = crm_uf_get_match_id($node->uid);
+ // if not yet a contact, create it
+ if (!$contact_id) {
+ $user = user_load(array('uid' => $uid));
+ $contact_user = object2array($user);
+ $contact_user['email'] = $contact_user['mail'];
+ $contact = crm_create_contact($contact_user);
+ } else {
+ $contact = crm_get_contact(array('contact_id' => $contact_id));
+ }
+ $contacts = array($contact);
+ $status = 'Added';
+ $ret = crm_add_group_contacts($group, $contacts, $status, 'API');
}
break;
case 'update':
@@ -76,10 +78,26 @@
}
break;
}
- }
+ }
}

-
+/**
+* @desc convert an object to an associative array
+*
+* function was in 4.6 core as object2array and has been added here since it is still used
+*/
+
+function og_civicrm_object2array($object) {
+ if (is_object($object)) {
+ foreach ($object as $key => $value) {
+ $array[$key] = $value;
+ }
+ }
+ else {
+ $array = $object;
+ }
+ return $array;
+}
/**
* implementation of hook_og();
*
@@ -89,41 +107,36 @@
* @param array $args (changed March 06)
*/
function og_civicrm_og($op, $nid, $uid, $args = array()) {
-
//If a user is subscribed to a group via Drupal's UI, then the user has
//already been subscribed on the Drupal side, and we will need to subscribe
//the user on the CRM side here as well.
-
if (!_og_civicrm_grab_baton("drupal")) {
- //But if we're here, CRM subscribed the user, and called og.
+ //But if we're here, CRM subscribed the user, and called og.
//Since we are done, we leave without going further.
return;
}

$status = $args['is_active'] ? "Added" : "Pending";
civicrm_initialize(TRUE);
- $gid = db_result(db_query('SELECT gid FROM {og_civicrm} WHERE nid = %d AND did = %d', $nid, CIVICRM_DOMAIN_ID));
- if (!$gid)
+ $gid = db_result(db_query('SELECT gid FROM {og_civicrm} WHERE nid = %d AND did = %d', $nid, CIVICRM_DOMAIN_ID ));
+ if (!$gid) {
return; //not mirrored
+ }
$group = array('id' => $gid, 'domain_id' => CIVICRM_DOMAIN_ID);
if ($gid) {
$groups = crm_get_groups($group);
$group = $groups[0];
}
$contact_id = crm_uf_get_match_id($uid);
-
- // If the user isn't a contact yet, make him.
+ // If the user isn't a contact yet, create the contact record
if (!$contact_id) {
$user = user_load(array('uid' => $uid));
- $contact_user = object2array($user);
+ $contact_user = og_civicrm_object2array($user);
$contact_user['email'] = $contact_user['mail'];
$contact = crm_create_contact($contact_user);
$contact_id = crm_uf_get_match_id($uid);
}
switch ($op) {
- //TO DO: API has changed (3/06), and you can get
- //a 'user update' event. Not clear if we
- //need to do anything with it, though.
case 'user insert':
$user_groups = crm_contact_get_groups($contact_id);
$group_ids = array(0);
@@ -132,18 +145,12 @@
$group_ids[] = $value['group_id'];
}
}
- //RMT: why are "all contacts added as pending"? Does not seem to work.
- // all contacts are added as pending
if (!in_array($group->id, $group_ids)) {
$contact = crm_get_contact(array('contact_id' => $contact_id));
$contacts = array($contact);
+ $status = 'Added';
crm_add_group_contacts($group, $contacts, $status, 'API');
- }
- if ($approved) {
- $contact = crm_get_contact(array('contact_id' => $contact_id));
- $contacts = array($contact);
- crm_confirm_group_contacts($group, $contacts);
- }
+ }
break;
case 'user delete':
$contact = crm_get_contact(array('contact_id' => $contact_id));

Comments

gracearoha’s picture

will you be updating this civicrm 1.7 by chance?

alexh’s picture

Hello,
thanks very much for sharing this. But I was not successful with the patch:
I tried to "patch -p0 < patch_from_above.patch"
OK, I don't have the README.txt, so I skipped that part.
But, then I get this error:

patching file og_civicrm.module
patch: **** malformed patch at line 23: /**

Am I doing sth wrong?

yopyop’s picture

Hi - Thanks for this patch also.

I downloaded 4.6, applied the patch and got this error as well:

patching file og_civicrm.module
patch: **** malformed patch at line 23: /**

I would really love to make this work - I'm helping out a coalition of peace organizations that I would like to use this for - some way to record/mirror the og groups in civicrm seems really crucial. I don't have the experience/skill with drupal modules and patches to make it happen myself, but I'd be willing to try to do what I can to help complete this (help fundraise to complete it?)

If there is anyone who has applied the patch and got it working for 5.1 and CiviCRM 1.7, I'd love to get the files, or some tips on how to make it happen.

Thanks again

g76’s picture

First off, thank you for your work on this, it is much appreciated.

I have patched the 4.6 module and the .INSTALL file, as well as created the .info file with what you have above. The problem is it does not show up in the module listing, it's not reading it at all. Any suggestions?

g76’s picture

Ignore my previous comment. Working a few too many hours I think, I got it showing up.

Jen Wolfe

g76’s picture

I get this error upon attempting to install the module:
Parse error: syntax error, unexpected $end in /home/domain.com/public_html/cvccms/modules/og_civicrm/og_civicrm.module on line 458

there is nothing on line 458, it's the last line of code, it's blank. I am not familiar with code, so I do not know what I should be looking for to fix things. If you could help it would be great. Again, thank you for your post and your work on this.

Jen Wolfe

aszalos’s picture

Many thanks for the work. Have you tested it on CiviCRM 1.7 as well? I guess this is a module which is really needed.