本文整理汇总了PHP中CRM_Utils_array::value方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_array::value方法的具体用法?PHP CRM_Utils_array::value怎么用?PHP CRM_Utils_array::value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_array
的用法示例。
在下文中一共展示了CRM_Utils_array::value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_domain_get
/**
* Get CiviCRM domain details
* {@getfields domain_create}
* @example DomainGet.php
*/
function civicrm_api3_domain_get($params)
{
$params['version'] = CRM_Utils_array::value('domain_version', $params);
unset($params['version']);
$bao = new CRM_Core_BAO_Domain();
if (CRM_Utils_Array::value('current_domain', $params)) {
$domainBAO = CRM_Core_Config::domainID();
$params['id'] = $domainBAO;
}
_civicrm_api3_dao_set_filter($bao, $params, true, 'domain');
$domains = _civicrm_api3_dao_to_array($bao, $params, true, 'domain');
foreach ($domains as $domain) {
$values = array();
$locparams = array('entity_id' => $domain['id'], 'entity_table' => 'civicrm_domain');
require_once 'CRM/Core/BAO/Location.php';
$values['location'] = CRM_Core_BAO_Location::getValues($locparams, TRUE);
$address_array = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2');
require_once 'CRM/Core/OptionGroup.php';
if (!empty($values['location']['email'])) {
$domain['domain_email'] = CRM_Utils_Array::value('email', $values['location']['email'][1]);
}
if (!empty($values['location']['phone'])) {
$domain['domain_phone'] = array('phone_type' => CRM_Core_OptionGroup::getLabel('phone_type', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])), 'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1]));
}
if (!empty($values['location']['address'])) {
foreach ($address_array as $value) {
$domain['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]);
}
}
list($domain['from_name'], $domain['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
$domains[$domain['id']] = array_merge($domains[$domain['id']], $domain);
}
return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao);
}
示例2: statistics
/**
* @param $rows
*
* @return array
*/
public function statistics(&$rows)
{
$statistics = parent::statistics($rows);
$isStatusFilter = FALSE;
$relStatus = NULL;
if (CRM_Utils_Array::value('is_active_value', $this->_params) == '1') {
$relStatus = 'Is equal to Active';
} elseif (CRM_Utils_Array::value('is_active_value', $this->_params) == '0') {
$relStatus = 'Is equal to Inactive';
}
if (!empty($statistics['filters'])) {
foreach ($statistics['filters'] as $id => $value) {
//for displaying relationship type filter
if ($value['title'] == 'Relationship') {
$relTypes = CRM_Core_PseudoConstant::relationshipType();
$op = CRM_Utils_array::value('relationship_type_id_op', $this->_params) == 'in' ? ts('Is one of') . ' ' : ts('Is not one of') . ' ';
$relationshipTypes = array();
foreach ($this->_params['relationship_type_id_value'] as $relationship) {
$relationshipTypes[] = $relTypes[$relationship]['label_' . $this->relationType];
}
$statistics['filters'][$id]['value'] = $op . implode(', ', $relationshipTypes);
}
//for displaying relationship status
if ($value['title'] == 'Relationship Status') {
$isStatusFilter = TRUE;
$statistics['filters'][$id]['value'] = $relStatus;
}
}
}
//for displaying relationship status
if (!$isStatusFilter && $relStatus) {
$statistics['filters'][] = array('title' => 'Relationship Status', 'value' => $relStatus);
}
return $statistics;
}
示例3: moveAllBelongings
/**
* Based on the provided two contact_ids and a set of tables, move the belongings of the
* other contact to the main one - be it Location / CustomFields or Contact .. related info.
* A superset of moveContactBelongings() function.
*
* @param int $mainId
* Main contact with whom merge has to happen.
* @param int $otherId
* Duplicate contact which would be deleted after merge operation.
*
* @param $migrationInfo
*
* @return bool
*/
public static function moveAllBelongings($mainId, $otherId, $migrationInfo)
{
if (empty($migrationInfo)) {
return FALSE;
}
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
$relTables = CRM_Dedupe_Merger::relTables();
$moveTables = $locBlocks = $tableOperations = array();
foreach ($migrationInfo as $key => $value) {
if ($value == $qfZeroBug) {
$value = '0';
}
if ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) || substr($key, 0, 12) == 'move_custom_') && $value != NULL) {
$submitted[substr($key, 5)] = $value;
} elseif (substr($key, 0, 14) == 'move_location_' and $value != NULL) {
$locField = explode('_', $key);
$fieldName = $locField[2];
$fieldCount = $locField[3];
$operation = CRM_Utils_Array::value('operation', $migrationInfo['location'][$fieldName][$fieldCount]);
// default operation is overwrite.
if (!$operation) {
$operation = 2;
}
$locBlocks[$fieldName][$fieldCount]['operation'] = $operation;
$locBlocks[$fieldName][$fieldCount]['locTypeId'] = CRM_Utils_Array::value('locTypeId', $migrationInfo['location'][$fieldName][$fieldCount]);
} elseif (substr($key, 0, 15) == 'move_rel_table_' and $value == '1') {
$moveTables = array_merge($moveTables, $relTables[substr($key, 5)]['tables']);
if (array_key_exists('operation', $migrationInfo)) {
foreach ($relTables[substr($key, 5)]['tables'] as $table) {
if (array_key_exists($key, $migrationInfo['operation'])) {
$tableOperations[$table] = $migrationInfo['operation'][$key];
}
}
}
}
}
// **** Do location related migration:
if (!empty($locBlocks)) {
$locComponent = array('email' => 'Email', 'phone' => 'Phone', 'im' => 'IM', 'openid' => 'OpenID', 'address' => 'Address');
$primaryBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, array('is_primary' => 1));
$billingBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, array('is_billing' => 1));
foreach ($locBlocks as $name => $block) {
if (!is_array($block) || CRM_Utils_System::isNull($block)) {
continue;
}
$daoName = 'CRM_Core_DAO_' . $locComponent[$name];
$primaryDAOId = array_key_exists($name, $primaryBlockIds) ? array_pop($primaryBlockIds[$name]) : NULL;
$billingDAOId = array_key_exists($name, $billingBlockIds) ? array_pop($billingBlockIds[$name]) : NULL;
foreach ($block as $blkCount => $values) {
$locTypeId = CRM_Utils_Array::value('locTypeId', $values, 1);
$operation = CRM_Utils_Array::value('operation', $values, 2);
$otherBlockId = CRM_Utils_Array::value($blkCount, $migrationInfo['other_details']['loc_block_ids'][$name]);
// keep 1-1 mapping for address - loc type.
$idKey = $blkCount;
if (array_key_exists($name, $locComponent)) {
$idKey = $locTypeId;
}
if (isset($migrationInfo['main_details']['loc_block_ids'][$name])) {
$mainBlockId = CRM_Utils_Array::value($idKey, $migrationInfo['main_details']['loc_block_ids'][$name]);
}
if (!$otherBlockId) {
continue;
}
// for the block which belongs to other-contact, link the contact to main-contact
$otherBlockDAO = new $daoName();
$otherBlockDAO->id = $otherBlockId;
$otherBlockDAO->contact_id = $mainId;
$otherBlockDAO->location_type_id = $locTypeId;
// if main contact already has primary & billing, set the flags to 0.
if ($primaryDAOId) {
$otherBlockDAO->is_primary = 0;
}
if ($billingDAOId) {
$otherBlockDAO->is_billing = 0;
}
// overwrite - need to delete block which belongs to main-contact.
if (isset($mainBlockId) && $mainBlockId && $operation == 2) {
$deleteDAO = new $daoName();
$deleteDAO->id = $mainBlockId;
$deleteDAO->find(TRUE);
// if we about to delete a primary / billing block, set the flags for new block
// that we going to assign to main-contact
if ($primaryDAOId && $primaryDAOId == $deleteDAO->id) {
$otherBlockDAO->is_primary = 1;
}
if ($billingDAOId && $billingDAOId == $deleteDAO->id) {
//.........这里部分代码省略.........
示例4: formRule
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param CRM_Core_Form $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self)
{
$errors = array();
$amount = self::computeAmount($fields, $self->_values);
if (!empty($fields['selectMembership']) && $fields['selectMembership'] != 'no_thanks' || !empty($fields['priceSetId']) && $self->_useForMember) {
$lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, FALSE, TRUE);
$membershipOrgDetails = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization();
$unallowedOrgs = array();
foreach (array_keys($lifeMember) as $memTypeId) {
$unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
}
}
//check for atleast one pricefields should be selected
if (!empty($fields['priceSetId'])) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$check = array();
$membershipIsActive = TRUE;
$previousId = $otherAmount = FALSE;
while ($priceField->fetch()) {
if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
}
}
if ($priceField->name == 'other_amount') {
if ($self->_quickConfig && empty($fields["price_{$priceField->id}"]) && array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
$otherAmount = $priceField->id;
} elseif (!empty($fields["price_{$priceField->id}"])) {
$otherAmountVal = CRM_Utils_Rule::cleanMoney($fields["price_{$priceField->id}"]);
$min = CRM_Utils_Array::value('min_amount', $self->_values);
$max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1', array(1 => $min));
}
if ($max && $otherAmountVal > $max) {
$errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
}
}
}
if (!empty($fields["price_{$priceField->id}"]) || $previousId == $priceField->id && isset($fields["price_{$previousId}"]) && empty($fields["price_{$previousId}"])) {
$check[] = $priceField->id;
}
}
$currentMemberships = NULL;
if ($membershipIsActive) {
$is_test = $self->_mode != 'live' ? 1 : 0;
$memContactID = $self->_membershipContactID;
// For anonymous user check using dedupe rule
// if user has Cancelled Membership
if (!$memContactID) {
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
$dedupeParams['check_permission'] = FALSE;
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
$memContactID = CRM_Utils_Array::value(0, $ids);
}
$currentMemberships = CRM_Member_BAO_Membership::getContactsCancelledMembership($memContactID, $is_test);
$errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) {
if (!is_array($fields['price_' . $fieldKey])) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]]) && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
}
} else {
foreach ($fields['price_' . $fieldKey] as $key => $ignore) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$key]) && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])));
}
}
}
}
}
}
// CRM-12233
if ($membershipIsActive && !$self->_membershipBlock['is_required'] && $self->_values['amount_block_is_active']) {
$membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
// if 'No thank you' membership is selected then set $membershipFieldId
if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey, $fields) == 0) {
$membershipFieldId = $fieldKey;
} elseif ($membershipFieldId) {
if ($fieldValue['name'] == 'other_amount') {
$otherFieldId = $fieldKey;
//.........这里部分代码省略.........
示例5: assignToTemplate
/**
* Assign the minimal set of variables to the template.
*/
public function assignToTemplate()
{
$name = CRM_Utils_Array::value('billing_first_name', $this->_params);
if (!empty($this->_params['billing_middle_name'])) {
$name .= " {$this->_params['billing_middle_name']}";
}
$name .= ' ' . CRM_Utils_Array::value('billing_last_name', $this->_params);
$name = trim($name);
$this->assign('billingName', $name);
$this->set('name', $name);
$this->assign('paymentProcessor', $this->_paymentProcessor);
$vars = array('amount', 'currencyID', 'credit_card_type', 'trxn_id', 'amount_level');
$config = CRM_Core_Config::singleton();
if (isset($this->_values['is_recur']) && !empty($this->_paymentProcessor['is_recur'])) {
$this->assign('is_recur_enabled', 1);
$vars = array_merge($vars, array('is_recur', 'frequency_interval', 'frequency_unit', 'installments'));
}
if (in_array('CiviPledge', $config->enableComponents) && CRM_Utils_Array::value('is_pledge', $this->_params) == 1) {
$this->assign('pledge_enabled', 1);
$vars = array_merge($vars, array('is_pledge', 'pledge_frequency_interval', 'pledge_frequency_unit', 'pledge_installments'));
}
// @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
// function to get correct amount level consistently. Remove setting of the amount level in
// CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
// to cover all variants.
if (isset($this->_params['amount_other']) || isset($this->_params['selectMembership'])) {
$this->_params['amount_level'] = '';
}
foreach ($vars as $v) {
if (isset($this->_params[$v])) {
if ($v == "amount" && $this->_params[$v] === 0) {
$this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], NULL, NULL, TRUE);
}
$this->assign($v, $this->_params[$v]);
}
}
// assign the address formatted up for display
$addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
$addressFields = array();
foreach ($addressParts as $part) {
list($n, $id) = explode('-', $part);
$addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $this->_params);
}
$this->assign('address', CRM_Utils_Address::format($addressFields));
if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf'])) {
$this->assign('onBehalfName', $this->_params['organization_name']);
$locTypeId = array_keys($this->_params['onbehalf_location']['email']);
$this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']);
}
//fix for CRM-3767
$assignCCInfo = FALSE;
if ($this->_amount > 0.0) {
$assignCCInfo = TRUE;
} elseif (!empty($this->_params['selectMembership'])) {
$memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee');
if ($memFee > 0.0) {
$assignCCInfo = TRUE;
}
}
// The concept of contributeMode is deprecated.
// The payment processor object can provide info about the fields it shows.
if ($this->_contributeMode == 'direct' && $assignCCInfo) {
if ($this->_paymentProcessor && $this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
$this->assign('account_holder', $this->_params['account_holder']);
$this->assign('bank_identification_number', $this->_params['bank_identification_number']);
$this->assign('bank_name', $this->_params['bank_name']);
$this->assign('bank_account_number', $this->_params['bank_account_number']);
} else {
$date = CRM_Utils_Date::format(CRM_Utils_array::value('credit_card_exp_date', $this->_params));
$date = CRM_Utils_Date::mysqlToIso($date);
$this->assign('credit_card_exp_date', $date);
$this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard(CRM_Utils_array::value('credit_card_number', $this->_params)));
}
}
$this->assign('email', $this->controller->exportValue('Main', "email-{$this->_bltID}"));
// also assign the receipt_text
if (isset($this->_values['receipt_text'])) {
$this->assign('receipt_text', $this->_values['receipt_text']);
}
}
示例6: formRule
/**
* global form rule
*
* @param array $fields the input form values
* @param array $files the uploaded files if any
* @param array $options additional user data
*
* @return true if no errors, else array of errors
* @access public
* @static
*/
static function formRule($fields, $files, $self)
{
$errors = array();
//as for separate membership payment we has to have
//contribution amount section enabled, hence to disable it need to
//check if separate membership payment enabled,
//if so disable first separate membership payment option
//then disable contribution amount section. CRM-3801,
$membershipBlock = new CRM_Member_DAO_MembershipBlock();
$membershipBlock->entity_table = 'civicrm_contribution_page';
$membershipBlock->entity_id = $self->_id;
$membershipBlock->is_active = 1;
$hasMembershipBlk = FALSE;
if ($membershipBlock->find(TRUE)) {
if (CRM_Utils_Array::value('amount_block_is_active', $fields) && ($setID = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $self->_id, NULL, 1))) {
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $setID, 'extends');
if ($extends && $extends == CRM_Core_Component::getComponentID('CiviMember')) {
$errors['amount_block_is_active'] = ts('You cannot use a Membership Price Set when the Contribution Amounts section is enabled. Click the Memberships tab above, and select your Membership Price Set on that form. Membership Price Sets may include additional fields for non-membership options that require an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
return $errors;
}
}
$hasMembershipBlk = TRUE;
if ($membershipBlock->is_separate_payment && !$fields['amount_block_is_active']) {
$errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.');
}
}
$minAmount = CRM_Utils_Array::value('min_amount', $fields);
$maxAmount = CRM_Utils_Array::value('max_amount', $fields);
if (!empty($minAmount) && !empty($maxAmount)) {
$minAmount = CRM_Utils_Rule::cleanMoney($minAmount);
$maxAmount = CRM_Utils_Rule::cleanMoney($maxAmount);
if ((double) $minAmount > (double) $maxAmount) {
$errors['min_amount'] = ts('Minimum Amount should be less than Maximum Amount');
}
}
if (isset($fields['is_pay_later'])) {
if (empty($fields['pay_later_text'])) {
$errors['pay_later_text'] = ts('Please enter the text for the \'pay later\' checkbox displayed on the contribution form.');
}
if (empty($fields['pay_later_receipt'])) {
$errors['pay_later_receipt'] = ts('Please enter the instructions to be sent to the contributor when they choose to \'pay later\'.');
}
}
// don't allow price set w/ membership signup, CRM-5095
if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
// don't allow price set w/ membership.
if ($hasMembershipBlk) {
$errors['price_set_id'] = ts('You cannot enable both a Contribution Price Set and Membership Signup on the same online contribution page.');
}
} else {
if (isset($fields['is_recur'])) {
if (empty($fields['recur_frequency_unit'])) {
$errors['recur_frequency_unit'] = ts('At least one recurring frequency option needs to be checked.');
}
}
// validation for pledge fields.
if (CRM_Utils_array::value('is_pledge_active', $fields)) {
if (empty($fields['pledge_frequency_unit'])) {
$errors['pledge_frequency_unit'] = ts('At least one pledge frequency option needs to be checked.');
}
if (CRM_Utils_array::value('is_recur', $fields)) {
$errors['is_recur'] = ts('You cannot enable both Recurring Contributions AND Pledges on the same online contribution page.');
}
}
// If Contribution amount section is enabled, then
// Allow other amounts must be enabeld OR the Fixed Contribution
// Contribution options must contain at least one set of values.
if (CRM_Utils_Array::value('amount_block_is_active', $fields)) {
if (!CRM_Utils_Array::value('is_allow_other_amount', $fields) && !$priceSetId) {
//get the values of amount block
$values = CRM_Utils_Array::value('value', $fields);
$isSetRow = FALSE;
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
$isSetRow = TRUE;
}
}
if (!$isSetRow) {
$errors['amount_block_is_active'] = ts('If you want to enable the \'Contribution Amounts section\', you need to either \'Allow Other Amounts\' and/or enter at least one row in the \'Fixed Contribution Amounts\' table.');
}
}
}
}
if (CRM_Utils_Array::value('is_recur_interval', $fields)) {
foreach (array_keys($fields['payment_processor']) as $paymentProcessorID) {
$paymentProcessorType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', $paymentProcessorID, 'payment_processor_type');
if ($paymentProcessorType == 'Google_Checkout') {
$errors['is_recur_interval'] = ts('Google Checkout does not support recurring intervals');
break;
//.........这里部分代码省略.........
示例7: assignToTemplate
/**
* assign the minimal set of variables to the template
*
* @return void
* @access public
*/
function assignToTemplate()
{
$name = CRM_Utils_Array::value('billing_first_name', $this->_params);
if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) {
$name .= " {$this->_params['billing_middle_name']}";
}
$name .= ' ' . CRM_Utils_Array::value('billing_last_name', $this->_params);
$name = trim($name);
$this->assign('billingName', $name);
$this->set('name', $name);
$this->assign('paymentProcessor', $this->_paymentProcessor);
$vars = array('amount', 'currencyID', 'credit_card_type', 'trxn_id', 'amount_level');
$config = CRM_Core_Config::singleton();
if (isset($this->_values['is_recur']) && CRM_Utils_Array::value('is_recur', $this->_paymentProcessor)) {
$this->assign('is_recur_enabled', 1);
$vars = array_merge($vars, array('is_recur', 'frequency_interval', 'frequency_unit', 'installments'));
}
if (in_array('CiviPledge', $config->enableComponents) && CRM_Utils_Array::value('is_pledge', $this->_params) == 1) {
$this->assign('pledge_enabled', 1);
$vars = array_merge($vars, array('is_pledge', 'pledge_frequency_interval', 'pledge_frequency_unit', 'pledge_installments'));
}
if (isset($this->_params['amount_other']) || isset($this->_params['selectMembership'])) {
$this->_params['amount_level'] = '';
}
foreach ($vars as $v) {
if (isset($this->_params[$v])) {
if ($v == 'frequency_unit' || $v == 'pledge_frequency_unit') {
$frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
if (array_key_exists($this->_params[$v], $frequencyUnits)) {
$this->_params[$v] = $frequencyUnits[$this->_params[$v]];
}
}
if ($v == "amount" && $this->_params[$v] === 0) {
$this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], NULL, NULL, TRUE);
}
$this->assign($v, $this->_params[$v]);
}
}
// assign the address formatted up for display
$addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
$addressFields = array();
foreach ($addressParts as $part) {
list($n, $id) = explode('-', $part);
$addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $this->_params);
}
$this->assign('address', CRM_Utils_Address::format($addressFields));
if (CRM_Utils_Array::value('hidden_onbehalf_profile', $this->_params)) {
$this->assign('onBehalfName', $this->_params['organization_name']);
$locTypeId = array_keys($this->_params['onbehalf_location']['email']);
$this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']);
}
//fix for CRM-3767
$assignCCInfo = FALSE;
if ($this->_amount > 0.0) {
$assignCCInfo = TRUE;
} elseif (CRM_Utils_array::value('selectMembership', $this->_params)) {
$memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee');
if ($memFee > 0.0) {
$assignCCInfo = TRUE;
}
}
if ($this->_contributeMode == 'direct' && $assignCCInfo) {
if ($this->_paymentProcessor && $this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
$this->assign('payment_type', $this->_paymentProcessor['payment_type']);
$this->assign('account_holder', $this->_params['account_holder']);
$this->assign('bank_identification_number', $this->_params['bank_identification_number']);
$this->assign('bank_name', $this->_params['bank_name']);
$this->assign('bank_account_number', $this->_params['bank_account_number']);
} else {
$date = CRM_Utils_Date::format(CRM_Utils_array::value('credit_card_exp_date', $this->_params));
$date = CRM_Utils_Date::mysqlToIso($date);
$this->assign('credit_card_exp_date', $date);
$this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard(CRM_Utils_array::value('credit_card_number', $this->_params)));
}
}
$this->assign('email', $this->controller->exportValue('Main', "email-{$this->_bltID}"));
// also assign the receipt_text
if (isset($this->_values['receipt_text'])) {
$this->assign('receipt_text', $this->_values['receipt_text']);
}
}
示例8: assignAddressField
/**
* Add fields to $profileAddressFields as appropriate.
* profileAddressFields is assigned to the template to tell it
* what fields are in the profile address
* that potentially should be copied to the Billing fields
* we want to give precedence to
* 1) Billing &
* 2) then Primary designated as 'Primary
* 3) location_type is primary
* 4) if none of these apply then it just uses the first one
*
* as this will be used to
* transfer profile address data to billing fields
* http://issues.civicrm.org/jira/browse/CRM-5869
*
* @param string $key Field key - e.g. street_address-Primary, first_name
* @param array $profileAddressFields array of profile fields that relate to address fields
* @param array $profileFilter filter to apply to profile fields - expected usage is to only fill based on
* the bottom profile per CRM-13726
*/
static function assignAddressField($key, &$profileAddressFields, $profileFilter)
{
$billing_id = CRM_Core_BAO_LocationType::getBilling();
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
$profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name')));
//check for valid fields ( fields that are present in billing block )
$validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country');
$validProfileFields = array();
foreach ($profileFields['values'] as $field) {
if (in_array($field['field_name'], $validBillingFields)) {
$validProfileFields[] = $field['field_name'];
}
}
if (!in_array($prefixName, $validProfileFields)) {
return;
}
if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) {
$profileAddressFields[$prefixName] = $index;
}
}
示例9: formRule
/**
* global form rule
*
* @param array $fields the input form values
* @param array $files the uploaded files if any
* @param array $options additional user data
*
* @return true if no errors, else array of errors
* @access public
* @static
*/
static function formRule($fields, $files, $self)
{
$errors = array();
$amount = self::computeAmount($fields, $self);
if (CRM_Utils_Array::value('selectMembership', $fields) && $fields['selectMembership'] != 'no_thanks' || CRM_Utils_Array::value('priceSetId', $fields) && $self->_useForMember) {
$lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_userID, FALSE, TRUE);
$membershipOrgDetails = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization();
$unallowedOrgs = array();
foreach (array_keys($lifeMember) as $memTypeId) {
$unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
}
}
//check for atleast one pricefields should be selected
if (CRM_Utils_Array::value('priceSetId', $fields)) {
$priceField = new CRM_Price_DAO_Field();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$check = array();
$membershipIsActive = TRUE;
$previousId = $otherAmount = FALSE;
while ($priceField->fetch()) {
if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
}
}
if ($priceField->name == 'other_amount') {
if ($self->_quickConfig && !CRM_Utils_Array::value("price_{$priceField->id}", $fields) && array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
$otherAmount = $priceField->id;
} elseif (!empty($fields["price_{$priceField->id}"])) {
$otherAmountVal = $fields["price_{$priceField->id}"];
$min = CRM_Utils_Array::value('min_amount', $self->_values);
$max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1', array(1 => $min));
}
if ($max && $otherAmountVal > $max) {
$errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
}
}
}
if (!empty($fields["price_{$priceField->id}"]) || $previousId == $priceField->id && isset($fields["price_{$previousId}"]) && empty($fields["price_{$previousId}"])) {
$check[] = $priceField->id;
}
}
if (empty($check)) {
if ($self->_useForMember == 1 && $membershipIsActive) {
$errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
} else {
$errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
}
}
if ($otherAmount && !empty($check)) {
$errors["price_{$otherAmount}"] = ts('Amount is required field.');
}
if ($self->_useForMember == 1 && !empty($check) && $membershipIsActive) {
$priceFieldIDS = array();
$priceFieldMemTypes = array();
foreach ($self->_priceSet['fields'] as $priceId => $value) {
if (!empty($fields['price_' . $priceId]) || $self->_quickConfig && $value['name'] == 'membership_amount' && !CRM_Utils_Array::value('is_required', $self->_membershipBlock)) {
if (CRM_Utils_Array::value('price_' . $priceId, $fields) && is_array($fields['price_' . $priceId])) {
foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
if ($isSet) {
$priceFieldIDS[] = $priceFldVal;
}
}
} elseif (!$value['is_enter_qty'] && CRM_Utils_Array::value('price_' . $priceId, $fields)) {
// The check for {!$value['is_enter_qty']} is done since, quantity fields allow entering
// quantity. And the quantity can't be conisdered as civicrm_price_field_value.id, CRM-9577
$priceFieldIDS[] = $fields['price_' . $priceId];
}
if (CRM_Utils_Array::value('options', $value)) {
foreach ($value['options'] as $val) {
if (CRM_Utils_Array::value('membership_type_id', $val)) {
$priceFieldMemTypes[] = $val['membership_type_id'];
}
}
}
}
}
if (!empty($lifeMember)) {
foreach ($priceFieldIDS as $priceFieldId) {
if (($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldId, 'membership_type_id')) && in_array($membershipOrgDetails[$id], $unallowedOrgs)) {
$errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
break;
}
}
//.........这里部分代码省略.........
示例10: mte_checkSettings
function mte_checkSettings($context)
{
$usedFor = 1;
if ($context == 'civimail') {
$usedFor = 2;
}
$mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
if (CRM_Utils_array::value('is_active', $mailingBackend) && array_key_exists('used_for', $mailingBackend) && !empty($mailingBackend['used_for'][$usedFor])) {
return TRUE;
}
return FALSE;
}
示例11: sendMailings
static function sendMailings($mappingID, $now)
{
$domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
$fromEmailAddress = "{$domainValues['0']} <{$domainValues['1']}>";
$mapping = new CRM_Core_DAO_ActionMapping();
$mapping->id = $mappingID;
$mapping->find(TRUE);
$actionSchedule = new CRM_Core_DAO_ActionSchedule();
$actionSchedule->mapping_id = $mappingID;
$actionSchedule->is_active = 1;
$actionSchedule->find(FALSE);
$tokenFields = array();
$session = CRM_Core_Session::singleton();
while ($actionSchedule->fetch()) {
$extraSelect = $extraJoin = $extraWhere = '';
if ($actionSchedule->record_activity) {
if ($mapping->entity == 'civicrm_membership') {
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Membership Renewal Reminder', 'name');
} else {
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Reminder Sent', 'name');
}
$activityStatusID = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
}
if ($mapping->entity == 'civicrm_activity') {
$tokenEntity = 'activity';
$tokenFields = array('activity_id', 'activity_type', 'subject', 'details', 'activity_date_time');
$extraSelect = ", ov.label as activity_type, e.id as activity_id";
$extraJoin = "INNER JOIN civicrm_option_group og ON og.name = 'activity_type'\nINNER JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id";
$extraWhere = "AND e.is_current_revision = 1 AND e.is_deleted = 0";
}
if ($mapping->entity == 'civicrm_participant') {
$tokenEntity = 'event';
$tokenFields = array('event_type', 'title', 'event_id', 'start_date', 'end_date', 'summary', 'description', 'location', 'info_url', 'registration_url', 'fee_amount', 'contact_email', 'contact_phone');
$extraSelect = ", ov.label as event_type, ev.title, ev.id as event_id, ev.start_date, ev.end_date, ev.summary, ev.description, address.street_address, address.city, address.state_province_id, address.postal_code, email.email as contact_email, phone.phone as contact_phone ";
$extraJoin = "\nINNER JOIN civicrm_event ev ON e.event_id = ev.id\nINNER JOIN civicrm_option_group og ON og.name = 'event_type'\nINNER JOIN civicrm_option_value ov ON ev.event_type_id = ov.value AND ov.option_group_id = og.id\nLEFT JOIN civicrm_loc_block lb ON lb.id = ev.loc_block_id\nLEFT JOIN civicrm_address address ON address.id = lb.address_id\nLEFT JOIN civicrm_email email ON email.id = lb.email_id\nLEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id\n";
}
if ($mapping->entity == 'civicrm_membership') {
$tokenEntity = 'membership';
$tokenFields = array('fee', 'id', 'join_date', 'start_date', 'end_date', 'status', 'type');
$extraSelect = ", mt.minimum_fee as fee, e.id as id , e.join_date, e.start_date, e.end_date, ms.name as status, mt.name as type";
$extraJoin = "\n INNER JOIN civicrm_membership_type mt ON e.membership_type_id = mt.id\n INNER JOIN civicrm_membership_status ms ON e.status_id = ms.id";
}
$query = "\nSELECT reminder.id as reminderID, reminder.*, e.id as entityID, e.* {$extraSelect}\nFROM civicrm_action_log reminder\nINNER JOIN {$mapping->entity} e ON e.id = reminder.entity_id\n{$extraJoin}\nWHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL\n{$extraWhere}";
$dao = CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer')));
while ($dao->fetch()) {
$entityTokenParams = array();
foreach ($tokenFields as $field) {
if ($field == 'location') {
$loc = array();
$stateProvince = CRM_Core_PseudoConstant::stateProvince();
$loc['street_address'] = $dao->street_address;
$loc['city'] = $dao->city;
$loc['state_province'] = CRM_Utils_array::value($dao->state_province_id, $stateProvince);
$loc['postal_code'] = $dao->postal_code;
$entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Address::format($loc);
} elseif ($field == 'info_url') {
$entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE);
} elseif ($field == 'registration_url') {
$entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE);
} elseif (in_array($field, array('start_date', 'end_date', 'join_date', 'activity_date_time'))) {
$entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Date::customFormat($dao->{$field});
} else {
$entityTokenParams["{$tokenEntity}." . $field] = $dao->{$field};
}
}
$isError = 0;
$errorMsg = '';
$toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($dao->contact_id);
if ($toEmail) {
$result = CRM_Core_BAO_ActionSchedule::sendReminder($dao->contact_id, $toEmail, $actionSchedule->id, $fromEmailAddress, $entityTokenParams);
if (!$result || is_a($result, 'PEAR_Error')) {
// we could not send an email, for now we ignore, CRM-3406
$isError = 1;
}
} else {
$isError = 1;
$errorMsg = "Couldn\\'t find recipient\\'s email address.";
}
// update action log record
$logParams = array('id' => $dao->reminderID, 'is_error' => $isError, 'message' => $errorMsg ? $errorMsg : "null", 'action_date_time' => $now);
CRM_Core_BAO_ActionLog::create($logParams);
// insert activity log record if needed
if ($actionSchedule->record_activity) {
$activityParams = array('subject' => $actionSchedule->title, 'details' => $actionSchedule->body_html, 'source_contact_id' => $session->get('userID') ? $session->get('userID') : $dao->contact_id, 'target_contact_id' => $dao->contact_id, 'activity_date_time' => date('YmdHis'), 'status_id' => $activityStatusID, 'activity_type_id' => $activityTypeID, 'source_record_id' => $dao->entityID);
$activity = CRM_Activity_BAO_Activity::create($activityParams);
}
}
$dao->free();
}
}
示例12: assignAddressField
/**
* Add fields to $profileAddressFields as appropriate.
* profileAddressFields is assigned to the template to tell it
* what fields are in the profile address
* that potentially should be copied to the Billing fields
* we want to give precedence to
* 1) Billing &
* 2) then Primary designated as 'Primary
* 3) location_type is primary
* 4) if none of these apply then it just uses the first one
*
* as this will be used to
* transfer profile address data to billing fields
* http://issues.civicrm.org/jira/browse/CRM-5869
* @param string $key Field key - e.g. street_address-Primary, first_name
* @params array $profileAddressFields array of profile fields that relate to address fields
*/
static function assignAddressField($key, &$profileAddressFields)
{
$billing_id = CRM_Core_BAO_LocationType::getBilling();
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
//check for valid fields ( fields that are present in billing block )
$validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country');
if (!in_array($prefixName, $validBillingFields)) {
return;
}
if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) {
$profileAddressFields[$prefixName] = $index;
}
}
示例13: formRule
/**
* global form rule
*
* @param array $fields the input form values
* @param array $files the uploaded files if any
* @param array $options additional user data
*
* @return true if no errors, else array of errors
* @access public
* @static
*/
static function formRule($fields, $files, $self)
{
$errors = array();
$amount = self::computeAmount($fields, $self);
//check for atleast one pricefields should be selected
if (CRM_Utils_Array::value('priceSetId', $fields)) {
$priceField = new CRM_Price_DAO_Field();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->find();
$check = array();
while ($priceField->fetch()) {
if (!empty($fields["price_{$priceField->id}"])) {
$check[] = $priceField->id;
}
}
if (empty($check)) {
if ($self->_useForMember == 1) {
$errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
} else {
$errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
}
}
require_once 'CRM/Price/BAO/Set.php';
if ($self->_useForMember == 1 && !empty($check)) {
$priceFieldIDS = array();
$priceFieldMemTypes = array();
foreach ($self->_priceSet['fields'] as $priceId => $value) {
if (!empty($fields['price_' . $priceId])) {
if (is_array($fields['price_' . $priceId])) {
foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
if ($isSet) {
$priceFieldIDS[] = $priceFldVal;
}
}
} else {
$priceFieldIDS[] = $fields['price_' . $priceId];
}
if (CRM_Utils_Array::value('options', $value)) {
foreach ($value['options'] as $val) {
if (CRM_Utils_Array::value('membership_type_id', $val)) {
$priceFieldMemTypes[] = $val['membership_type_id'];
}
}
}
}
}
$ids = implode(',', $priceFieldIDS);
$priceFieldIDS['id'] = $fields['priceSetId'];
$self->set('memberPriceFieldIDS', $priceFieldIDS);
$count = CRM_Price_BAO_Set::getMembershipCount($ids);
foreach ($count as $id => $occurance) {
if ($occurance > 1) {
$errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity. Contact the site administrator if you need assistance.');
}
}
if (empty($priceFieldMemTypes)) {
$errors['_qf_default'] = ts('Please select at least one membership option.');
}
}
CRM_Price_BAO_Set::processAmount($self->_values['fee'], $fields, $lineItem);
if ($fields['amount'] < 0) {
$errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
}
$amount = $fields['amount'];
}
if (isset($fields['selectProduct']) && $fields['selectProduct'] != 'no_thanks' && $self->_values['amount_block_is_active']) {
require_once 'CRM/Contribute/DAO/Product.php';
require_once 'CRM/Utils/Money.php';
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $fields['selectProduct'];
$productDAO->find(true);
$min_amount = $productDAO->min_contribution;
if ($amount < $min_amount) {
$errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($min_amount)));
}
}
if ($self->_values['honor_block_is_active'] && CRM_Utils_Array::value('honor_type_id', $fields)) {
// make sure there is a first name and last name if email is not there
if (!CRM_Utils_Array::value('honor_email', $fields)) {
if (!CRM_Utils_Array::value('honor_first_name', $fields) || !CRM_Utils_Array::value('honor_last_name', $fields)) {
$errors['honor_last_name'] = ts('In Honor Of - First Name and Last Name, OR an Email Address is required.');
}
}
}
if (isset($fields['is_recur']) && $fields['is_recur']) {
if ($fields['frequency_interval'] <= 0) {
$errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).');
}
if ($fields['frequency_unit'] == '0') {
//.........这里部分代码省略.........
示例14: CRM_Member_DAO_Membership
/**
* takes an associative array and creates a membership object
*
* the function extracts all the params it needs to initialize the created
* membership object. The params array could contain additional unused name/value
* pairs
*
* @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_Member_BAO_Membership object
* @access public
* @static
*/
static function &add(&$params, &$ids)
{
// get activity types for use in activity record creation
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
if (CRM_Utils_Array::value('membership', $ids)) {
CRM_Utils_Hook::pre('edit', 'Membership', $ids['membership'], $params);
$oldStatus = NULL;
$oldType = NULL;
$membershipObj = new CRM_Member_DAO_Membership();
$membershipObj->id = $ids['membership'];
$membershipObj->find();
while ($membershipObj->fetch()) {
$oldStatus = $membershipObj->status_id;
$oldType = $membershipObj->membership_type_id;
}
} else {
CRM_Utils_Hook::pre('create', 'Membership', NULL, $params);
}
if (array_key_exists('reminder_date', $params) && !$params['reminder_date']) {
$params['reminder_date'] = 'null';
}
if (array_key_exists('is_override', $params) && !$params['is_override']) {
$params['is_override'] = 'null';
}
$membership = new CRM_Member_BAO_Membership();
$membership->copyValues($params);
$membership->id = CRM_Utils_Array::value('membership', $ids);
$membership->save();
$membership->free();
$session = CRM_Core_Session::singleton();
if (empty($membership->contact_id) || empty($membership->status_id)) {
// this means we are in renewal mode and are just updating the membership
// record or this is an API update call and all fields are not present in the update record
// however the hooks dont care and want all data CRM-7784
$tempMembership = new CRM_Member_DAO_Membership();
$tempMembership->id = $membership->id;
$tempMembership->find(TRUE);
$membership = $tempMembership;
}
//get the log start date.
//it is set during renewal of membership.
$logStartDate = CRM_Utils_array::value('log_start_date', $params);
$logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : CRM_Utils_Date::isoToMysql($membership->start_date);
$values = self::getStatusANDTypeValues($membership->id);
$membershipLog = array('membership_id' => $membership->id, 'status_id' => $membership->status_id, 'start_date' => $logStartDate, 'end_date' => CRM_Utils_Date::isoToMysql($membership->end_date), 'renewal_reminder_date' => CRM_Utils_Date::isoToMysql($membership->reminder_date), 'modified_date' => date('Ymd'), 'membership_type_id' => $values[$membership->id]['membership_type_id']);
$session = CRM_Core_Session::singleton();
// If we have an authenticated session, set modified_id to that user's contact_id, else set to membership.contact_id
if ($session->get('userID')) {
$membershipLog['modified_id'] = $session->get('userID');
} elseif (!empty($ids['userId'])) {
$membershipLog['modified_id'] = $ids['userId'];
} else {
$membershipLog['modified_id'] = $membership->contact_id;
}
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
// reset the group contact cache since smart groups might be affected due to this
CRM_Contact_BAO_GroupContactCache::remove();
if (CRM_Utils_Array::value('membership', $ids)) {
if ($membership->status_id != $oldStatus) {
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
$activityParam = array('subject' => "Status changed from {$allStatus[$oldStatus]} to {$allStatus[$membership->status_id]}", 'source_contact_id' => $membershipLog['modified_id'], 'target_contact_id' => $membership->contact_id, 'source_record_id' => $membership->id, 'activity_type_id' => array_search('Change Membership Status', $activityTypes), 'status_id' => 2, 'version' => 3, 'priority_id' => 2, 'activity_date_time' => date('Y-m-d H:i:s'), 'is_auto' => 0, 'is_current_revision' => 1, 'is_deleted' => 0);
$activityResult = civicrm_api('activity', 'create', $activityParam);
}
if (isset($membership->membership_type_id) && $membership->membership_type_id != $oldType) {
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
$activityParam = array('subject' => "Type changed from {$membershipTypes[$oldType]} to {$membershipTypes[$membership->membership_type_id]}", 'source_contact_id' => $membershipLog['modified_id'], 'target_contact_id' => $membership->contact_id, 'source_record_id' => $membership->id, 'activity_type_id' => array_search('Change Membership Type', $activityTypes), 'status_id' => 2, 'version' => 3, 'priority_id' => 2, 'activity_date_time' => date('Y-m-d H:i:s'), 'is_auto' => 0, 'is_current_revision' => 1, 'is_deleted' => 0);
$activityResult = civicrm_api('activity', 'create', $activityParam);
}
CRM_Utils_Hook::post('edit', 'Membership', $membership->id, $membership);
} else {
CRM_Utils_Hook::post('create', 'Membership', $membership->id, $membership);
}
return $membership;
}
示例15: CRM_Member_BAO_Membership
/**
* takes an associative array and creates a membership object
*
* the function extract all the params it needs to initialize the create a
* membership object. the params array could contain additional unused name/value
* pairs
*
* @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_Member_BAO_Membership object
* @access public
* @static
*/
static function &add(&$params, &$ids)
{
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('membership', $ids)) {
CRM_Utils_Hook::pre('edit', 'Membership', $ids['membership'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Membership', null, $params);
}
// converting dates to mysql format
if (isset($params['join_date'])) {
$params['join_date'] = CRM_Utils_Date::isoToMysql($params['join_date']);
}
if (isset($params['start_date'])) {
$params['start_date'] = CRM_Utils_Date::isoToMysql($params['start_date']);
}
if (CRM_Utils_Array::value('end_date', $params)) {
$params['end_date'] = CRM_Utils_Date::isoToMysql($params['end_date']);
} else {
$params['end_date'] = 'null';
}
if (CRM_Utils_Array::value('reminder_date', $params)) {
$params['reminder_date'] = CRM_Utils_Date::isoToMysql($params['reminder_date']);
} else {
$params['reminder_date'] = 'null';
}
if (!CRM_Utils_Array::value('is_override', $params)) {
$params['is_override'] = 'null';
}
$membership = new CRM_Member_BAO_Membership();
$membership->copyValues($params);
$membership->id = CRM_Utils_Array::value('membership', $ids);
$membership->save();
$membership->free();
$session =& CRM_Core_Session::singleton();
//get the log start date.
//it is set during renewal of membership.
$logStartDate = CRM_Utils_array::value('log_start_date', $params);
$logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : $membership->start_date;
$membershipLog = array('membership_id' => $membership->id, 'status_id' => $membership->status_id, 'start_date' => $logStartDate, 'end_date' => $membership->end_date, 'renewal_reminder_date' => $membership->reminder_date, 'modified_id' => CRM_Utils_Array::value('userId', $ids), 'modified_date' => date('Ymd'));
require_once 'CRM/Member/BAO/MembershipLog.php';
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
// reset the group contact cache since smart groups might be affected due to this
require_once 'CRM/Contact/BAO/GroupContactCache.php';
CRM_Contact_BAO_GroupContactCache::remove();
if (CRM_Utils_Array::value('membership', $ids)) {
CRM_Utils_Hook::post('edit', 'Membership', $membership->id, $membership);
} else {
CRM_Utils_Hook::post('create', 'Membership', $membership->id, $membership);
}
return $membership;
}