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) »
  • Issue with Relationship API
Pages: [1]

Author Topic: Issue with Relationship API  (Read 1589 times)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Issue with Relationship API
January 11, 2010, 06:51:17 am
The relationship API returns an error if I try to establish a relation between an individual and an organization when the setup is All contacttypes.
I have set up a relationship type called Partner (see attachment) with All Contacttypes.

When I use the following code to add a relationship I get an error (Contact ID :3315 is not of contact type).
Code:
$params = array(
'contact_id_a' => 3315,
'contact_id_b' => 3314,
'relationship_type_id' => 30,
'start_date' => date("Y-m-d", strtotime("2010-01-14")),
'is_active' => 1);

// Call CiviCRM API functie to add relation:

$rel = & civicrm_relationship_create( $params );

/* write error if civicrm returns error */
print_r($rel);

The error disappears if I change the setup of the relationship to From Person To Organization. But I need this type as well between Organizations, and I assume this should work. I have already raised an issue (CRM-5646) but perhaps someone already has a fix?
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Issue with Relationship API
January 11, 2010, 10:49:14 am
I am stuck....I have located the problem in the function
Code: [Select]
civicrm_relationship_format_params in the API/v2/Relationship.php. The error occurs in this bit of code:
Code: [Select]
$relationTypes = CRM_Core_PseudoConstant::relationshipType( );

if (!array_key_exists($value, $relationTypes)) {
                return civicrm_create_error("$key not a valid: $value");
            }

I get the error with the following values in $relationTypes:
Code: [Select]
Array ( [1] => Array ( [label_a_b] => Kind van [label_b_a] => Ouder van [contact_type_a] => Individual [contact_type_b] => Individual ) [2] => Array ( [label_a_b] => Man/vrouw van [label_b_a] => Man/vrouw van [contact_type_a] => Individual [contact_type_b] => Individual ) [3] => Array ( [label_a_b] => Broer/zus van [label_b_a] => Broer/zus van [contact_type_a] => Individual [contact_type_b] => Individual ) [4] => Array ( [label_a_b] => Werknemer van [label_b_a] => Werkgever van [contact_type_a] => Individual [contact_type_b] => Organization ) [5] => Array ( [label_a_b] => Vrijwilliger bij [label_b_a] => Vrijwilliger [contact_type_a] => Individual [contact_type_b] => Organization ) [6] => Array ( [label_a_b] => Contractant [label_b_a] => Contractant [contact_type_a] => Individual [contact_type_b] => Household ) [7] => Array ( [label_a_b] => Lid huishouden [label_b_a] => Lid huishouden [contact_type_a] => Individual [contact_type_b] => Household ) [8] => Array ( [label_a_b] => Zaakcontact [label_b_a] => Zaakcontact [contact_type_a] => Individual [contact_type_b] => Individual ) [9] => Array ( [label_a_b] => Buurtbeheerder [label_b_a] => Buurbeheerder [contact_type_a] => Individual [contact_type_b] => Household ) [10] => Array ( [label_a_b] => Wijkagent [label_b_a] => Wijkagent [contact_type_a] => Household [contact_type_b] => Individual ) [11] => Array ( [label_a_b] => Contactpersoon [label_b_a] => Contactpersoon [contact_type_a] => Individual [contact_type_b] => Organization ) [12] => Array ( [label_a_b] => Begeleider Schuldhulpverlening [label_b_a] => Begeleider Schuldhulpverlening [contact_type_a] => Individual [contact_type_b] => Household ) [13] => Array ( [label_a_b] => Gezinsvoogd [label_b_a] => Gezinsvoogd [contact_type_a] => Individual [contact_type_b] => Household ) [14] => Array ( [label_a_b] => Maatschappelijk werker [label_b_a] => Maatschappelijk werker [contact_type_a] => Individual [contact_type_b] => Household ) [15] => Array ( [label_a_b] => Deurwaarder [label_b_a] => Deurwaarder [contact_type_a] => [contact_type_b] => ) [16] => Array ( [label_a_b] => Mdw Mens en Buurt [label_b_a] => Mdw Mens en Buurt [contact_type_a] => [contact_type_b] => ) [17] => Array ( [label_a_b] => Mdw huuradministratie [label_b_a] => Mdw huuradministratie [contact_type_a] => [contact_type_b] => ) [18] => Array ( [label_a_b] => Overlast medewerker [label_b_a] => Overlast medewerker [contact_type_a] => [contact_type_b] => ) [19] => Array ( [label_a_b] => Verkoopmedewerker [label_b_a] => Verkoopmedewerker [contact_type_a] => [contact_type_b] => ) [20] => Array ( [label_a_b] => Mdw. Te Woon [label_b_a] => Mdw. Te Woon [contact_type_a] => [contact_type_b] => ) [21] => Array ( [label_a_b] => Taxateur [label_b_a] => Taxateur [contact_type_a] => [contact_type_b] => ) [22] => Array ( [label_a_b] => Bouwkundige [label_b_a] => Bouwkundige [contact_type_a] => [contact_type_b] => ) [23] => Array ( [label_a_b] => Financieel adviseur [label_b_a] => Financieel adviseur [contact_type_a] => [contact_type_b] => ) [24] => Array ( [label_a_b] => Notaris [label_b_a] => Notaris [contact_type_a] => [contact_type_b] => ) [25] => Array ( [label_a_b] => Fellow of [label_b_a] => Fellowship for [contact_type_a] => Individual [contact_type_b] => Organization ) [26] => Array ( [label_a_b] => Senior fellow of [label_b_a] => Senior fellowship for [contact_type_a] => Individual [contact_type_b] => Organization ) [27] => Array ( [label_a_b] => Associate fellow of [label_b_a] => Associate fellowship for [contact_type_a] => Individual [contact_type_b] => Organization ) [28] => Array ( [label_a_b] => Advisor of [label_b_a] => Advised by [contact_type_a] => Individual [contact_type_b] => Organization ) [29] => Array ( [label_a_b] => Member of Board of Directors of [label_b_a] => Member of Board of Directors is [contact_type_a] => Individual [contact_type_b] => Organization ) [30] => Array ( [label_a_b] => Partner of [label_b_a] => Partner [contact_type_a] => [contact_type_b] => ) [31] => Array ( [label_a_b] => Guest of [label_b_a] => Host for [contact_type_a] => Individual [contact_type_b] => Organization ) [32] => Array ( [label_a_b] => Young Scholar at [label_b_a] => Scholarship for [contact_type_a] => Individual [contact_type_b] => Organization ) [33] => Array ( [label_a_b] => Friend of [label_b_a] => Friend of [contact_type_a] => [contact_type_b] => ) [34] => Array ( [label_a_b] => Individual Associate of [label_b_a] => Associate for [contact_type_a] => [contact_type_b] => ) )

