INFRA-132 - Batch 14 (g)
[civicrm-core.git] / api / v3 / Contact.php
index 59bf9c07200001950b2c6a0ea9211f8660803b11..4a23bdd0b49182102b2562cccb69226c41e02687 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
   +--------------------------------------------------------------------+
-  | CiviCRM version 4.5                                                |
+  | CiviCRM version 4.6                                                |
   +--------------------------------------------------------------------+
   | Copyright CiviCRM LLC (c) 2004-2014                                |
   +--------------------------------------------------------------------+
@@ -40,7 +40,8 @@
 /**
  * Create or update a contact (note you should always call this via civicrm_api() & never directly)
  *
- * @param  array $params input parameters
+ * @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
+ * @return array
+ *   API Result Array
  *
- * @static void
- * @access public
  */
 function civicrm_api3_contact_create($params) {
 
@@ -68,7 +68,8 @@ function civicrm_api3_contact_create($params) {
     if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
       $defLocType = CRM_Core_BAO_LocationType::getDefault();
       $params['email'] = array(
-        1 => array('email' => $email,
+        1 => array(
+      'email' => $email,
           'is_primary' => 1,
           'location_type_id' => ($defLocType->id) ? $defLocType->id : 1,
         ),
@@ -78,7 +79,9 @@ 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),
+    $params['website'] = array(
+    1 => array(
+    'website_type_id' => key($websiteTypes),
         'url' => $params['home_url'],
       ),
     );
@@ -116,7 +119,8 @@ function civicrm_api3_contact_create($params) {
 /**
  * Adjust Metadata for Create action
  *
- * @param array $params array or parameters determined by getfields
+ * @param array $params
+ *   Array or parameters determined by getfields.
  */
 function _civicrm_api3_contact_create_spec(&$params) {
   $params['contact_type']['api.required'] = 1;
@@ -137,15 +141,10 @@ function _civicrm_api3_contact_create_spec(&$params) {
 /**
  * Retrieve one or more contacts, given a set of search params
  *
- * @param  array  input parameters
- *
- * @return array API Result Array
- * (@getfields contact_get}
- * @static void
- * @access public
- *
- * @example ContactGet.php Standard GET example
+ * @param array input parameters
  *
+ * @return array
+ *   API Result Array
  */
 function civicrm_api3_contact_get($params) {
   $options = array();
@@ -162,14 +161,15 @@ function civicrm_api3_contact_get($params) {
 function civicrm_api3_contact_getcount($params) {
   $options = array();
   _civicrm_api3_contact_get_supportanomalies($params, $options);
-  $count = _civicrm_api3_get_using_query_object('contact', $params, $options,1);
+  $count = _civicrm_api3_get_using_query_object('contact', $params, $options, 1);
   return (int) $count;
 }
 
 /**
  * Adjust Metadata for Get action
  *
- * @param array $params array or parameters determined by getfields
+ * @param array $params
+ *   Array or parameters determined by getfields.
  */
 function _civicrm_api3_contact_get_spec(&$params) {
   $params['contact_is_deleted']['api.default'] = 0;
@@ -209,7 +209,7 @@ function _civicrm_api3_contact_get_spec(&$params) {
   $params['tag']['title'] = 'Assigned tags (filter, array)';
   $params['birth_date_low'] = array('name' => 'birth_date_low', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birth Date is equal to or greater than'));
   $params['birth_date_high'] = array('name' => 'birth_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birth Date is equal to or less than'));
-  $params['deceased_date_low'] = array('name' => 'deceased_date_low','type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or greater than'));
+  $params['deceased_date_low'] = array('name' => 'deceased_date_low', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or greater than'));
   $params['deceased_date_high'] = array('name' => 'deceased_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Deceased Date is equal to or less than'));
 }
 
@@ -221,8 +221,10 @@ function _civicrm_api3_contact_get_spec(&$params) {
  *
  * We also support 'filter_group_id' & 'filter.group_id'
  *
- * @param array $params as passed into api get or getcount function
- * @param array $options array of options (so we can modify the filter)
+ * @param array $params
+ *   As passed into api get or getcount function.
+ * @param array $options
+ *   Array of options (so we can modify the filter).
  */
 function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
   if (isset($params['showAll'])) {
@@ -246,7 +248,9 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
     if (is_array($params['filter.group_id'])) {
       $groups = $params['filter.group_id'];
     }
-    else $groups = explode(',', $params['filter.group_id']);
+    else {
+      $groups = explode(',', $params['filter.group_id']);
+    }
     unset($params['filter.group_id']);
     $groups = array_flip($groups);
     $groups[key($groups)] = 1;
@@ -257,13 +261,11 @@ function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
 /**
  * Delete a contact with given contact id
  *
- * @param  array       $params (reference ) input parameters, contact_id element required
- *
- * @return array API Result Array
- * @access public
+ * @param array $params
+ *   input parameters per getfields
  *
- * @example ContactDelete.php
- * {@getfields contact_delete}
+ * @return array
+ *   API Result Array
  */
 function civicrm_api3_contact_delete($params) {
 
@@ -294,33 +296,31 @@ function civicrm_api3_contact_delete($params) {
 /**
  * @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':
-      civicrm_api3_verify_mandatory($params, null, array('household_name'));
+      civicrm_api3_verify_mandatory($params, NULL, array('household_name'));
       break;
+
     case 'organization':
-      civicrm_api3_verify_mandatory($params, null, array('organization_name'));
+      civicrm_api3_verify_mandatory($params, NULL, array('organization_name'));
       break;
+
     case 'individual':
-      civicrm_api3_verify_one_mandatory($params, null, array(
+      civicrm_api3_verify_one_mandatory($params, NULL, array(
         'first_name',
         'last_name',
         'email',
         'display_name',
       )
-    );
-    break;
+      );
+      break;
   }
 
   // Fixme: This really needs to be handled at a lower level. @See CRM-13123
@@ -329,10 +329,10 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
   }
 
   if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
-      if (!(CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
-        throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array)$params['contact_sub_type']));
-      }
+    if (!(CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
+      throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
     }
+  }
 
   if ($dupeCheck) {
     // check for record already existing
@@ -348,8 +348,8 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
 
     $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Unsupervised', array());
 
-    if (count($ids) >0) {
-      throw new API_Exception("Found matching contacts: ". implode(',',$ids),"duplicate",array("ids"=>$ids));
+    if (count($ids) > 0) {
+      throw new API_Exception("Found matching contacts: " . implode(',', $ids), "duplicate", array("ids" => $ids));
     }
   }
 
@@ -380,7 +380,7 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
     else {
       $result = civicrm_api3('contact', 'create', array(
         'organization_name' => $params['current_employer'],
-        'contact_type' => 'Organization'
+        'contact_type' => 'Organization',
       ));
       $params['employer_id'] = $result['id'];
     }
@@ -393,12 +393,12 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE
  * Takes an associative array and creates a contact object and all the associated
  * derived objects (i.e. individual, location, email, phone etc)
  *
- * @param array $params (reference ) an assoc array of name/value pairs
- * @param  int     $contactID        if present the contact with that ID is updated
+ * @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 object
- * @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
@@ -412,12 +412,12 @@ function _civicrm_api3_contact_update($params, $contactID = NULL) {
 /**
  * Validate the addressee or email or postal greetings
  *
- * @param  array $params  Associative array of property name/value
+ * @param array $params
+ *   Associative array of property name/value.
  *                                   pairs to insert in new contact.
  *
  * @throws API_Exception
  *
- * @access public
  */
 function _civicrm_api3_greeting_format_params($params) {
   $greetingParams = array('', '_id', '_custom');
@@ -501,13 +501,11 @@ function _civicrm_api3_greeting_format_params($params) {
       $greetingId = CRM_Utils_Array::key('Customized', $greetings);
     }
 
-    $customValue = isset($params['contact_id']) ?
-      CRM_Core_DAO::getFieldValue(
+    $customValue = isset($params['contact_id']) ? CRM_Core_DAO::getFieldValue(
         'CRM_Contact_DAO_Contact',
         $params['contact_id'],
         "{$key}{$greeting}_custom"
-      ) :
-      FALSE;
+      ) : FALSE;
 
     if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
       $nullValue = TRUE;
@@ -544,7 +542,9 @@ function _civicrm_api3_greeting_format_params($params) {
  * @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'));
@@ -575,7 +575,7 @@ function civicrm_api3_contact_getquick($params) {
     }
     // phone_numeric should be phone
     $searchField = str_replace('_numeric', '', $field_name);
-    if(!in_array($searchField, $list)) {
+    if (!in_array($searchField, $list)) {
       $list[] = $searchField;
     }
   }
@@ -801,7 +801,7 @@ LIMIT    0, {$limit}
   while ($dao->fetch()) {
     $t = array('id' => $dao->id);
     foreach ($as as $k) {
-      $t[$k] = isset($dao->$k)? $dao->$k: '';
+      $t[$k] = isset($dao->$k) ? $dao->$k : '';
     }
     $t['data'] = $dao->data;
     $contactList[] = $t;
@@ -820,16 +820,16 @@ LIMIT    0, {$limit}
         $contactList = array(
           array(
           'data' => $currEmpDetails['data'],
-            'id'   => $currEmpDetails['id']
-          )
+            'id'   => $currEmpDetails['id'],
+          ),
         );
       }
       else {
         $contactList = array(
           array(
             'data' => $name,
-            'id'   => $name
-          )
+            'id'   => $name,
+          ),
         );
       }
     }
@@ -840,7 +840,8 @@ LIMIT    0, {$limit}
 
 /**
  * @deprecated api notice
- * @return array of deprecated actions
+ * @return array
+ *   Array of deprecated actions
  */
 function _civicrm_api3_contact_deprecation() {
   return array('getquick' => 'The "getquick" action is deprecated in favor of "getlist".');
@@ -849,7 +850,8 @@ function _civicrm_api3_contact_deprecation() {
 /**
  * Merges given pair of duplicate contacts.
  *
- * @param  array   $params   input parameters
+ * @param array $params
+ *   Input parameters.
  *
  * Allowed @params array keys are:
  * {int     main_id     main contact id with whom merge has to happen}
@@ -858,16 +860,16 @@ function _civicrm_api3_contact_deprecation() {
  *                      A 'safe' value skips the merge if there are no conflicts. Does a force merge otherwise.}
  * {boolean auto_flip   wether to let api decide which contact to retain and which to delete.}
  *
- * @return array  API Result Array
+ * @return array
+ *   API Result Array
  *
- * @static void
- * @access public
  */
 function civicrm_api3_contact_merge($params) {
   $mode = CRM_Utils_Array::value('mode', $params, 'safe');
   $autoFlip = CRM_Utils_Array::value('auto_flip', $params, TRUE);
 
-  $dupePairs = array(array('srcID' => CRM_Utils_Array::value('main_id', $params),
+  $dupePairs = array(array(
+  'srcID' => CRM_Utils_Array::value('main_id', $params),
       'dstID' => CRM_Utils_Array::value('other_id', $params),
     ));
   $result = CRM_Dedupe_Merger::merge($dupePairs, array(), $mode, $autoFlip);
@@ -946,7 +948,8 @@ WHERE     $whereClause
 /**
  * @see _civicrm_api3_generic_getlist_params
  *
- * @param $request array
+ * @param $request
+ *   Array.
  */
 function _civicrm_api3_contact_getlist_params(&$request) {
   // get the autocomplete options from settings
@@ -973,7 +976,7 @@ function _civicrm_api3_contact_getlist_params(&$request) {
   }
   // phone_numeric should be phone
   $searchField = str_replace('_numeric', '', $field_name);
-  if(!in_array($searchField, $list)) {
+  if (!in_array($searchField, $list)) {
     $list[] = $searchField;
   }
   $request['description_field'] = $list;
@@ -989,8 +992,10 @@ function _civicrm_api3_contact_getlist_params(&$request) {
 /**
  * @see _civicrm_api3_generic_getlist_output
  *
- * @param $result array
- * @param $request array
+ * @param $result
+ *   Array.
+ * @param $request
+ *   Array.
  *
  * @return array
  */
@@ -1010,7 +1015,7 @@ function _civicrm_api3_contact_getlist_output($result, $request) {
         }
       }
       $address = array();
-      foreach($addressFields as $item) {
+      foreach ($addressFields as $item) {
         if (!empty($row[$item])) {
           $address[] = $row[$item];
         }