本文整理汇总了PHP中CRM_Contact_BAO_Relationship::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Relationship::add方法的具体用法?PHP CRM_Contact_BAO_Relationship::add怎么用?PHP CRM_Contact_BAO_Relationship::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Relationship::add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess()
{
require_once 'CRM/Contact/Form/Relationship.php';
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$this->set('searchDone', 0);
if (CRM_Utils_Array::value('_qf_AddToOrganization_refresh', $_POST)) {
$searchParams['contact_type'] = array('Organization' => 'Organization');
$searchParams['rel_contact'] = $params['name'];
CRM_Contact_Form_Relationship::search($searchParams);
$this->set('searchDone', 1);
return;
}
$data = array();
//$params['relationship_type_id']='4_a_b';
$data['relationship_type_id'] = $params['relationship_type_id'];
$data['is_active'] = 1;
$invalid = 0;
$valid = 0;
$duplicate = 0;
if (is_array($this->_contactIds)) {
foreach ($this->_contactIds as $value) {
$ids = array();
$ids['contact'] = $value;
//contact b --> organization
// contact a -> individual
$errors = CRM_Contact_BAO_Relationship::checkValidRelationship($params, $ids, $params['contact_check']);
if ($errors) {
$invalid = $invalid + 1;
continue;
}
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($params, CRM_Utils_Array::value('contact', $ids), $params['contact_check'])) {
// step 2
$duplicate++;
continue;
}
CRM_Contact_BAO_Relationship::add($data, $ids, $params['contact_check']);
$valid++;
}
$status = array(ts('Added Contact(s) to Organization'), ts('Total Selected Contact(s): %1', array(1 => $valid + $invalid + $duplicate)));
if ($valid) {
$status[] = ts('New relationship record(s) created: %1.', array(1 => $valid)) . '<br/>';
}
if ($invalid) {
$status[] = ts('Relationship record(s) not created due to invalid target contact type: %1.', array(1 => $invalid)) . '<br/>';
}
if ($duplicate) {
$status[] = ts('Relationship record(s) not created - duplicate of existing relationship: %1.', array(1 => $duplicate)) . '<br/>';
}
CRM_Core_Session::setStatus($status);
}
}
示例2: crm_update_relationship
/**
* Function to update relationship
*
* @param object $relationship A valid Relationship object.
* @param array $params Associative array of property name/value pairs to be updated. See Data Model for available properties.
*
* @return updated relationship object
*
* @access public
*
*/
function crm_update_relationship(&$relationship, $params)
{
$ids = array();
if (!isset($relationship->id) && !isset($relationship->contact_id_a) && !isset($relationship->contact_id_b)) {
return _crm_error("{$relationship} is not valid relationship type object");
}
$conactId = $relationship->contact_id_b;
$params['relationship_type_id'] = $relationship->relationship_type_id . '_a_b';
$ids['contact'] = $relationship->contact_id_a;
$ids['relationship'] = $relationship->id;
$ids['contactTarget'] = $relationship->contact_id_b;
return CRM_Contact_BAO_Relationship::add($params, $ids, $conactId);
}
示例3: handleSharedRelation
/**
* Function to Add/Edit/Delete the relation of individual with shared-household.
*
* @param integer $contactID the input form values
* @param array $params the input form values
*
* @return void
* @access public
* @static
*/
static function handleSharedRelation($contactID, &$params)
{
if (CRM_Utils_Array::value('old_mail_to_household_id', $params) != $params['mail_to_household_id']) {
require_once 'CRM/Contact/BAO/Relationship.php';
$relID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Household Member of', 'id', 'name_a_b');
if (CRM_Utils_Array::value('old_mail_to_household_id', $params)) {
$relationship =& new CRM_Contact_DAO_Relationship();
$relationship->contact_id_b = $params['old_mail_to_household_id'];
$relationship->contact_id_a = $contactID;
$relationship->relationship_type_id = $relID;
if ($relationship->find(true)) {
$relationship->delete();
}
}
if ($params['mail_to_household_id']) {
$ids = array('contact' => $params['mail_to_household_id']);
$relationshipParams = array();
$relationshipParams['relationship_type_id'] = $relID . '_b_a';
$relationshipParams['is_active'] = 1;
$relationship =& new CRM_Contact_DAO_Relationship();
$relationship->contact_id_b = $params['mail_to_household_id'];
$relationship->contact_id_a = $contactID;
$relationship->relationship_type_id = $relID;
// if relationship already not present, add a new one
if (!$relationship->find(true)) {
CRM_Contact_BAO_Relationship::add($relationshipParams, $ids, $contactID);
}
}
}
return;
}
示例4: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return None
*/
public function postProcess()
{
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$this->set('searchDone', 0);
if (CRM_Utils_Array::value('_qf_AddToOrganization_refresh', $_POST)) {
$searchParams['contact_type'] = array('Organization' => 'Organization');
$searchParams['rel_contact'] = $params['name'];
CRM_Contact_Form_Task_AddToHousehold::search($this, $searchParams);
$this->set('searchDone', 1);
return;
}
$data = array();
$data['relationship_type_id'] = $params['relationship_type_id'];
$data['is_active'] = 1;
$invalid = 0;
$valid = 0;
$duplicate = 0;
if (is_array($this->_contactIds)) {
foreach ($this->_contactIds as $value) {
$ids = array();
$ids['contact'] = $value;
$errors = CRM_Contact_BAO_Relationship::checkValidRelationship($params, $ids, $params['contact_check']);
if ($errors) {
$invalid++;
continue;
}
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($params, CRM_Utils_Array::value('contact', $ids), $params['contact_check'])) {
$duplicate++;
continue;
}
CRM_Contact_BAO_Relationship::add($data, $ids, $params['contact_check']);
$valid++;
}
$org = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['contact_check'], 'display_name');
list($rtype, $a_b) = explode('_', $data['relationship_type_id'], 2);
$relationship = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $rtype, "label_{$a_b}");
$status = array(ts('%count %2 %3 relationship created', array('count' => $valid, 'plural' => '%count %2 %3 relationships created', 2 => $relationship, 3 => $org)));
if ($duplicate) {
$status[] = ts('%count was skipped because the contact is already %2 %3', array('count' => $duplicate, 'plural' => '%count were skipped because the contacts are already %2 %3', 2 => $relationship, 3 => $org));
}
if ($invalid) {
$status[] = ts('%count relationship was not created because the contact is not of the right type for this relationship', array('count' => $invalid, 'plural' => '%count relationships were not created because the contact is not of the right type for this relationship'));
}
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts('Relationship Created', array('count' => $valid, 'plural' => 'Relationships Created')), 'success', array('expires' => 0));
}
}
示例5: crm_update_relationship
/**
* Function to update relationship
*
* @param object $relationship A valid Relationship object.
* @param array $params Associative array of property name/value pairs to be updated. See Data Model for available properties.
*
* @return updated relationship object
*
* @access public
*
*/
function crm_update_relationship(&$relationship, $params)
{
$ids = array();
if (!isset($relationship->id) && !isset($relationship->contact_id_a) && !isset($relationship->contact_id_b)) {
return _crm_error('$relationship is not valid relationship type object');
}
$conactId = $relationship->contact_id_b;
$params['relationship_type_id'] = $relationship->relationship_type_id . '_a_b';
$ids['contact'] = $relationship->contact_id_a;
$ids['relationship'] = $relationship->id;
$ids['contactTarget'] = $relationship->contact_id_b;
$relationship = CRM_Contact_BAO_Relationship::add($params, $ids, $conactId);
if (CRM_Core_Permission::access('CiviMember')) {
$params['contact_check'] = array($relationship->contact_id_b => 1);
CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::ADD);
}
return $relationship;
}
示例6: create
/**
* takes an associative array and creates a relationship object
*
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Contact_BAO_Relationship object
* @access public
* @static
*/
function create(&$params, &$ids)
{
$valid = $invalid = $duplicate = $saved = 0;
$relationshipId = CRM_Utils_Array::value('relationship', $ids);
if (!$relationshipId) {
// creating a new relationship
$dataExists = CRM_Contact_BAO_Relationship::dataExists($params);
if (!$dataExists) {
return null;
}
foreach ($params['contact_check'] as $key => $value) {
$errors = '';
// check if the realtionship is valid between contacts.
// step 1: check if the relationship is valid if not valid skip and keep the count
// step 2: check the if two contacts already have a relationship if yes skip and keep the count
// step 3: if valid relationship then add the relation and keep the count
$errors = CRM_Contact_BAO_Relationship::checkValidRelationship($params, $ids, $key);
// step 1
if ($errors) {
$invalid++;
continue;
}
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($params, CRM_Utils_Array::value('contact', $ids), $key)) {
// step 2
$duplicate++;
continue;
}
$relationship = CRM_Contact_BAO_Relationship::add($params, $ids, $key);
$valid++;
}
//return array( $valid, $invalid, $duplicate, $saved );
} else {
//editing the relationship
// check for duplicate relationship
if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($params, CRM_Utils_Array::value('contact', $ids), $ids['contactTarget'], $relationshipId)) {
$duplicate++;
return array($valid, $invalid, $duplicate);
}
// editing an existing relationship
CRM_Contact_BAO_Relationship::add($params, $ids, $ids['contactTarget']);
$saved++;
//return array( $valid, $invalid, $duplicate, $saved );
}
return array($valid, $invalid, $duplicate, $saved);
}