本文整理汇总了PHP中CRM_Core_BAO_Block::sortPrimaryFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Block::sortPrimaryFirst方法的具体用法?PHP CRM_Core_BAO_Block::sortPrimaryFirst怎么用?PHP CRM_Core_BAO_Block::sortPrimaryFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Block
的用法示例。
在下文中一共展示了CRM_Core_BAO_Block::sortPrimaryFirst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Takes an associative array and creates a address.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param bool $fixAddress
* True if you need to fix (format) address values.
* before inserting in db
*
* @param null $entity
*
* @return array|NULL
* array of created address
*/
public static function create(&$params, $fixAddress = TRUE, $entity = NULL)
{
if (!isset($params['address']) || !is_array($params['address'])) {
return NULL;
}
CRM_Core_BAO_Block::sortPrimaryFirst($params['address']);
$addresses = array();
$contactId = NULL;
$updateBlankLocInfo = CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE);
if (!$entity) {
$contactId = $params['contact_id'];
//get all the addresses for this contact
$addresses = self::allAddress($contactId);
} else {
// get all address from location block
$entityElements = array('entity_table' => $params['entity_table'], 'entity_id' => $params['entity_id']);
$addresses = self::allEntityAddress($entityElements);
}
$isPrimary = $isBilling = TRUE;
$blocks = array();
foreach ($params['address'] as $key => $value) {
if (!is_array($value)) {
continue;
}
$addressExists = self::dataExists($value);
if (empty($value['id'])) {
if (!empty($addresses) && array_key_exists(CRM_Utils_Array::value('location_type_id', $value), $addresses)) {
$value['id'] = $addresses[CRM_Utils_Array::value('location_type_id', $value)];
}
}
// Note there could be cases when address 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 (isset($value['id']) && !$addressExists && $updateBlankLocInfo) {
//delete the existing record
CRM_Core_BAO_Block::blockDelete('Address', array('id' => $value['id']));
continue;
} elseif (!$addressExists) {
continue;
}
if ($isPrimary && !empty($value['is_primary'])) {
$isPrimary = FALSE;
} else {
$value['is_primary'] = 0;
}
if ($isBilling && !empty($value['is_billing'])) {
$isBilling = FALSE;
} else {
$value['is_billing'] = 0;
}
if (empty($value['manual_geo_code'])) {
$value['manual_geo_code'] = 0;
}
$value['contact_id'] = $contactId;
$blocks[] = self::add($value, $fixAddress);
}
return $blocks;
}
示例2: create
/**
* Takes an associative array and creates a address.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param bool $fixAddress
* True if you need to fix (format) address values.
* before inserting in db
*
* @param null $entity
*
* @return array|NULL
* array of created address
*/
public static function create(&$params, $fixAddress = TRUE, $entity = NULL)
{
if (!isset($params['address']) || !is_array($params['address'])) {
return NULL;
}
CRM_Core_BAO_Block::sortPrimaryFirst($params['address']);
$addresses = array();
$contactId = NULL;
$updateBlankLocInfo = CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE);
if (!$entity) {
$contactId = $params['contact_id'];
//get all the addresses for this contact
$addresses = self::allAddress($contactId);
} else {
// get all address from location block
$entityElements = array('entity_table' => $params['entity_table'], 'entity_id' => $params['entity_id']);
$addresses = self::allEntityAddress($entityElements);
}
$isPrimary = $isBilling = TRUE;
$blocks = array();
foreach ($params['address'] as $key => $value) {
if (!is_array($value)) {
continue;
}
$addressExists = self::dataExists($value);
// If the ID is empty then this is either a new address, or an edit coming
// from a Profile. So we need to match up the location type with any
// that are currently on the contact.
if (empty($value['id']) && !empty($value['location_type_id']) && !empty($addresses)) {
// Does the submitted address type already exist?
if (array_key_exists($value['location_type_id'], $addresses)) {
// Match the address ID and remove from the list so we know its matched
$value['id'] = $addresses[$value['location_type_id']];
unset($addresses[$value['location_type_id']]);
}
}
// Note there could be cases when address 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 (!empty($value['id']) && !$addressExists && $updateBlankLocInfo) {
//delete the existing record
CRM_Core_BAO_Block::blockDelete('Address', array('id' => $value['id']));
continue;
} elseif (!$addressExists) {
continue;
}
if ($isPrimary && !empty($value['is_primary'])) {
$isPrimary = FALSE;
} else {
$value['is_primary'] = 0;
}
if ($isBilling && !empty($value['is_billing'])) {
$isBilling = FALSE;
} else {
$value['is_billing'] = 0;
}
if (empty($value['manual_geo_code'])) {
$value['manual_geo_code'] = 0;
}
$value['contact_id'] = $contactId;
$blocks[] = self::add($value, $fixAddress);
}
// If this is an edit from the full contact edit page then delete any
// addresses that we couldn't match on - because they were deleted on the form
if (!empty($params['isFullContactEdit']) && count($addresses)) {
foreach ($addresses as $addressId) {
CRM_Core_BAO_Block::blockDelete('Address', array('id' => $addressId));
}
}
return $blocks;
}