Merge pull request #18997 from eileenmcnaughton/trans
[civicrm-core.git] / CRM / Core / BAO / Location.php
index 6af1d85bc8cf9cf639737ff56d3f7dc66d953944..c19fd727c699988fc9b66a9255c7f478feac0d28 100644 (file)
@@ -35,11 +35,9 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
    *   True if you need to fix (format) address values.
    *                               before inserting in db
    *
-   * @param null $entity
-   *
    * @return array
    */
-  public static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
+  public static function create(&$params, $fixAddress = TRUE) {
     $location = [];
     if (!self::dataExists($params)) {
       return $location;
@@ -47,30 +45,11 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
 
     // create location blocks.
     foreach (self::$blocks as $block) {
-      if ($block != 'address') {
-        $location[$block] = CRM_Core_BAO_Block::create($block, $params, $entity);
-      }
-      else {
-        $location[$block] = CRM_Core_BAO_Address::create($params, $fixAddress, $entity);
+      if ($block !== 'address') {
+        $location[$block] = CRM_Core_BAO_Block::create($block, $params);
       }
-    }
-
-    if ($entity) {
-      // this is a special case for adding values in location block table
-      $entityElements = [
-        'entity_table' => $params['entity_table'],
-        'entity_id' => $params['entity_id'],
-      ];
-
-      $location['id'] = self::createLocBlock($location, $entityElements);
-    }
-    else {
-      // when we come from a form which displays all the location elements (like the edit form or the inline block
-      // elements, we can skip the below check. The below check adds quite a feq queries to an already overloaded
-      // form
-      if (empty($params['updateBlankLocInfo'])) {
-        // make sure contact should have only one primary block, CRM-5051
-        self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params));
+      elseif (is_array($params['address'] ?? NULL)) {
+        $location[$block] = CRM_Core_BAO_Address::legacyCreate($params, $fixAddress);
       }
     }
 
@@ -80,12 +59,13 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
   /**
    * Creates the entry in the civicrm_loc_block.
    *
-   * @param string $location
+   * @param array $location
    * @param array $entityElements
    *
    * @return int
    */
-  public static function createLocBlock(&$location, &$entityElements) {
+  public static function createLocBlock($location, $entityElements) {
+    CRM_Core_Error::deprecatedFunctionWarning('Use LocBlock api');
     $locId = self::findExisting($entityElements);
     $locBlock = [];
 
@@ -116,8 +96,7 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
       return NULL;
     }
 
-    $locBlockInfo = self::addLocBlock($locBlock);
-    return $locBlockInfo->id;
+    return self::addLocBlock($locBlock)->id;
   }
 
   /**
@@ -147,17 +126,15 @@ WHERE e.id = %1";
    * Takes an associative array and adds location block.
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return CRM_Core_BAO_locBlock
+   * @return CRM_Core_DAO_LocBlock
    *   Object on success, null otherwise
    */
-  public static function addLocBlock(&$params) {
+  public static function addLocBlock($params) {
     $locBlock = new CRM_Core_DAO_LocBlock();
-
     $locBlock->copyValues($params);
-
-    return $locBlock->save();
+    $locBlock->save();
+    return $locBlock;
   }
 
   /**
@@ -255,6 +232,10 @@ WHERE e.id = %1";
   /**
    * Delete all the block associated with the location.
    *
+   * Note a universe search on 1 Oct 2020 found no calls to this function.
+   *
+   * @deprecated
+   *
    * @param int $contactId
    *   Contact id.
    * @param int $locationTypeId
@@ -262,6 +243,7 @@ WHERE e.id = %1";
    * @throws CRM_Core_Exception
    */
   public static function deleteLocationBlocks($contactId, $locationTypeId) {
+    CRM_Core_Error::deprecatedFunctionWarning('Use v4 api');
     // ensure that contactId has a value
     if (empty($contactId) ||
       !CRM_Utils_Rule::positiveInteger($contactId)