本文整理汇总了PHP中CRM_Contact_DAO_Relationship::free方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_DAO_Relationship::free方法的具体用法?PHP CRM_Contact_DAO_Relationship::free怎么用?PHP CRM_Contact_DAO_Relationship::free使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_DAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_DAO_Relationship::free方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCaseRelationships
/**
* Function to add/copy relationships, when new client is added for a case
*
* @param int $caseId case id
* @param int $contactId contact id / new client id
*
* @return void
*/
static function addCaseRelationships($caseId, $contactId)
{
// get the case role / relationships for the case
$caseRelationships = new CRM_Contact_DAO_Relationship();
$caseRelationships->case_id = $caseId;
$caseRelationships->find();
$relationshipTypes = array();
// make sure we don't add duplicate relationships of same relationship type.
while ($caseRelationships->fetch() && !in_array($caseRelationships->relationship_type_id, $relationshipTypes)) {
$values = array();
CRM_Core_DAO::storeValues($caseRelationships, $values);
// add relationship for new client.
$newRelationship = new CRM_Contact_DAO_Relationship();
$newRelationship->copyValues($values);
$newRelationship->id = NULL;
$newRelationship->case_id = $caseId;
$newRelationship->contact_id_a = $contactId;
$newRelationship->end_date = CRM_Utils_Date::isoToMysql($caseRelationships->end_date);
$newRelationship->start_date = CRM_Utils_Date::isoToMysql($caseRelationships->start_date);
// another check to avoid duplicate relationship, in cases where client is removed and re-added again.
if (!$newRelationship->find(TRUE)) {
$newRelationship->save();
}
$newRelationship->free();
// store relationship type of newly created relationship
$relationshipTypes[] = $caseRelationships->relationship_type_id;
}
}
示例2: relationship
public static function relationship()
{
$relType = CRM_Utils_Request::retrieve('rel_type', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
$relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
$relationshipID = CRM_Utils_Request::retrieve('rel_id', 'Positive', CRM_Core_DAO::$_nullObject);
// this used only to determine add or update mode
$caseID = CRM_Utils_Request::retrieve('case_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
// check if there are multiple clients for this case, if so then we need create
// relationship and also activities for each contacts
// get case client list
$clientList = CRM_Case_BAO_Case::getCaseClients($caseID);
$ret = array('is_error' => 0);
foreach ($clientList as $sourceContactID) {
$relationParams = array('relationship_type_id' => $relType . '_a_b', 'contact_check' => array($relContactID => 1), 'is_active' => 1, 'case_id' => $caseID, 'start_date' => date("Ymd"));
$relationIds = array('contact' => $sourceContactID);
// check if we are editing/updating existing relationship
if ($relationshipID && $relationshipID != 'null') {
// here we need to retrieve appropriate relationshipID based on client id and relationship type id
$caseRelationships = new CRM_Contact_DAO_Relationship();
$caseRelationships->case_id = $caseID;
$caseRelationships->relationship_type_id = $relType;
$caseRelationships->contact_id_a = $sourceContactID;
$caseRelationships->find();
while ($caseRelationships->fetch()) {
$relationIds['relationship'] = $caseRelationships->id;
$relationIds['contactTarget'] = $relContactID;
}
$caseRelationships->free();
}
// create new or update existing relationship
$return = CRM_Contact_BAO_Relationship::legacyCreateMultiple($relationParams, $relationIds);
if (!empty($return[4][0])) {
$relationshipID = $return[4][0];
//create an activity for case role assignment.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
} else {
$ret = array('is_error' => 1, 'error_message' => ts('The relationship type definition for the case role is not valid for the client and / or staff contact types. You can review and edit relationship types at <a href="%1">Administer >> Option Lists >> Relationship Types</a>.', array(1 => CRM_Utils_System::url('civicrm/admin/reltype', 'reset=1'))));
}
}
CRM_Utils_JSON::output($ret);
}
示例3: getRelationship
//.........这里部分代码省略.........
if ($status != self::INACTIVE) {
if ($links) {
$mask = array_sum(array_keys($links));
if ($mask & CRM_Core_Action::DISABLE) {
$mask -= CRM_Core_Action::DISABLE;
}
if ($mask & CRM_Core_Action::ENABLE) {
$mask -= CRM_Core_Action::ENABLE;
}
if ($status == self::CURRENT) {
$mask |= CRM_Core_Action::DISABLE;
} elseif ($status == self::DISABLED) {
$mask |= CRM_Core_Action::ENABLE;
}
$mask = $mask & $permissionMask;
}
}
while ($relationship->fetch()) {
$rid = $relationship->civicrm_relationship_id;
$cid = $relationship->civicrm_contact_id;
if ($permissionedContact && !CRM_Contact_BAO_Contact_Permission::allow($cid)) {
continue;
}
$values[$rid]['id'] = $rid;
$values[$rid]['cid'] = $cid;
$values[$rid]['contact_id_a'] = $relationship->contact_id_a;
$values[$rid]['contact_id_b'] = $relationship->contact_id_b;
$values[$rid]['contact_type'] = $relationship->contact_type;
$values[$rid]['relationship_type_id'] = $relationship->civicrm_relationship_type_id;
$values[$rid]['relation'] = $relationship->relation;
$values[$rid]['name'] = $relationship->sort_name;
$values[$rid]['display_name'] = $relationship->display_name;
$values[$rid]['job_title'] = $relationship->job_title;
$values[$rid]['email'] = $relationship->email;
$values[$rid]['phone'] = $relationship->phone;
$values[$rid]['employer_id'] = $relationship->employer_id;
$values[$rid]['organization_name'] = $relationship->organization_name;
$values[$rid]['country'] = $relationship->country;
$values[$rid]['city'] = $relationship->city;
$values[$rid]['state'] = $relationship->state;
$values[$rid]['start_date'] = $relationship->start_date;
$values[$rid]['end_date'] = $relationship->end_date;
$values[$rid]['description'] = $relationship->description;
$values[$rid]['is_active'] = $relationship->is_active;
$values[$rid]['is_permission_a_b'] = $relationship->is_permission_a_b;
$values[$rid]['is_permission_b_a'] = $relationship->is_permission_b_a;
$values[$rid]['case_id'] = $relationship->case_id;
if ($status) {
$values[$rid]['status'] = $status;
}
$values[$rid]['civicrm_relationship_type_id'] = $relationship->civicrm_relationship_type_id;
if ($relationship->contact_id_a == $contactId) {
$values[$rid]['rtype'] = 'a_b';
} else {
$values[$rid]['rtype'] = 'b_a';
}
if ($links) {
$replace = array('id' => $rid, 'rtype' => $values[$rid]['rtype'], 'cid' => $contactId, 'cbid' => $values[$rid]['cid'], 'caseid' => $values[$rid]['case_id'], 'clientid' => $contactId);
if ($status == self::INACTIVE) {
// setting links for inactive relationships
$mask = array_sum(array_keys($links));
if (!$values[$rid]['is_active']) {
$mask -= CRM_Core_Action::DISABLE;
} else {
$mask -= CRM_Core_Action::ENABLE;
$mask -= CRM_Core_Action::DISABLE;
}
$mask = $mask & $permissionMask;
}
// Give access to manage case link by copying to MAX_ACTION index temporarily, depending on case permission of user.
if ($values[$rid]['case_id']) {
// Borrowed logic from CRM_Case_Page_Tab
$hasCaseAccess = FALSE;
if (CRM_Core_Permission::check('access all cases and activities')) {
$hasCaseAccess = TRUE;
} else {
$userCases = CRM_Case_BAO_Case::getCases(FALSE);
if (array_key_exists($values[$rid]['case_id'], $userCases)) {
$hasCaseAccess = TRUE;
}
}
if ($hasCaseAccess) {
// give access by copying to MAX_ACTION temporarily, otherwise leave at NONE which won't display
$links[CRM_Core_Action::MAX_ACTION] = $links[CRM_Core_Action::NONE];
$links[CRM_Core_Action::MAX_ACTION]['name'] = ts('Manage Case #%1', array(1 => $values[$rid]['case_id']));
$links[CRM_Core_Action::MAX_ACTION]['class'] = 'no-popup';
// Also make sure we have the right client cid since can get here from multiple relationship tabs.
if ($values[$rid]['rtype'] == 'b_a') {
$replace['clientid'] = $values[$rid]['cid'];
}
}
}
$values[$rid]['action'] = CRM_Core_Action::formLink($links, $mask, $replace, ts('more'), FALSE, 'relationship.selector.row', 'Relationship', $rid);
unset($links[CRM_Core_Action::MAX_ACTION]);
}
}
$relationship->free();
return $values;
}
}
示例4: clearCurrentEmployer
/**
* Clear cached current employer name.
*
* @param int $contactId
* Contact id ( mostly individual contact id).
* @param int $employerId
* Contact id ( mostly organization contact id).
*/
public static function clearCurrentEmployer($contactId, $employerId = NULL)
{
$query = "UPDATE civicrm_contact\nSET organization_name=NULL, employer_id = NULL\nWHERE id={$contactId}; ";
$dao = CRM_Core_DAO::executeQuery($query);
// need to handle related meberships. CRM-3792
if ($employerId) {
//1. disable corresponding relationship.
//2. delete related membership.
//get the relationship type id of "Employee of"
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
if (!$relTypeId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Employee of'"));
}
$relMembershipParams['relationship_type_id'] = $relTypeId . '_a_b';
$relMembershipParams['contact_check'][$employerId] = 1;
//get relationship id.
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($relMembershipParams, $contactId, $employerId)) {
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->contact_id_a = $contactId;
$relationship->contact_id_b = $employerId;
$relationship->relationship_type_id = $relTypeId;
if ($relationship->find(TRUE)) {
CRM_Contact_BAO_Relationship::setIsActive($relationship->id, FALSE);
CRM_Contact_BAO_Relationship::relatedMemberships($contactId, $relMembershipParams, $ids = array(), CRM_Core_Action::DELETE);
}
$relationship->free();
}
}
}
示例5: relationship
static function relationship()
{
$relType = CRM_Utils_Array::value('rel_type', $_REQUEST);
$relContactID = CRM_Utils_Array::value('rel_contact', $_REQUEST);
$sourceContactID = CRM_Utils_Array::value('contact_id', $_REQUEST);
// we no longer need this.
$relationshipID = CRM_Utils_Array::value('rel_id', $_REQUEST);
// this used only to determine add or update mode
$caseID = CRM_Utils_Array::value('case_id', $_REQUEST);
// check if there are multiple clients for this case, if so then we need create
// relationship and also activities for each contacts
// get case client list
$clientList = CRM_Case_BAO_Case::getCaseClients($caseID);
foreach ($clientList as $sourceContactID) {
$relationParams = array('relationship_type_id' => $relType . '_a_b', 'contact_check' => array($relContactID => 1), 'is_active' => 1, 'case_id' => $caseID, 'start_date' => date("Ymd"));
$relationIds = array('contact' => $sourceContactID);
// check if we are editing/updating existing relationship
if ($relationshipID && $relationshipID != 'null') {
// here we need to retrieve appropriate relationshipID based on client id and relationship type id
$caseRelationships = new CRM_Contact_DAO_Relationship();
$caseRelationships->case_id = $caseID;
$caseRelationships->relationship_type_id = $relType;
$caseRelationships->contact_id_a = $sourceContactID;
$caseRelationships->find();
while ($caseRelationships->fetch()) {
$relationIds['relationship'] = $caseRelationships->id;
$relationIds['contactTarget'] = $relContactID;
}
$caseRelationships->free();
}
// create new or update existing relationship
$return = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds);
$status = 'process-relationship-fail';
if (CRM_Utils_Array::value(0, $return[4])) {
$relationshipID = $return[4][0];
$status = 'process-relationship-success';
//create an activity for case role assignment.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
}
}
$relation['status'] = $status;
echo json_encode($relation);
CRM_Utils_System::civiExit();
}
示例6: mergeCases
/**
* Function perform two task.
* 1. Merge two duplicate contacts cases - follow CRM-5758 rules.
* 2. Merge two cases of same contact - follow CRM-5598 rules.
*
* @param int $mainContactId contact id of main contact record.
* @param int $mainCaseId case id of main case record.
* @param int $otherContactId contact id of record which is going to merge.
* @param int $otherCaseId case id of record which is going to merge.
*
* @return void.
* @static
*/
function mergeCases($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE)
{
$moveToTrash = TRUE;
$duplicateContacts = FALSE;
if ($mainContactId && $otherContactId && $mainContactId != $otherContactId) {
$duplicateContacts = TRUE;
}
$duplicateCases = FALSE;
if ($mainCaseId && $otherCaseId && $mainCaseId != $otherCaseId) {
$duplicateCases = TRUE;
}
$mainCaseIds = array();
if (!$duplicateContacts && !$duplicateCases) {
return $mainCaseIds;
}
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
$activityStatuses = CRM_Core_PseudoConstant::activityStatus('name');
$processCaseIds = array($otherCaseId);
if ($duplicateContacts && !$duplicateCases) {
if ($changeClient) {
$processCaseIds = array($mainCaseId);
} else {
//get all case ids for other contact.
$processCaseIds = self::retrieveCaseIdsByContactId($otherContactId, TRUE);
}
if (!is_array($processCaseIds)) {
return;
}
}
$session = CRM_Core_Session::singleton();
$currentUserId = $session->get('userID');
// copy all cases and connect to main contact id.
foreach ($processCaseIds as $otherCaseId) {
if ($duplicateContacts) {
$mainCase = CRM_Core_DAO::copyGeneric('CRM_Case_DAO_Case', array('id' => $otherCaseId));
$mainCaseId = $mainCase->id;
if (!$mainCaseId) {
continue;
}
$mainCase->free();
$mainCaseIds[] = $mainCaseId;
//insert record for case contact.
$otherCaseContact = new CRM_Case_DAO_CaseContact();
$otherCaseContact->case_id = $otherCaseId;
$otherCaseContact->find();
while ($otherCaseContact->fetch()) {
$mainCaseContact = new CRM_Case_DAO_CaseContact();
$mainCaseContact->case_id = $mainCaseId;
$mainCaseContact->contact_id = $otherCaseContact->contact_id;
if ($mainCaseContact->contact_id == $otherContactId) {
$mainCaseContact->contact_id = $mainContactId;
}
//avoid duplicate object.
if (!$mainCaseContact->find(TRUE)) {
$mainCaseContact->save();
}
$mainCaseContact->free();
}
$otherCaseContact->free();
} elseif (!$otherContactId) {
$otherContactId = $mainContactId;
}
if (!$mainCaseId || !$otherCaseId || !$mainContactId || !$otherContactId) {
continue;
}
// get all activities for other case.
$otherCaseActivities = array();
CRM_Core_DAO::commonRetrieveAll('CRM_Case_DAO_CaseActivity', 'case_id', $otherCaseId, $otherCaseActivities);
//for duplicate cases do not process singleton activities.
$otherActivityIds = $singletonActivityIds = array();
foreach ($otherCaseActivities as $caseActivityId => $otherIds) {
$otherActId = CRM_Utils_Array::value('activity_id', $otherIds);
if (!$otherActId || in_array($otherActId, $otherActivityIds)) {
continue;
}
$otherActivityIds[] = $otherActId;
}
if ($duplicateCases) {
if ($openCaseType = array_search('Open Case', $activityTypes)) {
$sql = "\nSELECT id\n FROM civicrm_activity \n WHERE activity_type_id = {$openCaseType} \n AND id IN ( " . implode(',', array_values($otherActivityIds)) . ');';
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$singletonActivityIds[] = $dao->id;
}
$dao->free();
}
}
//.........这里部分代码省略.........