and the value of 30 for $value. I would then expect it would find the key value 30.....but at the end there is an error!

With the changed setup the array holds:
Code: [Select]
Array ( [1] => Array ( [label_a_b] => Kind van [label_b_a] => Ouder van [contact_type_a] => Individual [contact_type_b] => Individual ) [2] => Array ( [label_a_b] => Man/vrouw van [label_b_a] => Man/vrouw van [contact_type_a] => Individual [contact_type_b] => Individual ) [3] => Array ( [label_a_b] => Broer/zus van [label_b_a] => Broer/zus van [contact_type_a] => Individual [contact_type_b] => Individual ) [4] => Array ( [label_a_b] => Werknemer van [label_b_a] => Werkgever van [contact_type_a] => Individual [contact_type_b] => Organization ) [5] => Array ( [label_a_b] => Vrijwilliger bij [label_b_a] => Vrijwilliger [contact_type_a] => Individual [contact_type_b] => Organization ) [6] => Array ( [label_a_b] => Contractant [label_b_a] => Contractant [contact_type_a] => Individual [contact_type_b] => Household ) [7] => Array ( [label_a_b] => Lid huishouden [label_b_a] => Lid huishouden [contact_type_a] => Individual [contact_type_b] => Household ) [8] => Array ( [label_a_b] => Zaakcontact [label_b_a] => Zaakcontact [contact_type_a] => Individual [contact_type_b] => Individual ) [9] => Array ( [label_a_b] => Buurtbeheerder [label_b_a] => Buurbeheerder [contact_type_a] => Individual [contact_type_b] => Household ) [10] => Array ( [label_a_b] => Wijkagent [label_b_a] => Wijkagent [contact_type_a] => Household [contact_type_b] => Individual ) [11] => Array ( [label_a_b] => Contactpersoon [label_b_a] => Contactpersoon [contact_type_a] => Individual [contact_type_b] => Organization ) [12] => Array ( [label_a_b] => Begeleider Schuldhulpverlening [label_b_a] => Begeleider Schuldhulpverlening [contact_type_a] => Individual [contact_type_b] => Household ) [13] => Array ( [label_a_b] => Gezinsvoogd [label_b_a] => Gezinsvoogd [contact_type_a] => Individual [contact_type_b] => Household ) [14] => Array ( [label_a_b] => Maatschappelijk werker [label_b_a] => Maatschappelijk werker [contact_type_a] => Individual [contact_type_b] => Household ) [15] => Array ( [label_a_b] => Deurwaarder [label_b_a] => Deurwaarder [contact_type_a] => [contact_type_b] => ) [16] => Array ( [label_a_b] => Mdw Mens en Buurt [label_b_a] => Mdw Mens en Buurt [contact_type_a] => [contact_type_b] => ) [17] => Array ( [label_a_b] => Mdw huuradministratie [label_b_a] => Mdw huuradministratie [contact_type_a] => [contact_type_b] => ) [18] => Array ( [label_a_b] => Overlast medewerker [label_b_a] => Overlast medewerker [contact_type_a] => [contact_type_b] => ) [19] => Array ( [label_a_b] => Verkoopmedewerker [label_b_a] => Verkoopmedewerker [contact_type_a] => [contact_type_b] => ) [20] => Array ( [label_a_b] => Mdw. Te Woon [label_b_a] => Mdw. Te Woon [contact_type_a] => [contact_type_b] => ) [21] => Array ( [label_a_b] => Taxateur [label_b_a] => Taxateur [contact_type_a] => [contact_type_b] => ) [22] => Array ( [label_a_b] => Bouwkundige [label_b_a] => Bouwkundige [contact_type_a] => [contact_type_b] => ) [23] => Array ( [label_a_b] => Financieel adviseur [label_b_a] => Financieel adviseur [contact_type_a] => [contact_type_b] => ) [24] => Array ( [label_a_b] => Notaris [label_b_a] => Notaris [contact_type_a] => [contact_type_b] => ) [25] => Array ( [label_a_b] => Fellow of [label_b_a] => Fellowship for [contact_type_a] => Individual [contact_type_b] => Organization ) [26] => Array ( [label_a_b] => Senior fellow of [label_b_a] => Senior fellowship for [contact_type_a] => Individual [contact_type_b] => Organization ) [27] => Array ( [label_a_b] => Associate fellow of [label_b_a] => Associate fellowship for [contact_type_a] => Individual [contact_type_b] => Organization ) [28] => Array ( [label_a_b] => Advisor of [label_b_a] => Advised by [contact_type_a] => Individual [contact_type_b] => Organization ) [29] => Array ( [label_a_b] => Member of Board of Directors of [label_b_a] => Member of Board of Directors is [contact_type_a] => Individual [contact_type_b] => Organization ) [30] => Array ( [label_a_b] => Partner of [label_b_a] => Partner [contact_type_a] => Individual [contact_type_b] => Organization ) [31] => Array ( [label_a_b] => Guest of [label_b_a] => Host for [contact_type_a] => Individual [contact_type_b] => Organization ) [32] => Array ( [label_a_b] => Young Scholar at [label_b_a] => Scholarship for [contact_type_a] => Individual [contact_type_b] => Organization ) [33] => Array ( [label_a_b] => Friend of [label_b_a] => Friend of [contact_type_a] => [contact_type_b] => ) [34] => Array ( [label_a_b] => Individual Associate of [label_b_a] => Associate for [contact_type_a] => [contact_type_b] => ) )

I can't see any important difference that makes the array_key_exist go wrong?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Issue with Relationship API
January 11, 2010, 11:05:08 am
One step further, the actual problem is a little bit further in the function:
Code: [Select]
           if ($relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
                return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
            }

It will come up with 'Individual' as a result of the Contact_BAO_Contact::getContactType as that is indeed the relationshiptype of the contact in question. But this check makes no sense if there is no type to check. The obvious solution would be to change this in:
Code: [Select]
           if (!empty($relation['contact_type_a'])) {
if ($relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
               return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
             }
            }

and then the same for contact_type_b. Any flaws in this reasoning?
« Last Edit: January 11, 2010, 11:08:04 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Issue with Relationship API
January 11, 2010, 02:36:26 pm

thanx for investigating. we'll fix the issue in 3.0.x over the next few days and update this topic

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Issue with Relationship API

This forum was archived on 2017-11-26.