本文整理汇总了PHP中CRM_Contact_BAO_RelationshipType::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_RelationshipType::retrieve方法的具体用法?PHP CRM_Contact_BAO_RelationshipType::retrieve怎么用?PHP CRM_Contact_BAO_RelationshipType::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_RelationshipType
的用法示例。
在下文中一共展示了CRM_Contact_BAO_RelationshipType::retrieve方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: relationship
/**
* where / qill clause for relationship
*
* @return void
* @access public
*/
function relationship(&$values)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
// also get values array for relation_target_name
// for relatinship search we always do wildcard
$targetName = $this->getWhereValues('relation_target_name', $grouping);
$relStatus = $this->getWhereValues('relation_status', $grouping);
$targetGroup = $this->getWhereValues('relation_target_group', $grouping);
$nameClause = $name = NULL;
if ($targetName) {
$name = trim($targetName[2]);
if (substr($name, 0, 1) == '"' && substr($name, -1, 1) == '"') {
$name = substr($name, 1, -1);
$name = strtolower(CRM_Core_DAO::escapeString($name));
$nameClause = "= '{$name}'";
} else {
$name = strtolower(CRM_Core_DAO::escapeString($name));
$nameClause = "LIKE '%{$name}%'";
}
}
$rel = explode('_', $value);
self::$_relType = $rel[1];
$params = array('id' => $rel[0]);
$rTypeValues = array();
$rType = CRM_Contact_BAO_RelationshipType::retrieve($params, $rTypeValues);
if (!$rType) {
return;
}
if ($rTypeValues['name_a_b'] == $rTypeValues['name_b_a']) {
self::$_relType = 'reciprocal';
}
if ($nameClause) {
$this->_where[$grouping][] = "( contact_b.sort_name {$nameClause} AND contact_b.id != contact_a.id )";
}
$relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
$relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
$relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
$allRelationshipType = array();
$allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
$allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
if ($nameClause || !$targetGroup) {
$this->_qill[$grouping][] = "{$allRelationshipType[$value]} {$name}";
}
//check to see if the target contact is in specified group
if ($targetGroup) {
//add contacts from static groups
$this->_tables['civicrm_relationship_group_contact'] = $this->_whereTables['civicrm_relationship_group_contact'] = " LEFT JOIN civicrm_group_contact civicrm_relationship_group_contact ON civicrm_relationship_group_contact.contact_id = contact_b.id";
$groupWhere[] = "( civicrm_relationship_group_contact.group_id IN (" . implode(",", $targetGroup[2]) . ") )";
//add contacts from saved searches
$ssWhere = $this->addGroupContactCache($targetGroup[2], "civicrm_relationship_group_contact_cache", "contact_b");
//set the group where clause
if ($ssWhere) {
$groupWhere[] = "( " . $ssWhere . " )";
}
$this->_where[$grouping][] = "( " . implode(" OR ", $groupWhere) . " )";
//Get the names of the target groups for the qill
$groupNames =& CRM_Core_PseudoConstant::group();
$qillNames = array();
foreach ($targetGroup[2] as $groupId) {
if (array_key_exists($groupId, $groupNames)) {
$qillNames[] = $groupNames[$groupId];
}
}
$this->_qill[$grouping][] = "{$allRelationshipType[$value]} ( " . implode(", ", $qillNames) . " )";
}
//check for active, inactive and all relation status
$today = date('Ymd');
if ($relStatus[2] == 0) {
$this->_where[$grouping][] = "(\ncivicrm_relationship.is_active = 1 AND\n( civicrm_relationship.end_date IS NULL OR civicrm_relationship.end_date >= {$today} ) AND\n( civicrm_relationship.start_date IS NULL OR civicrm_relationship.start_date <= {$today} )\n)";
$this->_qill[$grouping][] = ts('Relationship - Active');
} elseif ($relStatus[2] == 1) {
$this->_where[$grouping][] = "(\ncivicrm_relationship.is_active = 0 OR\ncivicrm_relationship.end_date < {$today} OR\ncivicrm_relationship.start_date > {$today}\n)";
$this->_qill[$grouping][] = ts('Relationship - Inactive');
}
$this->_where[$grouping][] = 'civicrm_relationship.relationship_type_id = ' . $rel[0];
$this->_tables['civicrm_relationship'] = $this->_whereTables['civicrm_relationship'] = 1;
$this->_useDistinct = TRUE;
}
示例2: checkMembershipRelationship
/**
* Check the membership extended through relationship.
*
* @param int $membershipId
* Membership id.
* @param int $contactId
* Contact id.
*
* @param int $action
*
* @return array
* array of contact_id of all related contacts.
*/
public static function checkMembershipRelationship($membershipId, $contactId, $action = CRM_Core_Action::ADD)
{
$contacts = array();
$membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipId, 'membership_type_id');
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
$relationships = array();
if (isset($membershipType['relationship_type_id'])) {
$relationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT);
if ($action & CRM_Core_Action::UPDATE) {
$pastRelationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::PAST);
$relationships = array_merge($relationships, $pastRelationships);
}
}
if (!empty($relationships)) {
// check for each contact relationships
foreach ($relationships as $values) {
//get details of the relationship type
$relType = array('id' => $values['civicrm_relationship_type_id']);
$relValues = array();
CRM_Contact_BAO_RelationshipType::retrieve($relType, $relValues);
// Check if contact's relationship type exists in membership type
$relTypeDirs = array();
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
$bidirectional = FALSE;
foreach ($relTypeIds as $key => $value) {
$relTypeDirs[] = $value . '_' . $relDirections[$key];
if (in_array($value, $relType) && $relValues['name_a_b'] == $relValues['name_b_a']) {
$bidirectional = TRUE;
break;
}
}
$relTypeDir = $values['civicrm_relationship_type_id'] . '_' . $values['rtype'];
if ($bidirectional || in_array($relTypeDir, $relTypeDirs)) {
// $values['status'] is going to have value for
// current or past relationships.
$contacts[$values['cid']] = $values['status'];
}
}
}
// Sort by contact_id ascending
ksort($contacts);
return $contacts;
}
示例3: relationship
/**
* Where / qill clause for relationship.
*
* @param array $values
*/
public function relationship(&$values)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
if ($this->_relationshipValuesAdded) {
return;
}
// also get values array for relation_target_name
// for relationship search we always do wildcard
$relationType = $this->getWhereValues('relation_type_id', $grouping);
$targetName = $this->getWhereValues('relation_target_name', $grouping);
$relStatus = $this->getWhereValues('relation_status', $grouping);
$relPermission = $this->getWhereValues('relation_permission', $grouping);
$targetGroup = $this->getWhereValues('relation_target_group', $grouping);
$nameClause = $name = NULL;
if ($targetName) {
$name = trim($targetName[2]);
if (substr($name, 0, 1) == '"' && substr($name, -1, 1) == '"') {
$name = substr($name, 1, -1);
$name = strtolower(CRM_Core_DAO::escapeString($name));
$nameClause = "= '{$name}'";
} else {
$name = strtolower(CRM_Core_DAO::escapeString($name));
$nameClause = "LIKE '%{$name}%'";
}
}
$rTypeValues = array();
if (!empty($relationType)) {
$rel = explode('_', $relationType[2]);
self::$_relType = $rel[1];
$params = array('id' => $rel[0]);
$rType = CRM_Contact_BAO_RelationshipType::retrieve($params, $rTypeValues);
}
if (!empty($rTypeValues) && $rTypeValues['name_a_b'] == $rTypeValues['name_b_a']) {
// if we don't know which end of the relationship we are dealing with we'll create a temp table
//@todo unless we are dealing with a target group
self::$_relType = 'reciprocal';
}
// if we are creating a temp table we build our own where for the relationship table
$relationshipTempTable = NULL;
if (self::$_relType == 'reciprocal' && empty($targetGroup)) {
$where = array();
self::$_relationshipTempTable = $relationshipTempTable = CRM_Core_DAO::createTempTableName('civicrm_rel');
if ($nameClause) {
$where[$grouping][] = " sort_name {$nameClause} ";
}
} else {
$where =& $this->_where;
if ($nameClause) {
$where[$grouping][] = "( contact_b.sort_name {$nameClause} AND contact_b.id != contact_a.id )";
}
}
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE);
if ($nameClause || !$targetGroup) {
if (!empty($relationType)) {
$this->_qill[$grouping][] = $allRelationshipType[$relationType[2]] . " {$name}";
} else {
$this->_qill[$grouping][] = $name;
}
}
//check to see if the target contact is in specified group
if ($targetGroup) {
//add contacts from static groups
$this->_tables['civicrm_relationship_group_contact'] = $this->_whereTables['civicrm_relationship_group_contact'] = " LEFT JOIN civicrm_group_contact civicrm_relationship_group_contact ON civicrm_relationship_group_contact.contact_id = contact_b.id AND civicrm_relationship_group_contact.status = 'Added'";
$groupWhere[] = "( civicrm_relationship_group_contact.group_id IN (" . implode(",", $targetGroup[2]) . ") ) ";
//add contacts from saved searches
$ssWhere = $this->addGroupContactCache($targetGroup[2], "civicrm_relationship_group_contact_cache", "contact_b", $op);
//set the group where clause
if ($ssWhere) {
$groupWhere[] = "( " . $ssWhere . " )";
}
$this->_where[$grouping][] = "( " . implode(" OR ", $groupWhere) . " )";
//Get the names of the target groups for the qill
$groupNames = CRM_Core_PseudoConstant::group();
$qillNames = array();
foreach ($targetGroup[2] as $groupId) {
if (array_key_exists($groupId, $groupNames)) {
$qillNames[] = $groupNames[$groupId];
}
}
if (!empty($relationType)) {
$this->_qill[$grouping][] = $allRelationshipType[$relationType[2]] . " ( " . implode(", ", $qillNames) . " )";
} else {
$this->_qill[$grouping][] = implode(", ", $qillNames);
}
}
// Note we do not currently set mySql to handle timezones, so doing this the old-fashioned way
$today = date('Ymd');
//check for active, inactive and all relation status
if ($relStatus[2] == 0) {
$where[$grouping][] = "(\ncivicrm_relationship.is_active = 1 AND\n( civicrm_relationship.end_date IS NULL OR civicrm_relationship.end_date >= {$today} ) AND\n( civicrm_relationship.start_date IS NULL OR civicrm_relationship.start_date <= {$today} )\n)";
$this->_qill[$grouping][] = ts('Relationship - Active and Current');
} elseif ($relStatus[2] == 1) {
$where[$grouping][] = "(\ncivicrm_relationship.is_active = 0 OR\ncivicrm_relationship.end_date < {$today} OR\ncivicrm_relationship.start_date > {$today}\n)";
$this->_qill[$grouping][] = ts('Relationship - Inactive or not Current');
}
//.........这里部分代码省略.........
示例4: relatedMemberships
/**
* Create / update / delete membership for related contacts.
*
* This function will create/update/delete membership for related
* contact based on 1) contact have active membership 2) that
* membership is is extedned by the same relationship type to that
* of the existing relationship.
*
* @param int $contactId
* contact id.
* @param array $params
* array of values submitted by POST.
* @param array $ids
* array of ids.
* @param \const|int $action which action called this function
*
* @param bool $active
*
* @throws \CRM_Core_Exception
*/
public static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = TRUE)
{
// Check the end date and set the status of the relationship
// accordingly.
$status = self::CURRENT;
$targetContact = $targetContact = CRM_Utils_Array::value('contact_check', $params, array());
$today = date('Ymd');
// If a relationship hasn't yet started, just return for now
// TODO: handle edge-case of updating start_date of an existing relationship
if (!empty($params['start_date'])) {
$startDate = substr(CRM_Utils_Date::format($params['start_date']), 0, 8);
if ($today < $startDate) {
return;
}
}
if (!empty($params['end_date'])) {
$endDate = substr(CRM_Utils_Date::format($params['end_date']), 0, 8);
if ($today > $endDate) {
$status = self::PAST;
}
}
if ($action & CRM_Core_Action::ADD && $status & self::PAST) {
// If relationship is PAST and action is ADD, do nothing.
return;
}
$rel = explode('_', $params['relationship_type_id']);
$relTypeId = $rel[0];
if (!empty($rel[1])) {
$relDirection = "_{$rel[1]}_{$rel[2]}";
} else {
// this call is coming from somewhere where the direction was resolved early on (e.g an api call)
// so we can assume _a_b
$relDirection = "_a_b";
$targetContact = array($params['contact_id_b'] => 1);
}
if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
$contact = $contactId;
} elseif ($action & CRM_Core_Action::UPDATE) {
$contact = $ids['contact'];
$targetContact = array($ids['contactTarget'] => 1);
}
// Build the 'values' array for
// 1. ContactA
// 2. ContactB
// This will allow us to check if either of the contacts in
// relationship have active memberships.
$values = array();
// 1. ContactA
$values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
// 2. ContactB
if (!empty($targetContact)) {
foreach ($targetContact as $cid => $donCare) {
$values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
$relTypeParams = array('id' => $relTypeId);
$relTypeValues = array();
CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
$values[$cid]['relationshipTypeDirection'] = '_a_b';
} else {
$values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
}
}
}
// CRM-15829 UPDATES
// If we're looking for active memberships we must consider pending (id: 5) ones too.
// Hence we can't just call CRM_Member_BAO_Membership::getValues below with the active flag, is it would completely miss pending relatioships.
// As suggested by @davecivicrm, the pending status id is fetched using the CRM_Member_PseudoConstant::membershipStatus() class and method, since these ids differ from system to system.
$pendingStatusId = array_search('Pending', CRM_Member_PseudoConstant::membershipStatus());
$query = 'SELECT * FROM `civicrm_membership_status`';
if ($active) {
$query .= ' WHERE `is_current_member` = 1 OR `id` = %1 ';
}
$dao = CRM_Core_DAO::executeQuery($query, array(1 => array($pendingStatusId, 'Integer')));
while ($dao->fetch()) {
$membershipStatusRecordIds[$dao->id] = $dao->id;
}
// Now get the active memberships for all the contacts.
// If contact have any valid membership(s), then add it to
// 'values' array.
foreach ($values as $cid => $subValues) {
//.........这里部分代码省略.........
示例5: relatedMemberships
/**
* Function to create / update / delete membership for related contacts.
*
* This function will create/update/delete membership for related
* contact based on 1) contact have active membership 2) that
* membership is is extedned by the same relationship type to that
* of the existing relationship.
*
* @param $contactId Int contact id
* @param $params array array of values submitted by POST
* @param $ids array array of ids
* @param $action which action called this function
*
* @static
*
*/
static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = TRUE)
{
// Check the end date and set the status of the relationship
// accrodingly.
$status = self::CURRENT;
if (!empty($params['end_date'])) {
$endDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($params['end_date']), NULL, 'Ymd');
$today = date('Ymd');
if ($today > $endDate) {
$status = self::PAST;
}
}
if ($action & CRM_Core_Action::ADD && $status & self::PAST) {
// if relationship is PAST and action is ADD, no qustion
// of creating RELATED membership and return back to
// calling method
return;
}
$rel = explode('_', $params['relationship_type_id']);
$relTypeId = $rel[0];
$relDirection = "_{$rel[1]}_{$rel[2]}";
$targetContact = array();
if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
$contact = $contactId;
$targetContact = CRM_Utils_Array::value('contact_check', $params);
} elseif ($action & CRM_Core_Action::UPDATE) {
$contact = $ids['contact'];
$targetContact = array($ids['contactTarget'] => 1);
}
// Build the 'values' array for
// 1. ContactA
// 2. ContactB
// This will allow us to check if either of the contacts in
// relationship have active memberships.
$values = array();
// 1. ContactA
$values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
// 2. ContactB
if (!empty($targetContact)) {
foreach ($targetContact as $cid => $donCare) {
$values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
$relTypeParams = array('id' => $relTypeId);
$relTypeValues = array();
CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
$values[$cid]['relationshipTypeDirection'] = '_a_b';
} else {
$values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
}
}
}
// Now get the active memberships for all the contacts.
// If contact have any valid membership(s), then add it to
// 'values' array.
foreach ($values as $cid => $subValues) {
$memParams = array('contact_id' => $cid);
$memberships = array();
CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
if (empty($memberships)) {
continue;
}
$values[$cid]['memberships'] = $memberships;
}
$deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus());
// done with 'values' array.
// Finally add / edit / delete memberships for the related contacts
foreach ($values as $cid => $details) {
if (!array_key_exists('memberships', $details)) {
continue;
}
$mainRelatedContactId = key(CRM_Utils_Array::value('relatedContacts', $details, array()));
foreach ($details['memberships'] as $membershipId => $membershipValues) {
$relTypeIds = array();
if ($action & CRM_Core_Action::DELETE) {
// Delete memberships of the related contacts only if relationship type exists for membership type
$query = "\nSELECT relationship_type_id, relationship_direction\n FROM civicrm_membership_type\n WHERE id = {$membershipValues['membership_type_id']}";
$dao = CRM_Core_DAO::executeQuery($query);
$relTypeDirs = array();
while ($dao->fetch()) {
$relTypeId = $dao->relationship_type_id;
$relDirection = $dao->relationship_direction;
}
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $relTypeId);
if (in_array($values[$cid]['relationshipTypeId'], $relTypeIds)) {
//.........这里部分代码省略.........
示例6: checkMembershipRelationship
/**
* Function to check the membership extended through relationship
*
* @param int $membershipId membership id
* @param int $contactId contact id
*
* @return Array array of contact_id of all related contacts.
* @static
*/
static function checkMembershipRelationship($membershipId, $contactId, $action = CRM_Core_Action::ADD)
{
$contacts = array();
$membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipId, 'membership_type_id');
require_once 'CRM/Member/BAO/MembershipType.php';
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
require_once 'CRM/Contact/BAO/Relationship.php';
$relationships = array();
if (isset($membershipType['relationship_type_id'])) {
$relationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::CURRENT);
if ($action & CRM_Core_Action::UPDATE) {
$pastRelationships = CRM_Contact_BAO_Relationship::getRelationship($contactId, CRM_Contact_BAO_Relationship::PAST);
$relationships = array_merge($relationships, $pastRelationships);
}
}
if (!empty($relationships)) {
require_once "CRM/Contact/BAO/RelationshipType.php";
// check for each contact relationships
foreach ($relationships as $values) {
//get details of the relationship type
$relType = array('id' => $values['civicrm_relationship_type_id']);
$relValues = array();
CRM_Contact_BAO_RelationshipType::retrieve($relType, $relValues);
// 1. Check if contact and membership type relationship type are same
// 2. Check if relationship direction is same or name_a_b = name_b_a
if ($values['civicrm_relationship_type_id'] == $membershipType['relationship_type_id'] && ($values['rtype'] == $membershipType['relationship_direction'] || $relValues['name_a_b'] == $relValues['name_b_a'])) {
// $values['status'] is going to have value for
// current or past relationships.
$contacts[$values['cid']] = $values['status'];
}
}
}
return $contacts;
}
示例7: relationshipType
/**
* Where / qill clause for relationship_type
*
* @param $values
*
* @return void
*/
public function relationshipType(&$values)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
$clause = array();
foreach ($value as $k => $relationship_type_value) {
// we gebruiken de key om relaties in 2 richtingen op te vangen.
$relationship_type_id = substr_replace($relationship_type_value, "", -4);
$relationship_type_params = array('id' => $relationship_type_id);
CRM_Contact_BAO_RelationshipType::retrieve($relationship_type_params, $relationship_type);
$clause[$relationship_type['label_a_b']] = $relationship_type_id;
}
$this->_where[$grouping][] = "relationship.relationship_type_id {$op} ('" . implode("', '", $clause) . "')";
$this->_qill[$grouping][] = ts('Relationship Type') . " {$op} " . implode(' ' . ts('or') . ' ', array_keys($clause));
}
示例8: relationship
/**
* where / qill clause for relationship
*
* @return void
* @access public
*/
function relationship(&$values)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
// also get values array for relation_target_name
// for relatinship search we always do wildcard
$targetName = $this->getWhereValues('relation_target_name', $grouping);
$relStatus = $this->getWhereValues('relation_status', $grouping);
$nameClause = null;
if ($targetName) {
$name = trim($targetName[2]);
if (substr($name, 0, 1) == '"' && substr($name, -1, 1) == '"') {
$name = substr($name, 1, -1);
$name = strtolower(CRM_Core_DAO::escapeString($name));
$nameClause = "= '{$name}'";
} else {
$name = strtolower(CRM_Core_DAO::escapeString($name));
$nameClause = "LIKE '%{$name}%'";
}
}
$rel = explode('_', $value);
self::$_relType = $rel[1];
if ($nameClause) {
require_once 'CRM/Contact/BAO/RelationshipType.php';
$params = array('id' => $rel[0]);
$rTypeValues = array();
require_once "CRM/Contact/BAO/RelationshipType.php";
$rType =& CRM_Contact_BAO_RelationshipType::retrieve($params, $rTypeValues);
if (!$rType) {
return;
}
// for relatinship search we always do wildcard
if ($rTypeValues['name_a_b'] == $rTypeValues['name_b_a']) {
self::$_relType = 'reciprocal';
}
$this->_where[$grouping][] = "( contact_b.sort_name {$nameClause} AND contact_b.id != contact_a.id )";
}
require_once 'CRM/Contact/BAO/Relationship.php';
$relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Individual');
$relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Organization');
$relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Household');
$allRelationshipType = array();
$allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
$allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
$this->_qill[$grouping][] = "{$allRelationshipType[$value]} {$name}";
//check for active, inactive and all relation status
$today = date('Ymd');
if ($relStatus[2] == 0) {
$this->_where[$grouping][] = "civicrm_relationship.is_active = 1 AND ( civicrm_relationship.end_date is NULL OR civicrm_relationship.end_date >= {$today} )";
$this->_qill[$grouping][] = ts('Relationship - Active');
} else {
if ($relStatus[2] == 1) {
$this->_where[$grouping][] = "(civicrm_relationship.is_active = 0 OR civicrm_relationship.end_date < {$today})";
$this->_qill[$grouping][] = ts('Relationship - Inactive');
}
}
$this->_where[$grouping][] = 'civicrm_relationship.relationship_type_id = ' . $rel[0];
$this->_tables['civicrm_relationship'] = $this->_whereTables['civicrm_relationship'] = 1;
$this->_useDistinct = true;
}
示例9: relatedMemberships
/**
* Function to create / update / delete membership for related contacts.
*
* This function will create/update/delete membership for related
* contact based on 1) contact have active membership 2) that
* membership is is extedned by the same relationship type to that
* of the existing relationship.
*
* @param $contactId Int contact id
* @param $params array array of values submitted by POST
* @param $ids array array of ids
* @param $action which action called this function
*
* @static
*
*/
static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = true)
{
// Check the end date and set the status of the relationship
// accrodingly.
$status = self::CURRENT;
if (!empty($params['end_date'])) {
$endDate = CRM_Utils_Date::setDateDefaults($params['end_date'], null, 'Ymd');
$today = date('Ymd');
if ($today > $endDate) {
$status = self::PAST;
}
}
if ($action & CRM_Core_Action::ADD && $status & self::PAST) {
// if relationship is PAST and action is ADD, no qustion
// of creating RELATED membership and return back to
// calling method
return;
}
$rel = explode("_", $params['relationship_type_id']);
$relTypeId = $rel[0];
$relDirection = "_{$rel[1]}_{$rel[2]}";
$targetContact = array();
if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
$contact = $contactId;
$targetContact = CRM_Utils_Array::value('contact_check', $params);
} else {
if ($action & CRM_Core_Action::UPDATE) {
$contact = $ids['contact'];
$targetContact = array($ids['contactTarget'] => 1);
}
}
// Build the 'values' array for
// 1. ContactA
// 2. ContactB
// This will allow us to check if either of the contacts in
// relationship have active memberships.
$values = array();
// 1. ContactA
$values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
// 2. ContactB
if (!empty($targetContact)) {
foreach ($targetContact as $cid => $donCare) {
$values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
$relTypeParams = array('id' => $relTypeId);
$relTypeValues = array();
require_once 'CRM/Contact/BAO/RelationshipType.php';
CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
$values[$cid]['relationshipTypeDirection'] = '_a_b';
} else {
$values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
}
}
}
// Now get the active memberships for all the contacts.
// If contact have any valid membership(s), then add it to
// 'values' array.
foreach ($values as $cid => $subValues) {
$memParams = array('contact_id' => $cid);
$memberships = array();
require_once 'CRM/Member/BAO/Membership.php';
CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
if (empty($memberships)) {
continue;
}
$values[$cid]['memberships'] = $memberships;
}
// done with 'values' array.
// Finally add / edit / delete memberships for the related contacts
foreach ($values as $cid => $details) {
if (!array_key_exists('memberships', $details)) {
continue;
}
require_once 'CRM/Member/BAO/MembershipType.php';
foreach ($details['memberships'] as $membershipId => $membershipValues) {
if ($action & CRM_Core_Action::DELETE) {
// delete memberships of the related contacts.
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId);
continue;
}
if ($action & CRM_Core_Action::UPDATE && $status & self::PAST && $membershipValues['owner_membership_id']) {
// If relationship is PAST and action is UPDATE
// then delete the RELATED membership
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']);
//.........这里部分代码省略.........