Merge pull request #6457 from GinkgoFJG/angular_snippets
[civicrm-core.git] / CRM / Contact / BAO / Individual.php
index aa2b0c02f1282b480ff232c1ea9c70ec3b4ca2ae..245b59059ed43859366f33c9b1325d7178b6710e 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | 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        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -45,18 +45,18 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
   }
 
   /**
-   * Function is used to format the individual contact values
+   * Function is used to format the individual contact values.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
-   * @param array $contact
+   * @param CRM $contact
    *   Contact object.
    *
    * @return CRM_Contact_BAO_Contact
    */
   public static function format(&$params, &$contact) {
     if (!self::dataExists($params)) {
-      return;
+      return NULL;
     }
 
     // "null" value for example is passed by dedupe merge in order to empty.
@@ -254,7 +254,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
     }
 
     //now set the names.
-    $names = array('sortName' => 'sort_name', 'displayName' => 'display_name');
+    $names = array('displayName' => 'display_name', 'sortName' => 'sort_name');
     foreach ($names as $value => $name) {
       if (empty($$value)) {
         if ($email) {
@@ -263,6 +263,13 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
         elseif ($uniqId) {
           $$value = $uniqId;
         }
+        elseif (!empty($params[$name])) {
+          $$value = $params[$name];
+        }
+        // If we have nothing else going on set sort_name to display_name.
+        elseif ($displayName) {
+          $$value = $displayName;
+        }
       }
       //finally if we could not pass anything lets keep db.
       if (!empty($$value)) {
@@ -274,7 +281,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
     if ($date = CRM_Utils_Array::value('birth_date', $params)) {
       if (in_array($format, array(
         'dd-mm',
-        'mm/dd'
+        'mm/dd',
       ))) {
         $separator = '/';
         if ($format == 'dd-mm') {
@@ -283,17 +290,17 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
         $date = $date . $separator . '1902';
       }
       elseif (in_array($format, array(
-        'yy-mm'
+        'yy-mm',
       ))) {
         $date = $date . '-01';
       }
       elseif (in_array($format, array(
-        'M yy'
+        'M yy',
       ))) {
         $date = $date . '-01';
       }
       elseif (in_array($format, array(
-        'yy'
+        'yy',
       ))) {
         $date = $date . '-01-01';
       }
@@ -306,7 +313,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
     if ($date = CRM_Utils_Array::value('deceased_date', $params)) {
       if (in_array($format, array(
         'dd-mm',
-        'mm/dd'
+        'mm/dd',
       ))) {
         $separator = '/';
         if ($format == 'dd-mm') {
@@ -315,17 +322,17 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
         $date = $date . $separator . '1902';
       }
       elseif (in_array($format, array(
-        'yy-mm'
+        'yy-mm',
       ))) {
         $date = $date . '-01';
       }
       elseif (in_array($format, array(
-        'M yy'
+        'M yy',
       ))) {
         $date = $date . '-01';
       }
       elseif (in_array($format, array(
-        'yy'
+        'yy',
       ))) {
         $date = $date . '-01-01';
       }
@@ -393,7 +400,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
   }
 
   /**
-   * Creates display name
+   * Creates display name.
    *
    * @return string
    *   the constructed display name
@@ -405,18 +412,18 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
   }
 
   /**
-   * Check if there is data to create the object
+   * Check if there is data to create the object.
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return boolean
+   * @return bool
    */
-  public static function dataExists(&$params) {
+  public static function dataExists($params) {
     if ($params['contact_type'] == 'Individual') {
       return TRUE;
     }
 
     return FALSE;
   }
+
 }