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) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Best way to map from drupal <username> to civicrm <firstname><surname>
Pages: [1]

Author Topic: Best way to map from drupal <username> to civicrm <firstname><surname>  (Read 2599 times)

cgfoz

  • Guest
Best way to map from drupal <username> to civicrm <firstname><surname>
July 31, 2007, 05:08:13 am
Hi, Drupal 5.1 user with civicrm here:

In my current drupal setup I am using views to display tables of news items and events.

I wish to display the firstname and surname of the poster of each post rather than the often irrelevant drupal username. However when I get the drupal user object this information does not appear. So I assume that this information comes from within civicrm.

A play with the civicrm api makes it looks like it might be possible to get this information, but I'm worried now that I'm going to kill my database with a lookups with this method. The page that displays the news items is quite prominant on the website and may have 10-20 posts where I would need to translate.

Any suggestions. Is the api the best way to go or is there a better way or hack to quickly translate drupal details to firstname, lastname without killing the db?

Thanks
Chris

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Best way to map from drupal <username> to civicrm <firstname><surname>
July 31, 2007, 11:18:20 am
I don't know that in your case this solution will work, but CiviNode is how I have done this in the past. You can use CiviNode with CCK to pull in contact reference, etc, but that would mean your news content type would have to be through CCK. You would then edit the template file for that CCK type (or your View) and pull the first and last name that are associated with the CiviCRM id CiviNode pulls. Again, not sure if this is helpful in your case, but definitely take a look at the module as it may come in handy now or in the future.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Best way to map from drupal <username> to civicrm <firstname><surname>
July 31, 2007, 12:46:08 pm
Chris - you can use CiviCRM's crm_uf_get_match_id API to pass in a Drupal User ID and get back the corresponding   CiviCRM contact ID. Then use the search API to retrieve the desired contact properties (i.e. first and last name). An example of the first call is here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Using+CiviCRM+APIs+-+Code+Snippets#UsingCiviCRMAPIs-CodeSnippets-GetaCiviCRMuserobject

...dave
Protect your investment in CiviCRM by  becoming a Member!

cgfoz

  • Guest
Re: Best way to map from drupal <username> to civicrm <firstname><surname>
August 10, 2007, 02:48:08 am
Thanks for the help.

I gave civinode a try and it has a very much less daunting API than civicrm.

If anyone is interested the line below uses a drupal id and returns the data of the default profile. In my setup I set the default profile to just be the civicrm first and last name:
Code: [Select]
$user_crm = civinode_util_load_cdata(civinode_util_get_user_cid($node->uid) , civinode_get_default_profile_id());

Next step - Shoehorn this into the views API ;-)


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Best way to map from drupal <username> to civicrm <firstname><surname>

This forum was archived on 2017-11-26.