Active
Project:
CiviNode And Civinode CCK
Version:
master
Component:
Documentation
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
24 Apr 2006 at 21:30 UTC
Updated:
16 May 2006 at 22:02 UTC
When I add a user to a group, I get an error message from CiviNode:
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/civicrm/modules/civinode/civinode_utils.inc on line 894
I'm not quite sure what this code is looking for:
function civinode_add_node_memberships($gid, $contact_list){
//Are any nodes associated with this group?
$lookup = civinode_get_node_memberships($gid);
//Loop over the contact IDs and if they have associated
//nodes, add them to this group's list.
$sql = "INSERT INTO {civinode_node_memberships} (nid, contact_id, group_id) VALUES (%d,%d,%d)";
foreach ($contact_list as $cid) {
if ( !isset($lookup[$cid]) ) {
//See if a node exists
$node = civinode_util_node_factory($cid, FALSE);
if (isset($node->nid))
db_query($sql, $node->nid, $cid, $gid);
}
}
}
Comments
Comment #1
Torenware commentedMark,
The bug here really is one of documentation, since this API isn't used to add contacts to CRM groups; it's used to update a table used by the access system. So it's really part of the private API. I haven't marked it, so there isn't much way you'd be able to tell.
Clearly, though, there needs to be a call to this, since doing this directly in the CRM API is a big messy.
What you really want to do right now is this:
I haven't had the need yet to add this functionality to the library, but plenty of modules do exactly what you want here.
I'll start factoring some of the more obscure code, like civinode_add_node_memberships(), into .inc files, and will do a better job of labelling them as private APIs when I do.
Comment #2
Torenware commentedI'm adding an API to do this to the library:
I want to test this before I commit it, but this should be fairly bullet proof, I think.
Comment #3
mfredrickson commentedI get a sql error now (which might not be your fault):
Comment #4
mfredrickson commentedAlso, a point of clarification, when I say "add a contact to a group" I mean using the point-n-click CiviCRM method (click on contact, select group, click add button). I'm not doing this through an API.