Skip to content

Commit

Permalink
CRM-11799 fix on form is_primary for address handling
Browse files Browse the repository at this point in the history
CRM-11799 fix on form is_primary for address handling
  • Loading branch information
eileenmcnaughton committed Feb 27, 2013
1 parent d36fb4d commit 9d3a2fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 1 addition & 3 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1860,9 +1860,7 @@ static function formatProfileContactParams(&$params, &$fields, $contactID = NULL
$data[$blockName][$loc]['is_primary'] = 1;
}
}
elseif (($locTypeId == $defaultLocationId || $locTypeId == $billingLocationTypeId) &&
($loc == 1 || !CRM_Utils_Array::retrieveValueRecursive($data['location'][$loc - 1], 'is_primary'))
) {
elseif ($locTypeId == $defaultLocationId) {
$data[$blockName][$loc]['is_primary'] = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static function create(&$params, $fixAddress, $entity = NULL) {
) {
return;
}

CRM_Core_BAO_Block::sortPrimaryFirst($params['address']);
$addresses = array();
$contactId = NULL;

Expand Down
25 changes: 24 additions & 1 deletion CRM/Core/BAO/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ public static function handlePrimary(&$params, $class) {
elseif (CRM_Utils_Array::value('contact_id', $params)) {
$contactId = $params['contact_id'];
}

if ( !$contactId ) {
// entity not associated with contact so concept of is_primary not relevant
return;
Expand Down Expand Up @@ -494,5 +493,29 @@ public static function handlePrimary(&$params, $class) {
$existingEntities->save();
}
}

/**
* Sort location array so primary element is first
* @param Array $location
*/
static function sortPrimaryFirst(&$locations){
uasort($locations, 'self::primaryComparison');
}

/**
* compare 2 locations to see which should go first based on is_primary
* (sort function for sortPrimaryFirst)
* @param array $location1
* @param array_type $location2
* @return number
*/
static function primaryComparison($location1, $location2){
$l1 = CRM_Utils_Array::value('is_primary', $location1);
$l2 = CRM_Utils_Array::value('is_primary', $location2);
if ($l1 == $l2) {
return 0;
}
return ($l1 < $l2) ? -1 : 1;
}
}

0 comments on commit 9d3a2fb

Please sign in to comment.