CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook civicrm_post : question on Groups > Added By
Pages: [1]

Author Topic: hook civicrm_post : question on Groups > Added By  (Read 589 times)

David L

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 2
hook civicrm_post : question on Groups > Added By
May 03, 2011, 02:40:11 pm
Two newbie questions:

a) I need all my Organization contacts to be automatically added to a specific group. I used the civicrm_post hook to do this, rather straighforward and it works well, however when I open the organization contact and go to the groups tab, it is added to the right group (yay) but the Status just says: Added (by ) instead of Added (by Admin) or something similar.

Where in the db is the AddedBy stored?

[code below, is it ok]?


b) Is CRM_Core_DAO:: (and other CRM objects and classes) thoroughly documented anywhere, explaining what attributes each one takes, and which methods are available? I'm not experienced with OOP, this would be very helpful, if it exists somewhere. Not having any luck finding it. Thanks


Code: [Select]
function foocivihooks_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {

if ( ($op == 'create') && ($objectName == 'Organization') ) {

$q = "INSERT INTO civicrm_group_contact(group_id, contact_id, status) VALUES (9, '$objectId', 'Added')";

CRM_Core_DAO::executeQuery($q);

} elseif ( ($op == 'create') && ($objectName == 'Relationship') ) {

$q = "SELECT contact_id_b, relationship_type_id FROM civicrm_relationship WHERE id='$objectId'";
$dao = CRM_Core_DAO::executeQuery($q);

while ($dao->fetch()) {

if ($dao->relationship_type_id == 4) { // Is employee relationship

$q = "INSERT INTO civicrm_group_contact(group_id, contact_id, status) VALUES (9, '$dao->contact_id_b', 'Added')";
CRM_Core_DAO::executeQuery($q);

}

} // End while

}

}

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: hook civicrm_post : question on Groups > Added By
May 03, 2011, 05:21:10 pm
In answer to a)
Why not just create a smart group? It's the easiest search in the world, just go to search (not even advanced search) and select contact type: organization. Then save it as a smart group.
Try asking your question on the new CiviCRM help site.

David L

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 2
Re: hook civicrm_post : question on Groups > Added By
May 04, 2011, 08:39:20 am
Good point colemanw! Why didn't I think of that?!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook civicrm_post : question on Groups > Added By

This forum was archived on 2017-11-26.