本文整理汇总了PHP中CRM_Contact_BAO_Relationship::disableEnableRelationship方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Relationship::disableEnableRelationship方法的具体用法?PHP CRM_Contact_BAO_Relationship::disableEnableRelationship怎么用?PHP CRM_Contact_BAO_Relationship::disableEnableRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Relationship::disableEnableRelationship方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteContact
/**
* Delete a contact and all its associated records.
*
* @param int $id
* Id of the contact to delete.
* @param bool $restore
* Whether to actually restore, not delete.
* @param bool $skipUndelete
* Whether to force contact delete or not.
*
* @return bool
* Was contact deleted?
*/
public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE)
{
if (!$id) {
return FALSE;
}
// If trash is disabled in system settings then we always skip
if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL, 1)) {
$skipUndelete = TRUE;
}
// make sure we have edit permission for this contact
// before we delete
if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) {
return FALSE;
}
// CRM-12929
// Restrict contact to be delete if contact has financial trxns
$error = NULL;
if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($id), $error)) {
return FALSE;
}
// make sure this contact_id does not have any membership types
$membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
if ($membershipTypeID) {
return FALSE;
}
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $id;
if (!$contact->find(TRUE)) {
return FALSE;
}
$contactType = $contact->contact_type;
// currently we only clear employer cache.
// we are now deleting inherited membership if any.
if ($contact->contact_type == 'Organization') {
$action = $restore ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
$relationshipDtls = CRM_Contact_BAO_Relationship::getRelationship($id);
if (!empty($relationshipDtls)) {
foreach ($relationshipDtls as $rId => $details) {
CRM_Contact_BAO_Relationship::disableEnableRelationship($rId, $action);
}
}
CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
}
if ($restore) {
return self::contactTrashRestore($contact, TRUE);
}
// start a new transaction
$transaction = new CRM_Core_Transaction();
if ($skipUndelete) {
CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray);
//delete billing address if exists.
CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id);
// delete the log entries since we dont have triggers enabled as yet
$logDAO = new CRM_Core_DAO_Log();
$logDAO->entity_table = 'civicrm_contact';
$logDAO->entity_id = $id;
$logDAO->delete();
// delete contact participants CRM-12155
CRM_Event_BAO_Participant::deleteContactParticipant($id);
// delete contact contributions CRM-12155
CRM_Contribute_BAO_Contribution::deleteContactContribution($id);
// do activity cleanup, CRM-5604
CRM_Activity_BAO_Activity::cleanupActivity($id);
// delete all notes related to contact
CRM_Core_BAO_Note::cleanContactNotes($id);
// delete cases related to contact
$contactCases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($id);
if (!empty($contactCases)) {
foreach ($contactCases as $caseId) {
//check if case is associate with other contact or not.
$caseContactId = CRM_Case_BAO_Case::getCaseClients($caseId);
if (count($caseContactId) <= 1) {
CRM_Case_BAO_Case::deleteCase($caseId);
}
}
}
$contact->delete();
} else {
self::contactTrashRestore($contact);
}
//delete the contact id from recently view
CRM_Utils_Recent::delContact($id);
// Update the group contact cache
if ($restore) {
CRM_Contact_BAO_GroupContactCache::remove();
} else {
CRM_Contact_BAO_GroupContactCache::removeContact($id);
//.........这里部分代码省略.........
示例2: run
/**
* This function is the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* return null
* @access public
*/
function run()
{
$this->preProcess();
$this->setContext();
$this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this);
if ($this->_action & CRM_Core_Action::VIEW) {
$this->view();
} else {
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
$this->edit();
} else {
if ($this->_action & CRM_Core_Action::DISABLE) {
CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_id, CRM_Core_Action::DISABLE);
CRM_Contact_BAO_Relationship::setIsActive($this->_id, 0);
$session =& CRM_Core_Session::singleton();
CRM_Utils_System::redirect($session->popUserContext());
} else {
if ($this->_action & CRM_Core_Action::ENABLE) {
CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_id, CRM_Core_Action::ENABLE);
CRM_Contact_BAO_Relationship::setIsActive($this->_id, 1);
$session =& CRM_Core_Session::singleton();
CRM_Utils_System::redirect($session->popUserContext());
}
}
}
}
// if this is called from case view, suppress browse relationships form
if (!$this->_caseId) {
$this->browse();
}
return parent::run();
}
示例3: civicrm_api3_relationship_setvalue
/**
* Hack to ensure inherited membership got created/deleted on
* relationship add/delete respectively.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
*/
function civicrm_api3_relationship_setvalue($params)
{
require_once 'api/v3/Generic/Setvalue.php';
$result = civicrm_api3_generic_setValue(array("entity" => 'Relationship', 'params' => $params));
if (empty($result['is_error']) && CRM_Utils_String::munge($params['field']) == 'is_active') {
$action = CRM_Core_Action::DISABLE;
if ($params['value'] == TRUE) {
$action = CRM_Core_Action::ENABLE;
}
CRM_Contact_BAO_Relationship::disableEnableRelationship($params['id'], $action);
}
return $result;
}
示例4: postProcess
//.........这里部分代码省略.........
$params['note'] = 'null';
}
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], NULL, TRUE);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], NULL, TRUE);
//special case to handle if all checkboxes are unchecked
$customFields = CRM_Core_BAO_CustomField::getFields('Relationship', FALSE, FALSE, $relationshipTypeId);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
// if this is called from case view,
//create an activity for case role removal.CRM-4480
if ($this->_caseId) {
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
}
$status = '';
if ($valid) {
CRM_Core_Session::setStatus(ts('New relationship created.', array('count' => $valid, 'plural' => '%count new relationships created.')), ts('Saved'), 'success');
}
if ($invalid) {
CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records were not created due to invalid target contact types.')), ts('%count invalid relationship record', array('count' => $invalid, 'plural' => '%count invalid relationship records')));
}
if ($duplicate) {
CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array('count' => $duplicate, 'plural' => '%count relationships were not created because they already exist.')), ts('%count duplicate relationship', array('count' => $duplicate, 'plural' => '%count duplicate relationships')));
}
if ($saved) {
CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success');
}
if (!empty($relationshipIds)) {
$note = new CRM_Core_DAO_Note();
$note->entity_id = $relationshipIds[0];
$note->entity_table = 'civicrm_relationship';
$noteIds = array();
if ($note->find(TRUE)) {
$id = $note->id;
$noteIds['id'] = $id;
}
$noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId);
CRM_Core_BAO_Note::add($noteParams, $noteIds);
$params['relationship_ids'] = $relationshipIds;
}
// Membership for related contacts CRM-1657
if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
if ($this->_action & CRM_Core_Action::ADD) {
CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
//fixes for CRM-7985
//only if the relationship has been toggled to enable /disable
if (CRM_Utils_Array::value('is_active', $params) != $this->_enabled) {
$active = CRM_Utils_Array::value('is_active', $params) ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_relationshipId, $active);
}
}
}
//handle current employee/employer relationship, CRM-3532
if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') {
$orgId = NULL;
if (CRM_Utils_Array::value('employee_of', $params)) {
$orgId = $params['employee_of'];
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) {
if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) {
$orgId = CRM_Utils_Array::value('contactTarget', $ids);
}
} elseif (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) {
//clear current employer.
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId);
}
}
//set current employer
if ($orgId) {
$currentEmpParams[$this->_contactId] = $orgId;
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
} elseif ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') {
$individualIds = array();
if (CRM_Utils_Array::value('employer_of', $params)) {
$individualIds = array_keys($params['employer_of']);
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Utils_Array::value('is_current_employer', $params)) {
if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) {
$individualIds[] = CRM_Utils_Array::value('contactTarget', $ids);
}
} elseif (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) {
// clear current employee
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']);
}
}
//set current employee
if (!empty($individualIds)) {
//build the employee params.
foreach ($individualIds as $key => $Id) {
$currentEmpParams[$Id] = $this->_contactId;
}
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
}
}
if ($quickSave) {
$session = CRM_Core_Session::singleton();
CRM_Utils_System::redirect($session->popUserContext());
}
}
示例5: postProcess
/**
* This function is called when the form is submitted
*
* @access public
*
* @return void
*/
public function postProcess()
{
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
// action is taken depending upon the mode
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
return;
}
$ids = array('contact' => $this->_contactId);
$relationshipTypeId = str_replace(array('_', 'a', 'b'), '', $params['relationship_type_id']);
// CRM-14612 - Don't use adv-checkbox as it interferes with the form js
$params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $params, 0);
$params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $params, 0);
// Update mode (always single)
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['relationship'] = $this->_relationshipId;
$relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId);
$ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
if ($this->_isCurrentEmployer) {
// if relationship type changes, relationship is disabled, or "current employer" is unchecked,
// clear the current employer. CRM-3235.
$relChanged = $relationshipTypeId != $this->_values['relationship_type_id'];
if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['contact_id_a']);
// Refresh contact summary if in ajax mode
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
}
}
} else {
// Fill up this weird param with contact ids like the weird relationship bao expects
$params['contact_check'] = array_fill_keys(explode(',', $params['related_contact_id']), 1);
if (!$this->_rtype) {
list(, $this->_rtype) = explode('_', $params['relationship_type_id'], 2);
}
}
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], NULL, TRUE);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], NULL, TRUE);
// Process custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Relationship', FALSE, FALSE, $relationshipTypeId);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
// Save relationships
list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
// if this is called from case view,
//create an activity for case role removal.CRM-4480
if ($this->_caseId) {
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
}
if ($valid) {
CRM_Core_Session::setStatus(ts('Relationship created.', array('count' => $valid, 'plural' => '%count relationships created.')), ts('Saved'), 'success');
}
if ($invalid) {
CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid contact type.', array('count' => $invalid, 'plural' => '%count relationship records were not created due to invalid contact types.')), ts('%count invalid relationship record', array('count' => $invalid, 'plural' => '%count invalid relationship records')));
}
if ($duplicate) {
CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array('count' => $duplicate, 'plural' => '%count relationships were not created because they already exist.')), ts('%count duplicate relationship', array('count' => $duplicate, 'plural' => '%count duplicate relationships')));
}
if ($saved) {
CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success');
}
// Save notes
if ($this->_action & CRM_Core_Action::UPDATE || $params['note']) {
foreach ($relationshipIds as $id) {
$noteParams = array('entity_id' => $id, 'entity_table' => 'civicrm_relationship');
$existing = civicrm_api3('note', 'get', $noteParams);
if (!empty($existing['id'])) {
$noteParams['id'] = $existing['id'];
}
$noteParams['note'] = $params['note'];
$noteParams['contact_id'] = $this->_contactId;
if (!empty($existing['id']) || $params['note']) {
$action = $params['note'] ? 'create' : 'delete';
civicrm_api3('note', $action, $noteParams);
}
}
}
// Membership for related contacts CRM-1657
if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
$params['relationship_ids'] = $relationshipIds;
if ($this->_action & CRM_Core_Action::ADD) {
CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
} elseif ($this->_action & CRM_Core_Action::UPDATE) {
//fixes for CRM-7985
//only if the relationship has been toggled to enable /disable
if (CRM_Utils_Array::value('is_active', $params) != $this->_enabled) {
$active = !empty($params['is_active']) ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
CRM_Contact_BAO_Relationship::disableEnableRelationship($this->_relationshipId, $active);
}
}
// Refresh contact tabs with related data
$this->ajaxResponse['updateTabs'] = array('#tab_member' => CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId));
}
// Set current employee/employer relationship, CRM-3532
//.........这里部分代码省略.........