Merge branch 4.5 into master
[civicrm-core.git] / api / v3 / Contact.php
index 0bdcffdeaf117fe1593b24ed5b635bd566bfb74a..5d97e5362a4ee3f06a12f9c08de1eedf341a7999 100644 (file)
@@ -23,7 +23,7 @@
   | GNU Affero General Public License or the licensing of CiviCRM,     |
   | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * new version of civicrm apis. See blog post at
  * @subpackage API_Contact
  * @copyright CiviCRM LLC (c) 2004-2014
  * $Id: Contact.php 30879 2010-11-22 15:45:55Z shot $
- *
  */
 
 /**
- * Create or update a contact (note you should always call this via civicrm_api() & never directly)
+ * Create or update a contact (note you should always call this via civicrm_api() & never directly).
  *
  * @param array $params
  *   Input parameters.
  *
- * Allowed @params array keys are:
- * {@getfields contact_create}
- *
- *
  * @throws API_Exception
- * @example ContactCreate.php Example of Create Call
  *
  * @return array
  *   API Result Array
- *
- * @static
- * @access public
  */
 function civicrm_api3_contact_create($params) {
 
@@ -71,7 +62,7 @@ function civicrm_api3_contact_create($params) {
       $defLocType = CRM_Core_BAO_LocationType::getDefault();
       $params['email'] = array(
         1 => array(
-      'email' => $email,
+          'email' => $email,
           'is_primary' => 1,
           'location_type_id' => ($defLocType->id) ? $defLocType->id : 1,
         ),
@@ -82,8 +73,8 @@ function civicrm_api3_contact_create($params) {
   if (!empty($params['home_url'])) {
     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     $params['website'] = array(
-    1 => array(
-    'website_type_id' => key($websiteTypes),
+      1 => array(
+        'website_type_id' => key($websiteTypes),
         'url' => $params['home_url'],
       ),
     );
@@ -119,7 +110,7 @@ function civicrm_api3_contact_create($params) {
 }
 
 /**
- * Adjust Metadata for Create action
+ * Adjust Metadata for Create action.
  *
  * @param array $params
  *   Array or parameters determined by getfields.
@@ -141,18 +132,12 @@ function _civicrm_api3_contact_create_spec(&$params) {
 }
 
 /**
- * Retrieve one or more contacts, given a set of search params
+ * Retrieve one or more contacts, given a set of search params.
  *
- * @param array input parameters
+ * @param array $params
  *
  * @return array
  *   API Result Array
- * (@getfields contact_get}
- * @static
- * @access public
- *
- * @example ContactGet.php Standard GET example
- *
  */
 function civicrm_api3_contact_get($params) {
   $options = array();
@@ -162,6 +147,8 @@ function civicrm_api3_contact_get($params) {
 }
 
 /**
+ * Get count of contact.
+ *
  * @param array $params
  *
  * @return int
@@ -174,7 +161,7 @@ function civicrm_api3_contact_getcount($params) {
 }
 
 /**
- * Adjust Metadata for Get action
+ * Adjust Metadata for Get action.
  *
  * @param array $params
  *   Array or parameters determined by getfields.
@@ -182,7 +169,7 @@ function civicrm_api3_contact_getcount($params) {
 function _civicrm_api3_contact_get_spec(&$params) {
   $params['contact_is_deleted']['api.default'] = 0;
 
-  //we declare all these pseudofields as there are other undocumented fields accessible
+  // We declare all these pseudoFields as there are other undocumented fields accessible
   // via the api - but if check permissions is set we only allow declared fields
   $params['address_id']['title'] = 'Primary Address ID';
   $params['street_address']['title'] = 'Primary Address Street Address';
@@ -222,6 +209,8 @@ function _civicrm_api3_contact_get_spec(&$params) {
 }
 
 /**
+ * Support for historical oddities.
+ *
  * We are supporting 'showAll' = 'all', 'trash' or 'active' for contact get
  * and for getcount
  * - hopefully some day we'll come up with a std syntax for the 3-way-boolean of
@@ -267,17 +256,13 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
 }
 
 /**
- * Delete a contact with given contact id
+ * Delete a contact with given contact id.
  *
  * @param array $params
- *   (reference ) input parameters, contact_id element required.
+ *   input parameters per getfields
  *
  * @return array
  *   API Result Array
- * @access public
- *
- * @example ContactDelete.php
- * {@getfields contact_delete}
  */
 function civicrm_api3_contact_delete($params) {
 
@@ -306,17 +291,18 @@ function civicrm_api3_contact_delete($params) {
 
 
 /**
+ * Check parameters passed in.
+ *
+ * This function is on it's way out.
+ *
  * @param array $params
  * @param bool $dupeCheck
- * @param bool $dupeErrorArray
- * @param bool $obsoletevalue
- * @param int $dedupeRuleGroupID
  *
  * @return null
  * @throws API_Exception
  * @throws CiviCRM_API3_Exception
  */
-function _civicrm_api3_contact_check_params(&$params, $dupeCheck = TRUE, $dupeErrorArray = FALSE, $obsoletevalue = TRUE, $dedupeRuleGroupID = NULL) {
+function _civicrm_api3_contact_check_params(&$params, $dupeCheck) {
 
   switch (strtolower(CRM_Utils_Array::value('contact_type', $params))) {
     case 'household':
@@ -405,17 +391,14 @@ function _civicrm_api3_contact_check_params(&$params, $dupeCheck = TRUE, $dupeEr
 }
 
 /**
- * Takes an associative array and creates a contact object and all the associated
- * derived objects (i.e. individual, location, email, phone etc)
+ * Helper function for contact create.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param int $contactID
  *   If present the contact with that ID is updated.
  *
- * @return CRM_Contact_BAO_Contact
- * @access public
- * @static
+ * @return CRM_Contact_BAO_Contact|CRM_Core_Error
  */
 function _civicrm_api3_contact_update($params, $contactID = NULL) {
   //@todo - doesn't contact create support 'id' which is already set- check & remove
@@ -427,15 +410,12 @@ function _civicrm_api3_contact_update($params, $contactID = NULL) {
 }
 
 /**
- * Validate the addressee or email or postal greetings
+ * Validate the addressee or email or postal greetings.
  *
  * @param array $params
- *   Associative array of property name/value.
- *                                   pairs to insert in new contact.
+ *   Array per getfields metadata.
  *
  * @throws API_Exception
- *
- * @access public
  */
 function _civicrm_api3_greeting_format_params($params) {
   $greetingParams = array('', '_id', '_custom');
@@ -446,7 +426,7 @@ function _civicrm_api3_greeting_format_params($params) {
     }
 
     $formatParams = FALSE;
-    // unset display value from params.
+    // Unset display value from params.
     if (isset($params["{$key}{$greeting}_display"])) {
       unset($params["{$key}{$greeting}_display"]);
     }
@@ -555,12 +535,14 @@ function _civicrm_api3_greeting_format_params($params) {
 }
 
 /**
- * Old contact quick search api
+ * Old contact quick search api.
  *
  * @deprecated
  *
- * {@example ContactGetquick.php 0}
+ * @param array $params
  *
+ * @return array
+ * @throws \API_Exception
  */
 function civicrm_api3_contact_getquick($params) {
   civicrm_api3_verify_mandatory($params, NULL, array('name'));
@@ -835,7 +817,7 @@ LIMIT    0, {$limit}
       if ($listCurrentEmployer && !empty($currEmpDetails)) {
         $contactList = array(
           array(
-          'data' => $currEmpDetails['data'],
+            'data' => $currEmpDetails['data'],
             'id'   => $currEmpDetails['id'],
           ),
         );
@@ -855,6 +837,8 @@ LIMIT    0, {$limit}
 }
 
 /**
+ * Declare deprecated api functions.
+ *
  * @deprecated api notice
  * @return array
  *   Array of deprecated actions
@@ -878,9 +862,6 @@ function _civicrm_api3_contact_deprecation() {
  *
  * @return array
  *   API Result Array
- *
- * @static
- * @access public
  */
 function civicrm_api3_contact_merge($params) {
   $mode = CRM_Utils_Array::value('mode', $params, 'safe');
@@ -901,6 +882,8 @@ function civicrm_api3_contact_merge($params) {
 }
 
 /**
+ * Adjust metadata for contact_proximity api function.
+ *
  * @param array $params
  */
 function _civicrm_api3_contact_proximity_spec(&$params) {
@@ -913,6 +896,8 @@ function _civicrm_api3_contact_proximity_spec(&$params) {
 }
 
 /**
+ * Get contacts by proximity.
+ *
  * @param array $params
  *
  * @return array
@@ -964,10 +949,11 @@ WHERE     $whereClause
 
 
 /**
+ * Get parameters for getlist function.
+ *
  * @see _civicrm_api3_generic_getlist_params
  *
- * @param $request
- *   Array.
+ * @param array $request
  */
 function _civicrm_api3_contact_getlist_params(&$request) {
   // get the autocomplete options from settings
@@ -1008,19 +994,25 @@ function _civicrm_api3_contact_getlist_params(&$request) {
 }
 
 /**
+ * Get output for getlist function.
+ *
  * @see _civicrm_api3_generic_getlist_output
  *
- * @param $result
- *   Array.
- * @param $request
- *   Array.
+ * @param array $result
+ * @param array $request
  *
  * @return array
  */
 function _civicrm_api3_contact_getlist_output($result, $request) {
   $output = array();
   if (!empty($result['values'])) {
-    $addressFields = array_intersect(array('street_address', 'city', 'state_province', 'country'), $request['params']['return']);
+    $addressFields = array_intersect(array(
+        'street_address',
+        'city',
+        'state_province',
+        'country',
+      ),
+      $request['params']['return']);
     foreach ($result['values'] as $row) {
       $data = array(
         'id' => $row[$request['id_field']],