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) »
  • Relationship creation during drupal user registration
Pages: [1]

Author Topic: Relationship creation during drupal user registration  (Read 2308 times)

ewanmclean

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 0
Relationship creation during drupal user registration
April 06, 2011, 06:48:35 am
Hi folks

Dlobo kindly pointed me to some documentation on hooks and relationship APIs for this query but I'm afraid I just don't understand where to start with this.

Our use case is (www.nightline.ac.uk) that when volunteers register for an account we need them to be able to specify which branch of the charity they belong to. This means we need an autocomplete on the reg form which pulls out contacts of type 'charity branch' when they start typing. Once they select it and create their account, a relationship should be automatically created to make that volunteer a 'nightliner at' the branch.

I reckon it's in build_form or postprocess hooks but I'm a bit of a Civi coding n00b so can't even find where to start coding (found Utils/Hooks.php but this seems too generic).

Any ideas or does anyone know an existing workaround for this? Would be happy to contribute it back to the codebase if we can get it working.

Many thanks

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: Relationship creation during drupal user registration
April 06, 2011, 10:13:44 am

check:

http://svn.civicrm.org/tools/trunk/drupal/modules/civicrm_regsite/civicrm_regsite.module

While it does not do exactly what u want, it does show you how to create relationships via a hook in a profile (which is the same thing used in user register)

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

jpb

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
    • Nightline
Re: Relationship creation during drupal user registration
April 15, 2011, 04:16:27 pm
Hi Ewan

This blog post looks like it would be useful too if the link is done as a reference rather than a relationship.
How to customise a contact reference custom field
It would be nice to have the option of setting up the link as a membership of the branch too as well.

James

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Relationship creation during drupal user registration
April 17, 2011, 03:09:49 pm
Hi

WRT to creating the autocomplete -there is an MIH underway to include the ability to restrict a autocomplete 'out-of-the-box' to a certain group of contacts - that would essentially acheive what Xavier has described in his blog / the first part of your requirement. The current status is that $800 out of the required $1500 has been raised. Even if you do custom code something you will probably find that contributing towards this initiative may save you money at upgrade time.


This is the part of Lobo's code you should be focussing on


function civicrm_regsite_civicrm_postProcess( $class, &$form ) {
    if ( is_a( $form, 'CRM_Profile_Form_Edit' ) ) {
        $gid = $form->getVar( '_gid' );
        if ( $form->getVar( '_gid' ) == 3 ) {  // where 3 is the number of the form you are interested in
       $result =    civicrm_api('Relationship', 'Create', array('version' => 3, 'contact_id_a' => $form['values']['contact_id'], 'contact_id_b' => $form['values']['custom_2'], 'relationship_type_id' => 4,);// where 4 is the relationship type you want to create

if ($result['is_error'] ==1){
print_r("something needs fixing");
die;
        }
     }
}


Note that this is just an off -the top of my head guess. You would need to backport apiv3 for this to work (there is a thread on this forum about that) and I would use the civicrm_developer module (also on this forum) to capture the actual names of things rather than just my wild guesses
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Relationship creation during drupal user registration
June 14, 2011, 05:10:44 pm
Hi ewanmclean and others

Ewan did you find/made a solution. I'm looking for exactly this functionality.

I have students from all over the country registering, and they need to choose which school they are at, eg I need a drop-down/auto-complete list of all the schools allready in the system in the profile form (The profile is for the contact type Student, but the schools are of the organisation contact type, so I cannot mix them on the same profile form). I've created a student-school relationship and when a student register a relation between them and the school should be created automaticly.

Eileen am I right in thinking that your code would more or less do this?

If I'm missing some obvious alternative method to do this please advice me - I'm a newbee :)

Thanks in advance!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Relationship creation during drupal user registration

This forum was archived on 2017-11-26.