* 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;
// 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);
}
}
/**
* 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 = [];
return NULL;
}
- $locBlockInfo = self::addLocBlock($locBlock);
- return $locBlockInfo->id;
+ return self::addLocBlock($locBlock)->id;
}
/**
* 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;
}
/**
/**
* 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
* @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)