本文整理汇总了PHP中CRM_Contact_BAO_Contact::find方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact::find方法的具体用法?PHP CRM_Contact_BAO_Contact::find怎么用?PHP CRM_Contact_BAO_Contact::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Contact
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Contact::find方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the page.
*
* This method is called after the page is created.
*/
public function run()
{
// get the emails for this contact
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name'));
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$entityBlock = array('contact_id' => $contactId);
$phones = CRM_Core_BAO_Phone::getValues($entityBlock);
if (!empty($phones)) {
foreach ($phones as $key => &$value) {
$value['location_type'] = $locationTypes[$value['location_type_id']];
$value['phone_type'] = $phoneTypes[$value['phone_type_id']];
}
}
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contactId;
$contact->find(TRUE);
$privacy = array();
foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
if (isset($contact->{$name})) {
$privacy[$name] = $contact->{$name};
}
}
$this->assign('contactId', $contactId);
$this->assign('phone', $phones);
$this->assign('privacy', $privacy);
// check logged in user permission
CRM_Contact_Page_View::checkUserPermission($this, $contactId);
// finally call parent
parent::run();
}
示例2: validateData
/**
* Validate incoming data. This function is intended to ensure that incoming data matches
* It provides a form of pseudo-authentication - by checking the calling fn already knows
* the correct contact id & contribution id (this can be problematic when that has changed in
* the meantime for transactions that are delayed & contacts are merged in-between. e.g
* Paypal allows you to resend Instant Payment Notifications if you, for example, moved site
* and didn't update your IPN URL.
*
* @param array $input interpreted values from the values returned through the IPN
* @param array $ids more interpreted values (ids) from the values returned through the IPN
* @param array $objects an empty array that will be populated with loaded object
* @param boolean $required boolean Return FALSE if the relevant objects don't exist
* @param integer $paymentProcessorID Id of the payment processor ID in use
* @return boolean
*/
function validateData(&$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL)
{
// make sure contact exists and is valid
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $ids['contact'];
if (!$contact->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contact record: {$ids['contact']} in IPN request: " . print_r($input, TRUE));
echo "Failure: Could not find contact record: {$ids['contact']}<p>";
return FALSE;
}
// make sure contribution exists and is valid
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $ids['contribution'];
if (!$contribution->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contribution record: {$contribution->id} in IPN request: " . print_r($input, TRUE));
echo "Failure: Could not find contribution record for {$contribution->id}<p>";
return FALSE;
}
$contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
$objects['contact'] =& $contact;
$objects['contribution'] =& $contribution;
if (!$this->loadObjects($input, $ids, $objects, $required, $paymentProcessorID)) {
return FALSE;
}
return TRUE;
}
示例3: run
/**
* Run the page.
*
* This method is called after the page is created.
*/
public function run()
{
// get the emails for this contact
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
$addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
$address = array();
if ($addressId > 0) {
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name'));
$entityBlock = array('id' => $addressId);
$address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
if (!empty($address)) {
foreach ($address as $key => &$value) {
$value['location_type'] = $locationTypes[$value['location_type_id']];
}
}
}
// we just need current address block
$currentAddressBlock['address'][$locBlockNo] = array_pop($address);
if (!empty($currentAddressBlock['address'][$locBlockNo])) {
// get contact name of shared contact names
$sharedAddresses = array();
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
foreach ($currentAddressBlock['address'] as $key => $addressValue) {
if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
$sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
}
}
$idValue = $currentAddressBlock['address'][$locBlockNo]['id'];
if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) {
$idValue = $currentAddressBlock['address'][$locBlockNo]['master_id'];
}
// add custom data of type address
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $this, $idValue);
// we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
$currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
$this->assign("dnc_viewCustomData", NULL);
$this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
$this->assign('sharedAddresses', $sharedAddresses);
}
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contactId;
$contact->find(TRUE);
$privacy = array();
foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
if (isset($contact->{$name})) {
$privacy[$name] = $contact->{$name};
}
}
$this->assign('contactId', $contactId);
$this->assign('locationIndex', $locBlockNo);
$this->assign('addressId', $addressId);
$this->assign('privacy', $privacy);
// check logged in user permission
CRM_Contact_Page_View::checkUserPermission($this, $contactId);
// finally call parent
parent::run();
}
示例4: validateData
/**
* Validate incoming data. This function is intended to ensure that incoming data matches
* It provides a form of pseudo-authentication - by checking the calling fn already knows
* the correct contact id & contribution id (this can be problematic when that has changed in
* the meantime for transactions that are delayed & contacts are merged in-between. e.g
* Paypal allows you to resend Instant Payment Notifications if you, for example, moved site
* and didn't update your IPN URL.
*
* @param array $input
* Interpreted values from the values returned through the IPN.
* @param array $ids
* More interpreted values (ids) from the values returned through the IPN.
* @param array $objects
* An empty array that will be populated with loaded object.
* @param bool $required
* Boolean Return FALSE if the relevant objects don't exist.
* @param int $paymentProcessorID
* Id of the payment processor ID in use.
*
* @return bool
*/
function validateData(&$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL)
{
// make sure contact exists and is valid
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $ids['contact'];
if (!$contact->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contact record: " . (int) $ids['contact'] . " in IPN request:\n " . print_r($input, TRUE));
echo "Failure: Could not find contact record: " . (int) $ids['contact'] . "<p>";
return FALSE;
}
if (!isset($input['net_amount']) && !empty($input['total_amount'])) {
$input['net_amount'] = (double) $input['total_amount'] - (double) CRM_Utils_Array::value('fee_amount', $input);
}
// make sure contribution exists and is valid
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $ids['contribution'];
if (!$contribution->find(TRUE)) {
CRM_Core_Error::debug_log_message("Could not find contribution record: " . (int) $contribution->id . " in IPN\n request: " . print_r($input, TRUE));
echo "Failure: Could not find contribution record for " . (int) $contribution->id . "<p>";
return FALSE;
}
$contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
$objects['contact'] =& $contact;
$objects['contribution'] =& $contribution;
if (!$this->loadObjects($input, $ids, $objects, $required, $paymentProcessorID)) {
return FALSE;
}
//the process is that the loadObjects is kind of hacked by loading the objects for the original contribution and then somewhat inconsistently using them for the
//current contribution. Here we ensure that the original contribution is available to the complete transaction function
//we don't want to fix this in the payment processor classes because we would have to fix all of them - so better to fix somewhere central
if (isset($objects['contributionRecur'])) {
$objects['first_contribution'] = $objects['contribution'];
}
return TRUE;
}
示例5: getValues
/**
* Fetch the object and store the values in the values array.
*
* @param array $params
* Input parameters to find object.
* @param array $values
* Output values of the object.
*
* @return CRM_Contact_BAO_Contact|null
* The found object or null
*/
public static function getValues(&$params, &$values)
{
$contact = new CRM_Contact_BAO_Contact();
$contact->copyValues($params);
if ($contact->find(TRUE)) {
CRM_Core_DAO::storeValues($contact, $values);
$privacy = array();
foreach (self::$_commPrefs as $name) {
if (isset($contact->{$name})) {
$privacy[$name] = $contact->{$name};
}
}
if (!empty($privacy)) {
$values['privacy'] = $privacy;
}
// communication Prefferance
$preffComm = $comm = array();
$comm = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contact->preferred_communication_method);
foreach ($comm as $value) {
$preffComm[$value] = 1;
}
$temp = array('preferred_communication_method' => $contact->preferred_communication_method);
$names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
CRM_Core_OptionGroup::lookupValues($temp, $names, FALSE);
$values['preferred_communication_method'] = $preffComm;
$values['preferred_communication_method_display'] = CRM_Utils_Array::value('preferred_communication_method_display', $temp);
$preferredMailingFormat = CRM_Core_SelectValues::pmf();
$values['preferred_mail_format'] = $preferredMailingFormat[$contact->preferred_mail_format];
// get preferred languages
if (!empty($contact->preferred_language)) {
$values['preferred_language'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $contact->preferred_language);
}
// Calculating Year difference
if ($contact->birth_date) {
$birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d');
if ($birthDate < date('Ymd')) {
$age = CRM_Utils_Date::calculateAge($birthDate);
$values['age']['y'] = CRM_Utils_Array::value('years', $age);
$values['age']['m'] = CRM_Utils_Array::value('months', $age);
}
list($values['birth_date']) = CRM_Utils_Date::setDateDefaults($contact->birth_date, 'birth');
$values['birth_date_display'] = $contact->birth_date;
}
if ($contact->deceased_date) {
list($values['deceased_date']) = CRM_Utils_Date::setDateDefaults($contact->deceased_date, 'birth');
$values['deceased_date_display'] = $contact->deceased_date;
}
$contact->contact_id = $contact->id;
return $contact;
}
return NULL;
}
示例6: _civicrm_api3_deprecated_participant_check_params
/**
*
* @param array $params
*
* @param bool $checkDuplicate
*
* @return array|bool
* <type>
*/
function _civicrm_api3_deprecated_participant_check_params($params, $checkDuplicate = FALSE)
{
// check if participant id is valid or not
if (!empty($params['id'])) {
$participant = new CRM_Event_BAO_Participant();
$participant->id = $params['id'];
if (!$participant->find(TRUE)) {
return civicrm_api3_create_error(ts('Participant id is not valid'));
}
}
require_once 'CRM/Contact/BAO/Contact.php';
// check if contact id is valid or not
if (!empty($params['contact_id'])) {
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $params['contact_id'];
if (!$contact->find(TRUE)) {
return civicrm_api3_create_error(ts('Contact id is not valid'));
}
}
// check that event id is not an template
if (!empty($params['event_id'])) {
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
if (!empty($isTemplate)) {
return civicrm_api3_create_error(ts('Event templates are not meant to be registered.'));
}
}
$result = array();
if ($checkDuplicate) {
if (CRM_Event_BAO_Participant::checkDuplicate($params, $result)) {
$participantID = array_pop($result);
$error = CRM_Core_Error::createError("Found matching participant record.", CRM_Core_Error::DUPLICATE_PARTICIPANT, 'Fatal', $participantID);
return civicrm_api3_create_error($error->pop(), array('contactID' => $params['contact_id'], 'participantID' => $participantID));
}
}
return TRUE;
}
示例7: updateDisplayNames
/**
* Regenerates display_name for contacts with given prefixes/suffixes.
*
* @param array $ids
* The array with the prefix/suffix id governing which contacts to regenerate.
* @param int $action
* The action describing whether prefix/suffix was UPDATED or DELETED.
*/
public static function updateDisplayNames(&$ids, $action)
{
// get the proper field name (prefix_id or suffix_id) and its value
$fieldName = '';
foreach ($ids as $key => $value) {
switch ($key) {
case 'individualPrefix':
$fieldName = 'prefix_id';
$fieldValue = $value;
break 2;
case 'individualSuffix':
$fieldName = 'suffix_id';
$fieldValue = $value;
break 2;
}
}
if ($fieldName == '') {
return;
}
// query for the affected individuals
$fieldValue = CRM_Utils_Type::escape($fieldValue, 'Integer');
$contact = new CRM_Contact_BAO_Contact();
$contact->{$fieldName} = $fieldValue;
$contact->find();
// iterate through the affected individuals and rebuild their display_names
while ($contact->fetch()) {
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contact->contact_id;
if ($action == CRM_Core_Action::DELETE) {
$contact->{$fieldName} = 'NULL';
$contact->save();
}
$contact->display_name = $contact->displayName();
$contact->save();
}
}
示例8: getEntityData
/**
* Returns an array with data for an entity
*
* If entity is not available then an empty array is returned
*
* @param string $entity
* @return array
*/
public function getEntityData($entity)
{
//only lookup entities by their lower case name. Entity is now case insensetive
if (isset($this->entity_data[strtolower($entity)]) && is_array($this->entity_data[strtolower($entity)])) {
return $this->entity_data[strtolower($entity)];
//just for backwards compatibility also check case sensitive entity
} elseif (isset($this->entity_data[$entity]) && is_array($this->entity_data[$entity])) {
return $this->entity_data[$entity];
} elseif (strtolower($entity) == strtolower('Contact') && $this->getContactId()) {
$contactObject = new CRM_Contact_BAO_Contact();
$contactObject->id = $this->getContactId();
$contactData = array();
if ($contactObject->find(true)) {
CRM_Core_DAO::storeValues($contactObject, $contactData);
}
return $contactData;
}
return array();
}
示例9: rebookRules
/**
* Rule set for the rebooking forms
*/
static function rebookRules($values)
{
$errors = array();
$contactId = trim($values['contactId']);
$contributionIds = $values['contributionIds'];
if (!preg_match('/^\\d+$/', $contactId)) {
// check if is int
$errors['contactId'] = ts('Please enter a CiviCRM ID!', array('domain' => 'de.systopia.donrec'));
return empty($errors) ? TRUE : $errors;
}
// validation for contact
$contact = new CRM_Contact_BAO_Contact();
$contact->id = (int) $contactId;
if (!$contact->find(true)) {
$errors['contactId'] = ts('A contact with CiviCRM ID %1 doesn\'t exist!', array(1 => $contactId, 'domain' => 'de.systopia.donrec'));
return empty($errors) ? TRUE : $errors;
}
// Der Kontakt, auf den umgebucht wird, darf kein Haushalt sein.
$contactType = $contact->getContactType($contactId);
if (!empty($contactType) && $contactType == 'Household') {
$errors['contactId'] = ts('The target contact can not be a household!', array('domain' => 'de.systopia.donrec'));
return empty($errors) ? TRUE : $errors;
}
// Der Kontakt, auf den umgebucht wird, darf nicht im Papierkorb sein.
$contactIsDeleted = $contact->is_deleted;
if ($contactIsDeleted == 1) {
$errors['contactId'] = ts('The target contact can not be in trash!', array('domain' => 'de.systopia.donrec'));
return empty($errors) ? TRUE : $errors;
}
// Check contributions
$completed = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
$arr = explode(",", $contributionIds);
foreach ($arr as $contributionId) {
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->id = $contributionId;
if ($contribution->find(true)) {
// only 'completed' contributions can be rebooked
if ($contribution->contribution_status_id != $completed) {
$errors['contactId'] = ts('The contribution with ID %1 is not completed!', array(1 => $contributionId, 'domain' => 'de.systopia.donrec'));
return empty($errors) ? TRUE : $errors;
}
// receipted contributions can NOT be rebooked
if (CRM_Donrec_Logic_Receipt::isContributionLocked($contributionId)) {
$errors['contactId'] = ts('The contribution with ID %1 cannot be rebooked, because it has a valid contribution receipt.', array(1 => $contributionId, 'domain' => 'de.systopia.donrec'));
return empty($errors) ? TRUE : $errors;
}
}
}
return empty($errors) ? TRUE : $errors;
}
示例10: _getValues
/**
* Given the list of params in the params array, fetch the object
* and store the values in the values array
*
* @param array $params input parameters to find object
* @param array $values output values of the object
*
* @return CRM_Contact_BAO_Contact|null the found object or null
* @access public
* @static
*/
private static function _getValues(&$params, &$values)
{
$contact = new CRM_Contact_BAO_Contact();
$contact->copyValues($params);
if ($contact->find(true)) {
CRM_Core_DAO::storeValues($contact, $values);
$privacy = array();
foreach (self::$_commPrefs as $name) {
if (isset($contact->{$name})) {
$privacy[$name] = $contact->{$name};
}
}
if (!empty($privacy)) {
$values['privacy'] = $privacy;
}
// communication Prefferance
$preffComm = $comm = array();
$comm = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $contact->preferred_communication_method);
foreach ($comm as $value) {
$preffComm[$value] = 1;
}
$temp = array('preferred_communication_method' => $contact->preferred_communication_method);
$names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
require_once 'CRM/Core/OptionGroup.php';
CRM_Core_OptionGroup::lookupValues($temp, $names, false);
$values['preferred_communication_method'] = $preffComm;
$values['preferred_communication_method_display'] = CRM_Utils_Array::value('preferred_communication_method_display', $temp);
CRM_Contact_DAO_Contact::addDisplayEnums($values);
// get preferred languages
if (!empty($contact->preferred_language)) {
$languages =& CRM_Core_PseudoConstant::languages();
$values['preferred_language'] = CRM_Utils_Array::value($contact->preferred_language, $languages);
}
// Calculating Year difference
if ($contact->birth_date) {
$birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d');
if ($birthDate < date('Ymd')) {
$age = CRM_Utils_Date::calculateAge($birthDate);
$values['age']['y'] = CRM_Utils_Array::value('years', $age);
$values['age']['m'] = CRM_Utils_Array::value('months', $age);
}
list($values['birth_date']) = CRM_Utils_Date::setDateDefaults($contact->birth_date, 'birth');
$values['birth_date_display'] = $contact->birth_date;
}
if ($contact->deceased_date) {
list($values['deceased_date']) = CRM_Utils_Date::setDateDefaults($contact->deceased_date, 'birth');
$values['deceased_date_display'] = $contact->deceased_date;
}
$contact->contact_id = $contact->id;
return $contact;
}
return null;
}
示例11: syncCollectCiviCRM
/**
* Collect CiviCRM data into temporary working table.
*/
static function syncCollectCiviCRM($listID)
{
CRM_Mailchimp_Utils::checkDebug('Start-CRM_Mailchimp_Form_Sync syncCollectCiviCRM $listID= ', $listID);
// Nb. these are temporary tables but we don't use TEMPORARY table because they are
// needed over multiple sessions because of queue.
CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS tmp_mailchimp_push_c;");
$dao = CRM_Core_DAO::executeQuery("CREATE TABLE tmp_mailchimp_push_c (\n contact_id INT(10) UNSIGNED NOT NULL,\n email_id INT(10) UNSIGNED NOT NULL,\n email VARCHAR(200),\n first_name VARCHAR(100),\n last_name VARCHAR(100),\n hash CHAR(32),\n groupings VARCHAR(4096),\n PRIMARY KEY (email_id, email, hash)\n );");
// Cheekily access the database directly to obtain a prepared statement.
$db = $dao->getDatabaseConnection();
$insert = $db->prepare('INSERT INTO tmp_mailchimp_push_c VALUES(?, ?, ?, ?, ?, ?, ?)');
//create table for mailchim civicrm syn errors
$dao = CRM_Core_DAO::executeQuery("CREATE TABLE IF NOT EXISTS mailchimp_civicrm_syn_errors (\n id int(11) NOT NULL AUTO_INCREMENT,\n email VARCHAR(200),\n error VARCHAR(200),\n error_count int(10),\n group_id int(20),\n list_id VARCHAR(20),\n PRIMARY KEY (id)\n );");
// We need to know what groupings we have maps to.
// We only care about CiviCRM groups that are mapped to this MC List:
$mapped_groups = CRM_Mailchimp_Utils::getGroupsToSync(array(), $listID);
// First, get all subscribers from the membership group for this list.
// ... Find CiviCRM group id for the membership group.
// ... And while we're at it, build an SQL-safe array of groupIds for groups mapped to groupings.
// (we use that later)
$membership_group_id = FALSE;
$grouping_group_ids = array('normal' => array(), 'smart' => array());
$default_info = array();
foreach ($mapped_groups as $group_id => $details) {
CRM_Contact_BAO_GroupContactCache::loadAll($group_id);
if (!$details['grouping_id']) {
$membership_group_id = $group_id;
} else {
$grouping_group_ids[$details['civigroup_uses_cache'] ? 'smart' : 'normal'][] = (int) $group_id;
$default_info[$details['grouping_id']][$details['group_id']] = FALSE;
}
}
$grouping_group_ids['smart'] = implode(',', $grouping_group_ids['smart']);
$grouping_group_ids['normal'] = implode(',', $grouping_group_ids['normal']);
if (!$membership_group_id) {
throw new Exception("No CiviCRM group is mapped to determine membership of Mailchimp list {$listID}");
}
// ... Load all subscribers in $groupContact object
if (!($groupContact = CRM_Mailchimp_Utils::getGroupContactObject($membership_group_id))) {
CRM_Mailchimp_Utils::checkDebug('get group contact= ', $groupContact);
throw new Exception("No CiviCRM group is mapped to determine membership of Mailchimp list {$listID}. CiviCRM group {$membership_group_id} failed to load");
}
// Now we iterate through the subscribers, collecting data about the other mapped groups
// This is pretty inefficient :-(
while ($groupContact->fetch()) {
// Find the contact, for the name fields
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $groupContact->contact_id;
$contact->is_deleted = 0;
if (!$contact->find(TRUE)) {
continue;
}
// Find their primary (bulk) email
$email = new CRM_Core_BAO_Email();
$email->contact_id = $groupContact->contact_id;
$email->is_primary = TRUE;
if (!$email->find(TRUE)) {
continue;
}
// If no email, it's like they're not there.
if (!$email->email || $email->on_hold || $contact->is_opt_out || $contact->do_not_email) {
//@todo update stats.
continue;
}
// Find out if they're in any groups that we care about.
// Start off as not in the groups...
$info = $default_info;
// We can do this with two queries, one for normal groups, one for smart groups.
// Normal groups.
if ($grouping_group_ids['normal']) {
$groupContact2 = new CRM_Contact_BAO_GroupContact();
$groupContact2->contact_id = $groupContact->contact_id;
$groupContact2->whereAdd("status = 'Added'");
$groupContact2->whereAdd("group_id IN ({$grouping_group_ids['normal']})");
$groupContact2->find();
while ($groupContact2->fetch()) {
// need MC grouping_id and group_id
$details = $mapped_groups[$groupContact2->group_id];
$info[$details['grouping_id']][$details['group_id']] = TRUE;
}
unset($groupContact2);
}
// Smart groups
if ($grouping_group_ids['smart']) {
$groupContactCache = new CRM_Contact_BAO_GroupContactCache();
$groupContactCache->contact_id = $groupContact->contact_id;
$groupContactCache->whereAdd("group_id IN ({$grouping_group_ids['smart']})");
$groupContactCache->find();
while ($groupContactCache->fetch()) {
// need MC grouping_id and group_id
$details = $mapped_groups[$groupContactCache->group_id];
$info[$details['grouping_id']][$details['group_id']] = TRUE;
}
unset($groupContactCache);
}
// OK we should now have all the info we need.
// Serialize the grouping array for SQL storage - this is the fastest way.
$info = serialize($info);
//.........这里部分代码省略.........
示例12: getContactById
/**
* Get a Contact and Email DAO objects for a given contact id.
*/
static function getContactById($contact_id)
{
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contact_id;
if (!$contact->find(TRUE)) {
throw new CRM_CiviMailchimp_Exception("Could not find Contact record with ID {$contact_id}");
}
$emails = new CRM_Core_BAO_Email();
$emails->contact_id = $contact->id;
$emails->find();
while ($emails->fetch()) {
$email = clone $emails;
$contact->email[] = $email;
}
return $contact;
}
示例13: getContactRelationshipType
/**
* Function to get get list of relationship type based on the contact type.
*
* @param int $contactId this is the contact id of the current contact.
* @param string $strContact it's values are 'a or b' if value is 'a' then selected contact is the
* value of contac_id_a for the relationship and if value is 'b'
* then selected contact is the value of contac_id_b for the relationship
* @param string $relationshipId the id of the existing relationship if any
* @param string $contactType contact type
* @param boolean $all if true returns relationship types in both the direction
* @param string $column name/label that going to retrieve from db.
*
*
* @param string $contactSubType includes relationshiptypes between this subtype
*
* @param boolean $onlySubTypeRelationTypes if set only subtype which is passed by $contactSubType
* related relationshiptypes get return
* @access public
* @static
*
* @return array - array reference of all relationship types with context to current contact.
*/
function getContactRelationshipType($contactId = null, $contactSuffix, $relationshipId, $contactType = null, $all = false, $column = 'label', $biDirectional = true, $contactSubType = null, $onlySubTypeRelationTypes = false)
{
$allRelationshipType = array();
$relationshipType = array();
$allRelationshipType = CRM_Core_PseudoConstant::relationshipType($column);
$otherContactType = null;
if ($relationshipId) {
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->id = $relationshipId;
if ($relationship->find(true)) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $relationship->contact_id_a === $contactId ? $relationship->contact_id_b : $relationship->contact_id_a;
if ($contact->find(true)) {
$otherContactType = $contact->contact_type;
//CRM-5125 for contact subtype specific relationshiptypes
if ($contact->contact_sub_type) {
$otherContactSubType = $contact->contact_sub_type;
}
}
}
}
if ($contactId) {
$contact = new CRM_Contact_BAO_Contact();
$contact->id = $contactId;
if ($contact->find(true)) {
$contactType = $contact->contact_type;
if ($contact->contact_sub_type) {
$contactSubType = $contact->contact_sub_type;
}
}
}
foreach ($allRelationshipType as $key => $value) {
// the contact type is required or matches
if ((!$value['contact_type_a'] || $value['contact_type_a'] == $contactType) && (!$value['contact_type_b'] || !$otherContactType || $value['contact_type_b'] == $otherContactType) && ($value['contact_sub_type_a'] == $contactSubType || !$value['contact_sub_type_b'] && !$value['contact_sub_type_a'] && !$onlySubTypeRelationTypes)) {
$relationshipType[$key . '_a_b'] = $value["{$column}_a_b"];
}
if ((!$value['contact_type_b'] || $value['contact_type_b'] == $contactType) && (!$value['contact_type_a'] || !$otherContactType || $value['contact_type_a'] == $otherContactType) && (!$value['contact_sub_type_a'] && !$value['contact_sub_type_b'] && !$onlySubTypeRelationTypes || $value['contact_sub_type_b'] == $contactSubType)) {
$relationshipType[$key . '_b_a'] = $value["{$column}_b_a"];
}
if ($all) {
$relationshipType[$key . '_a_b'] = $value["{$column}_a_b"];
$relationshipType[$key . '_b_a'] = $value["{$column}_b_a"];
}
}
if ($biDirectional) {
// lets clean up the data and eliminate all duplicate values
// (i.e. the relationship is bi-directional)
$relationshipType = array_unique($relationshipType);
}
return $relationshipType;
}