Merge pull request #7057 from davecivicrm/CRM-17271
[civicrm-core.git] / api / v3 / Relationship.php
index 9e0456e1764bf37c4f502bfb54d2b5644a559acb..71f84029c3969da9dfab3491e26d96365a717290 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  */
 
 /**
- * File for the CiviCRM APIv3 relationship functions
+ * This api exposes CiviCRM relationships.
  *
  * @package CiviCRM_APIv3
- * @subpackage API_Relationship
- *
- * @copyright CiviCRM LLC (c) 2004-2014
- * @version $Id: Relationship.php 30486 2010-11-02 16:12:09Z shot $
  */
 
 /**
@@ -55,7 +51,7 @@ function civicrm_api3_relationship_create($params) {
  * Adjust Metadata for Create action.
  *
  * @param array $params
- *   Array or parameters determined by getfields.
+ *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_relationship_create_spec(&$params) {
   $params['contact_id_a']['api.required'] = 1;
@@ -150,3 +146,26 @@ function _civicrm_api3_handle_relationship_type(&$params) {
     }
   }
 }
+
+/**
+ * Hack to ensure inherited membership got created/deleted on
+ * relationship add/delete respectively.
+ *
+ * @param array $params
+ *   Array per getfields metadata.
+ *
+ * @return array
+ */
+function civicrm_api3_relationship_setvalue($params) {
+  require_once 'api/v3/Generic/Setvalue.php';
+  $result = civicrm_api3_generic_setValue(array("entity" => 'Relationship', 'params' => $params));
+
+  if (empty($result['is_error']) && CRM_Utils_String::munge($params['field']) == 'is_active') {
+    $action = CRM_Core_Action::DISABLE;
+    if ($params['value'] == TRUE) {
+      $action = CRM_Core_Action::ENABLE;
+    }
+    CRM_Contact_BAO_Relationship::disableEnableRelationship($params['id'], $action);
+  }
+  return $result;
+}