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 (Moderator: Donald Lobo) »
  • using hooks & profiles to create relationships at sign-up
Pages: [1]

Author Topic: using hooks & profiles to create relationships at sign-up  (Read 1209 times)

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
using hooks & profiles to create relationships at sign-up
March 20, 2009, 02:04:42 pm
I need to develop a way to add relationships via profiles (i.e. when creating a new user in Drupal) and am wondering if I can use a couple hooks & the API

The client for this implementation is a non-profit that serves schools.  When teachers from a school signs up for an account they are going to be asked what school and district they teach in.  I need for both the school and the building to show up as a relationship, the district as the current employer and the school as a custom relationship called something like "school building".  The districts & schools are going to be organizations in civi.  I was thinking that I could create custom field called district & building and use hook_civicrm_customFieldOptions to populate those fields using SQL to pull from civicrm_contact table (which seems to fit with the documentation for that hook and this forum http://forum.civicrm.org/index.php?topic=6918.0).  From there things get tricky I was thinking I could use  hook_civicrm_custom to intercept the data before it gets inserted into the custom table and create relationship using the api, specifically civicrm_relationship_create(&$params ).   Though I wasn't sure if maybe it would be best to use the post or pre hooks

Does this sound doable?

btw, I have developed modules calling the api, but I'm definitely not terribly familiar with the this area of civi

this would be in CiviCRM 2.2, Drupal 6.10+
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: using hooks & profiles to create relationships at sign-up
March 20, 2009, 02:14:26 pm

that sounds like a good plan. I would modify it a bit:

1. I would actually use both custom data and relationship to store the information. I'd treat the custom data as "user" entered information while the relationships are created by the system based on the user info. You need to the custom data values when viewing the custom data

2. hook_civicrm_custom does not have pre/post part. You should be able to use that part

3. what happens when an admin changes the relationship from the UI? would you clean up the custom data?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: using hooks & profiles to create relationships at sign-up
March 23, 2009, 06:22:16 am
Lobo,

on point #1, is there another way.  I was assuming I would have to use both, is there a way to have a field only show up in a profile and not in the contact record?


On #3, that's a good point could I use hook_civicrm_post, though the documentation (http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmpost) says Drupal does not support pre/post hooks.  Is that in reference to Drupal's FAPI?
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: using hooks & profiles to create relationships at sign-up
March 23, 2009, 08:18:35 am
a profile field does not show up in a contact record. However custom data does show up in a contact record (either inline or as a seperate tab based on how the group was structured) - unless you create a custom version of the corresponding templates which exclude the fieldset or tab explicitly.

i fixed the documentation to eliminate that statement (since it was confusing folks). The post hook is called by CiviCRM for all CMS's

lobo
« Last Edit: March 23, 2009, 01:59:40 pm by Dave Greenberg »
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • using hooks & profiles to create relationships at sign-up

This forum was archived on 2017-11-26.