System.get API - Return system details (PHP+MySQL version, ad nauseum)
[civicrm-core.git] / api / v3 / Relationship.php
index 5a36bc353460109ac5ba4f240a037d723d89fd90..234b40c57686efbe39b3d754a7e0e27b8fa96162 100644 (file)
@@ -1,10 +1,9 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
- * 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 $
- *
  */
 
 /**
- * Add or update a relationship
+ * Add or update a relationship.
  *
  * @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) {
   _civicrm_api3_handle_relationship_type($params);
@@ -58,10 +48,10 @@ function civicrm_api3_relationship_create($params) {
 }
 
 /**
- * Adjust Metadata for Create action
+ * 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;
@@ -71,17 +61,12 @@ function _civicrm_api3_relationship_create_spec(&$params) {
 }
 
 /**
- * Delete a relationship
+ * Delete a relationship.
  *
  * @param array $params
  *
  * @return array
  *   API Result Array
- * {@getfields relationship_delete}
- * @example RelationshipDelete.php Delete Example
- *
- * @static void
- * @access public
  */
 function civicrm_api3_relationship_delete($params) {
 
@@ -101,19 +86,17 @@ function civicrm_api3_relationship_delete($params) {
 }
 
 /**
- * get the relationship
+ * Get one or more relationship/s.
  *
  * @param array $params
  *   Input parameters.
+ *
  * @todo  Result is inconsistent depending on whether contact_id is passed in :
  * -  if you pass in contact_id - it just returns all relationships for 'contact_id'
  * -  if you don't pass in contact_id then it does a filter on the relationship table (DAO based search)
  *
- * @return Array
+ * @return array
  *   API Result Array
- * {@getfields relationship_get}
- * @example RelationshipGet.php
- * @access  public
  */
 function civicrm_api3_relationship_get($params) {
   $options = _civicrm_api3_get_options_from_params($params);
@@ -147,7 +130,7 @@ function civicrm_api3_relationship_get($params) {
 }
 
 /**
- * legacy handling for relationship_type parameter
+ * Legacy handling for relationship_type parameter.
  *
  * @param array $params
  *   Associative array of property name/value.
@@ -163,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;
+}