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 »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • finding a CiviCRM contact from Joomla login
Pages: [1]

Author Topic: finding a CiviCRM contact from Joomla login  (Read 1437 times)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
finding a CiviCRM contact from Joomla login
December 06, 2011, 09:43:14 am
When a user logs on to a Joomla site, I want to be able to retrieve their CiviCRM profile. I've synchronised users to contacts so how do I use this. I can get the Joomla username and/or email addres.

Up to now I've been using the emaila ddres, but the user can change his CiviCRM email address so the link no longer works.

Help? :-)

ta

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: finding a CiviCRM contact from Joomla login
December 06, 2011, 01:11:34 pm
Joomla users are mapped to corresponding CiviCRM contacts by the 'synchronize' function. The mappings are stored in civicrm_uf_match table.

If you create a CiviCRM Profile 'edit' menu option for authenticated users, that profile form will be preloaded w/ their contact data when they visit the form.

There are a number of freely available Joomla extensions which include code to grab contact data based on logged in user - if you're looking for a programmatic solution I'd check them out:
http://wiki.civicrm.org/confluence/display/CRMDOC40/Joomla!+Extensions+for+CiviCRM+%283rd+party%29
Protect your investment in CiviCRM by  becoming a Member!

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: finding a CiviCRM contact from Joomla login
December 07, 2011, 03:36:15 am
Thanks I'll have a look at these

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: finding a CiviCRM contact from Joomla login
December 07, 2011, 03:40:34 am
if you have the j! user id, you can use the api.

In drupal, if you don't put the user id, it default to the connected one:

civicrm_api("UFMatch","get", array ('version' =>'3'))

(haven't tried on Joomla, would be good to let us know if it works)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: finding a CiviCRM contact from Joomla login
December 10, 2011, 02:19:54 am
this works

<?php
// Get the current user's ID
// Input None
// Output ID if user is logged on else Null
require_once 'api/api.php';
function GetUsersCIVIcrmID()

{
   $user =& JFactory::getUser();
   $joomla_id = $user->id;

   $params = array(
      'uf_id' => $joomla_id,
      'return.contact_id' => 1,
      'version' => 3,
   );

   $result = civicrm_api( 'uf_match','get',$params );
   $values = array_values ($result['values']);
   $contact_id = $values[0]['contact_id'];
   return $contact_id;
}
?>

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: finding a CiviCRM contact from Joomla login
December 11, 2011, 03:25:34 am
Hi,

Glad you got it working. Few comments:

- Usually don't need to require the api.php (at least in the latest civi versions)
- the return is usually not necessary, but it's a good habit (especially with things like contact, that got a gazillion fields by default you don't care about).
- you can also use return='contact_id,other_field" or return = array () (the later not so sure) that I find more compact

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: finding a CiviCRM contact from Joomla login
December 12, 2011, 04:13:22 am
Thanks for your comments

as an old style coder (I used to Write FORTRAN code for a living in the 70's, 80's and into the 90's) I'm used to making things explicitly clear and not making any assumptions in the code - generally because other people make different assumptions :))

Generic

  • I post occasionally
  • **
  • Posts: 87
  • Karma: 4
  • CiviCRM version: 4.2.*, 4.5.*
  • CMS version: Joomla 2.5.*
  • MySQL version: 5.1.*
  • PHP version: 5.3.*
Re: finding a CiviCRM contact from Joomla login
May 03, 2013, 08:44:33 am
Code: [Select]
function GetUsersCIVIcrmID()
  {
    $user =& JFactory::getUser();
  $userID = $user->get('id');

// Perform bootstrap as we are outside of CiviCRM core
define('CIVICRM_SETTINGS_PATH', JPATH_ROOT . '/' . 'administrator/components/com_civicrm/civicrm.settings.php');
require_once CIVICRM_SETTINGS_PATH;
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();

// Get civiID
    $params = array(
      'uf_id' => $userID,
      'version' => 3,
  );
    $result = civicrm_api( 'UFMatch','Get',$params );
  $values = array_values ($result['values']);
    $contact_id = $values[0]['contact_id'];

//$array = print_r($result); // Use this to print the array, its worth a look
    return $contact_id;
}

$civiID = GetUsersCIVIcrmID();
echo $civiID;
Document everything!
Zim-Wiki

Generic

  • I post occasionally
  • **
  • Posts: 87
  • Karma: 4
  • CiviCRM version: 4.2.*, 4.5.*
  • CMS version: Joomla 2.5.*
  • MySQL version: 5.1.*
  • PHP version: 5.3.*
Re: finding a CiviCRM contact from Joomla login
May 03, 2013, 08:47:15 am
Code: [Select]
function GetContactsMembershipstatus()
{
    $user =& JFactory::getUser();
  $userID = $user->get('id');

// Perform bootstrap as we are outside of CiviCRM core
define('CIVICRM_SETTINGS_PATH', JPATH_ROOT . '/' . 'administrator/components/com_civicrm/civicrm.settings.php');
require_once CIVICRM_SETTINGS_PATH;
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();

// Get civiID
    $params = array(
      'uf_id' => $userID,
      'version' => 3,
  );
    $result = civicrm_api( 'uf_match','Get',$params );
  $values = array_values ($result['values']);
    $contact_id = $values[0]['contact_id'];

    // Get contacts membership status id
    $params = array(
      'contact_id' => $contact_id,
      'version' => 3,
  );
    $result = civicrm_api( 'Membership','Get',$params );
  $values = array_values ($result['values']);
    $membership_status_id = $values[0]['status_id'];

// Get status id name (label)
    $params = array(
      'id' => $membership_status_id,
      'version' => 3,
  );
    $result = civicrm_api( 'MembershipStatus','Get',$params );
  $values = array_values ($result['values']);
    $membership_status = $values[0]['label'];

//$array = print_r($result); // Use this to print the array, its worth a look
return $membership_status;

}

$memstatus = GetContactsMembershipstatus();
echo $memstatus;
Document everything!
Zim-Wiki

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • finding a CiviCRM contact from Joomla login

This forum was archived on 2017-11-26.