X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FBlock.php;h=c9bb3402d04eef330bd6a5c25d5ed309f2f626c3;hb=da6b46f4a1c9a3dfd1502637efad4fa003eee61a;hp=46f796b282b0479aa518a84d3afd5046a2e5f902;hpb=6bc3f2dc2e311d196a583dedf520a28017df8a6c;p=civicrm-core.git diff --git a/CRM/Core/BAO/Block.php b/CRM/Core/BAO/Block.php index 46f796b282..c9bb3402d0 100644 --- a/CRM/Core/BAO/Block.php +++ b/CRM/Core/BAO/Block.php @@ -1,9 +1,9 @@ $blockValue) { - if (CRM_Utils_Array::value('is_primary', $blockValue)) { + if (!empty($blockValue['is_primary'])) { $resetPrimaryId = $blockId; break; } @@ -294,12 +300,12 @@ class CRM_Core_BAO_Block { ); //check for update - if (!CRM_Utils_Array::value('id', $value) && + if (empty($value['id']) && is_array($blockIds) && !empty($blockIds) ) { foreach ($blockIds as $blockId => $blockValue) { if ($updateBlankLocInfo) { - if (CRM_Utils_Array::value($count, $blockIds)) { + if (!empty($blockIds[$count])) { $value['id'] = $blockIds[$count]['id']; unset($blockIds[$count]); } @@ -327,7 +333,7 @@ class CRM_Core_BAO_Block { if ($valueId) { //assigned id as first come first serve basis $value['id'] = $blockValue['id']; - if (!$primaryId && CRM_Utils_Array::value('is_primary', $blockValue)) { + if (!$primaryId && !empty($blockValue['is_primary'])) { $value['is_primary'] = $blockValue['is_primary']; } unset($blockIds[$blockId]); @@ -343,7 +349,7 @@ class CRM_Core_BAO_Block { // Note there could be cases when block info already exist ($value[id] is set) for a contact/entity // BUT info is not present at this time, and therefore we should be really careful when deleting the block. // $updateBlankLocInfo will help take appropriate decision. CRM-5969 - if (CRM_Utils_Array::value('id', $value) && !$dataExits && $updateBlankLocInfo) { + if (!empty($value['id']) && !$dataExits && $updateBlankLocInfo) { //delete the existing record self::blockDelete($blockName, array('id' => $value['id'])); continue; @@ -352,7 +358,7 @@ class CRM_Core_BAO_Block { continue; } - if ($isPrimary && CRM_Utils_Array::value('is_primary', $value)) { + if ($isPrimary && !empty($value['is_primary'])) { $contactFields['is_primary'] = $value['is_primary']; $isPrimary = FALSE; } @@ -360,7 +366,7 @@ class CRM_Core_BAO_Block { $contactFields['is_primary'] = 0; } - if ($isBilling && CRM_Utils_Array::value('is_billing', $value)) { + if ($isBilling && !empty($value['is_billing'])) { $contactFields['is_billing'] = $value['is_billing']; $isBilling = FALSE; } @@ -376,7 +382,7 @@ class CRM_Core_BAO_Block { // we need to delete blocks that were deleted during update if ($updateBlankLocInfo && !empty($blockIds)) { foreach ($blockIds as $deleteBlock) { - if (!CRM_Utils_Array::value('id', $deleteBlock)) { + if (empty($deleteBlock['id'])) { continue; } self::blockDelete($blockName, array('id' => $deleteBlock['id'])); @@ -424,29 +430,24 @@ class CRM_Core_BAO_Block { * - if no other entry is 1 change to 1 * - if one other entry exists change that to 1 * - if more than one other entry exists change first one to 1 - * @fixme - perhaps should choose by location_type + * @fixme - perhaps should choose by location_type * # empty - same as 0 as once we have checked first step * we know if it should be 1 or 0 * * if $params['id'] is set $params['contact_id'] may need to be retrieved * - * @param array $params + * @param array $params + * @param $class + * + * @throws API_Exception * @static */ public static function handlePrimary(&$params, $class) { - switch ($class) { - case 'CRM_Core_BAO_Phone': - $table = 'civicrm_phone'; - break; - - case 'CRM_Core_BAO_Email': - $table = 'civicrm_email'; - break; - - case 'CRM_Core_BAO_Address': - $table = 'civicrm_address'; - break; + $table = CRM_Core_DAO_AllCoreTables::getTableForClass($class); + if (!$table) { + throw new API_Exception("Failed to locate table for class [$class]"); } + // contact_id in params might be empty or the string 'null' so cast to integer $contactId = (int) CRM_Utils_Array::value('contact_id', $params); // If id is set & we haven't been passed a contact_id, retrieve it @@ -462,7 +463,7 @@ class CRM_Core_BAO_Block { } // if params is_primary then set all others to not be primary & exit out - if (CRM_Utils_Array::value('is_primary', $params)) { + if (!empty($params['is_primary'])) { $sql = "UPDATE $table SET is_primary = 0 WHERE contact_id = %1"; $sqlParams = array(1 => array($contactId, 'Integer')); // we don't want to create unecessary entries in the log_ tables so exclude the one we are working on