X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FRelationship.php;h=2dede0b650dcd0441033bf8ccb5d5e0ebb5c5931;hb=85bb0909cffd925f4cd5c0022a68a1ff74d3ad8e;hp=e6ba8153f529b191dd0468c9b2a4439bd2cbdbda;hpb=4d20ef52acecafc3c3aa0f22b8268e5468352022;p=civicrm-core.git diff --git a/api/v3/Relationship.php b/api/v3/Relationship.php index e6ba8153f5..2dede0b650 100644 --- a/api/v3/Relationship.php +++ b/api/v3/Relationship.php @@ -2,9 +2,9 @@ /* +--------------------------------------------------------------------+ - | CiviCRM version 4.3 | + | CiviCRM version 4.5 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2013 | + | Copyright CiviCRM LLC (c) 2004-2014 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -32,7 +32,7 @@ * @package CiviCRM_APIv3 * @subpackage API_Relationship * - * @copyright CiviCRM LLC (c) 2004-2013 + * @copyright CiviCRM LLC (c) 2004-2014 * @version $Id: Relationship.php 30486 2010-11-02 16:12:09Z shot $ * */ @@ -40,15 +40,15 @@ /** * Add or update a relationship * - * @param array $params input parameters + * @param array $params input parameters * + * @throws API_Exception * @example RelationshipCreate.php Std Create example * * @return array API Result Array * {@getfields relationship_create} * @static void * @access public - * */ function civicrm_api3_relationship_create($params) { @@ -56,7 +56,7 @@ function civicrm_api3_relationship_create($params) { _civicrm_api3_relationship_format_params($params, $values); $ids = array(); - if (CRM_Utils_Array::value('id', $params)) { + if (!empty($params['id'])) { $ids['contactTarget'] = $values['contact_id_b']; } @@ -136,8 +136,12 @@ function civicrm_api3_relationship_delete($params) { * @access public */ function civicrm_api3_relationship_get($params) { + $options = _civicrm_api3_get_options_from_params($params); - if (!CRM_Utils_Array::value('contact_id', $params)) { + if (empty($params['contact_id'])) { + if(!empty($params['membership_type_id']) && empty($params['relationship_type_id'])) { + CRM_Contact_BAO_Relationship::membershipTypeToRelationshipTypes($params); + } $relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); } else { @@ -145,15 +149,21 @@ function civicrm_api3_relationship_get($params) { $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], CRM_Utils_Array::value('status_id', $params), 0, - 0, - CRM_Utils_Array::value('id', $params), NULL + CRM_Utils_Array::value('is_count', $options), + CRM_Utils_Array::value('id', $params), + NULL, + NULL, + FALSE, + $params ); } + //perhaps we should add a 'getcount' but at this stage lets just handle getcount output + if($options['is_count']) { + return array('count' => $relationships); + } foreach ($relationships as $relationshipId => $values) { _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id',$values)); } - - return civicrm_api3_create_success($relationships, $params); } @@ -161,11 +171,12 @@ function civicrm_api3_relationship_get($params) { * take the input parameter list as specified in the data model and * convert it into the same format that we use in QF and BAO object * - * @param array $params Associative array of property name/value + * @param array $params Associative array of property name/value * pairs to insert in new contact. - * @param array $values The reformatted properties that we can use internally + * @param array $values The reformatted properties that we can use internally * ' * + * @throws Exception * @return array|CRM_Error * @access public */ @@ -176,7 +187,7 @@ function _civicrm_api3_relationship_format_params($params, &$values) { _civicrm_api3_store_values($fields, $params, $values); $relationTypes = CRM_Core_PseudoConstant::relationshipType('name'); - if (CRM_Utils_Array::value('id', $params)) { + if (!empty($params['id'])) { $relation = new CRM_Contact_BAO_Relationship(); $relation->id = $params['id']; if (!$relation->find(TRUE)) { @@ -234,7 +245,7 @@ function _civicrm_api3_relationship_format_params($params, &$values) { } if ($relationshipTypeId) { - if (CRM_Utils_Array::value('relationship_type_id', $values) && + if (!empty($values['relationship_type_id']) && $relationshipTypeId != $values['relationship_type_id'] ) { throw new Exception('Mismatched Relationship Type and Relationship Type Id');