本文整理汇总了PHP中CRM_Member_BAO_Membership::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_Membership::create方法的具体用法?PHP CRM_Member_BAO_Membership::create怎么用?PHP CRM_Member_BAO_Membership::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Member_BAO_Membership
的用法示例。
在下文中一共展示了CRM_Member_BAO_Membership::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_membership_contact_create
/**
* Create a Contact Membership
*
* This API is used for creating a Membership for a contact.
* Required parameters : membership_type_id and status_id.
*
* @param array $params an associative array of name/value property values of civicrm_membership
*
* @return array of newly created membership property values.
* @access public
*/
function civicrm_membership_contact_create(&$params)
{
_civicrm_initialize();
$error = _civicrm_membership_check_params($params);
if (civicrm_error($error)) {
return $error;
}
$values = array();
$error = _civicrm_membership_format_params($params, $values);
if (civicrm_error($error)) {
return $error;
}
$params = array_merge($values, $params);
require_once 'CRM/Core/Action.php';
$action = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array('userId' => $params['contact_id']);
//for edit membership id should be present
if (CRM_Utils_Array::value('id', $params)) {
$ids = array('membership' => $params['id'], 'userId' => $params['contact_id']);
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;
require_once 'CRM/Member/BAO/Membership.php';
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, true);
if (array_key_exists('is_error', $membershipBAO)) {
// In case of no valid status for given dates, $membershipBAO
// is going to contain 'is_error' => "Error Message"
return civicrm_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
$membership = array();
_civicrm_object_to_array($membershipBAO, $membership);
$values = array();
$values['id'] = $membership['id'];
$values['is_error'] = 0;
return $values;
}
示例2: civicrm_membership_contact_create
/**
* Create a Contact Membership
*
* This API is used for creating a Membership for a contact.
* Required parameters : membership_type_id and status_id.
*
* @param array $params an associative array of name/value property values of civicrm_membership
*
* @return array of newly created membership property values.
* @access public
*/
function civicrm_membership_contact_create(&$params)
{
_civicrm_initialize();
if (!is_array($params)) {
return civicrm_create_error('Params is not an array');
}
if (!isset($params['membership_type_id']) || !isset($params['contact_id']) || isset($params['is_override']) && !$params['status_id']) {
return civicrm_create_error(ts('Required parameter missing'));
}
$values = array();
$error = _civicrm_membership_format_params($params, $values);
if (is_a($error, 'CRM_Core_Error')) {
return civicrm_create_error('Membership is not created');
}
$params = array_merge($values, $params);
require_once 'CRM/Core/Action.php';
$action = CRM_Core_Action::ADD;
//for edit membership id should be present
if (CRM_Utils_Array::value('id', $params)) {
$ids = array('membership' => $params['id'], 'user_id' => $params['contact_id']);
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;
require_once 'CRM/Member/BAO/Membership.php';
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, true);
if (array_key_exists('is_error', $membershipBAO)) {
// In case of no valid status for given dates, $membershipBAO
// is going to contain 'is_error' => "Error Message"
return civicrm_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
$membership = array();
_civicrm_object_to_array($membershipBAO, $membership);
$values = array();
$values['id'] = $membership['id'];
$values['is_error'] = 0;
return $values;
}
示例3: testresetmodifiedId
/**
* Test resetmodified()
*/
public function testresetmodifiedId()
{
$contactId = Contact::createIndividual();
$params = array('contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => date('Ymd', strtotime('2006-01-21')), 'start_date' => date('Ymd', strtotime('2006-01-21')), 'end_date' => date('Ymd', strtotime('2006-12-21')), 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_mebershipStatusID);
$ids = array('userId' => $contactId);
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$resetModifiedId = CRM_Member_BAO_MembershipLog::resetModifiedID($contactId);
$this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactId, 'modified_id', 'modified_id', 'Database check for NULL modified id.');
$this->membershipDelete($membership->id);
$this->contactDelete($contactId);
}
示例4: processMembership
//.........这里部分代码省略.........
$value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
}
}
if (!empty($value['receive_date'])) {
$value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
}
$params['actualBatchTotal'] += $value['total_amount'];
unset($value['financial_type']);
unset($value['payment_instrument']);
$value['batch_id'] = $this->_batchId;
$value['skipRecentView'] = TRUE;
// make entry in line item for contribution
$editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
$editedResults = array();
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
if (!empty($editedResults)) {
unset($this->_priceSet['fields']);
$this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
unset($this->_priceSet['fields'][$editedResults['id']]['options']);
$fid = $editedResults['id'];
$editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
$editedResults = array();
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
if (!empty($value['total_amount'])) {
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
}
$fieldID = key($this->_priceSet['fields']);
$value['price_' . $fieldID] = $editedResults['id'];
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
//CRM-11529 for backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
foreach ($lineItem[$priceSetId] as &$values) {
$values['financial_type_id'] = $value['financial_type_id'];
}
}
$value['lineItems'] = $lineItem;
$value['processPriceSet'] = TRUE;
}
// end of contribution related section
unset($value['membership_type']);
unset($value['membership_start_date']);
unset($value['membership_end_date']);
$value['is_renew'] = FALSE;
if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
// The following parameter setting may be obsolete.
$this->_params = $params;
$value['is_renew'] = TRUE;
$isPayLater = CRM_Utils_Array::value('is_pay_later', $params);
$campaignId = NULL;
if (isset($this->_values) && is_array($this->_values) && !empty($this->_values)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $this->_params);
if (!array_key_exists('campaign_id', $this->_params)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $this->_values);
}
}
foreach (array('join_date', 'start_date', 'end_date') as $dateType) {
//CRM-18000 - ignore $dateType if its not explicitly passed
if (!empty($fDate[$dateType]) || !empty($fDate['membership_' . $dateType])) {
$formDates[$dateType] = CRM_Utils_Array::value($dateType, $value);
}
}
$membershipSource = CRM_Utils_Array::value('source', $value);
list($membership) = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, NULL, NULL, $value['custom'], 1, NULL, FALSE, NULL, $membershipSource, $isPayLater, $campaignId, $formDates);
// make contribution entry
$contrbutionParams = array_merge($value, array('membership_id' => $membership->id));
// @todo - calling this from here is pretty hacky since it is called from membership.create anyway
// This form should set the correct params & not call this fn directly.
CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
} else {
$membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
}
//process premiums
if (!empty($value['product_name'])) {
if ($value['product_name'][0] > 0) {
list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
$value['hidden_Premium'] = 1;
$value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]);
$premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id'), 'product_option' => $value['product_option'], 'quantity' => 1);
CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
}
}
// end of premium
//send receipt mail.
if ($membership->id && !empty($value['send_receipt'])) {
// add the domain email id
$domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
$domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>";
$value['from_email_address'] = $domainEmail;
$value['membership_id'] = $membership->id;
$value['contribution_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id');
CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
}
}
}
return TRUE;
}
示例5: civicrm_api3_membership_create
/**
* Create a Contact Membership
*
* This API is used for creating a Membership for a contact.
* Required parameters : membership_type_id and status_id.
*
* @param array $params an associative array of name/value property values of civicrm_membership
*
* @return array of newly created membership property values.
* {@getfields membership_create}
* @access public
*/
function civicrm_api3_membership_create($params)
{
// @todo shouldn't be required - should be handling by api.aliases & api.required in _spec
civicrm_api3_verify_one_mandatory($params, NULL, array('membership_type_id', 'membership_type'));
// check params for membership id during update
if (CRM_Utils_Array::value('id', $params) && !isset($params['skipStatusCal'])) {
//don't calculate dates on exisiting membership - expect API use to pass them in
// or leave unchanged
$params['skipStatusCal'] = 1;
} else {
// also check for status id if override is set (during add/update)
if (isset($params['is_override']) && !CRM_Utils_Array::value('status_id', $params)) {
return civicrm_api3_create_error('Status ID required');
}
}
$values = array();
$error = _civicrm_api3_membership_format_params($params, $values);
if (civicrm_error($error)) {
return $error;
}
_civicrm_api3_custom_format_params($params, $values, 'Membership');
$params = array_merge($params, $values);
$action = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array();
if (CRM_Utils_Array::value('contact_id', $params)) {
$ids['userId'] = $params['contact_id'];
}
//for edit membership id should be present
if (CRM_Utils_Array::value('id', $params)) {
$ids['membership'] = $params['id'];
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
if (array_key_exists('is_error', $membershipBAO)) {
// In case of no valid status for given dates, $membershipBAO
// is going to contain 'is_error' => "Error Message"
return civicrm_api3_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
$membership = array();
_civicrm_api3_object_to_array($membershipBAO, $membership[$membershipBAO->id]);
return civicrm_api3_create_success($membership, $params, 'membership', 'create', $membershipBAO);
}
示例6: processMembership
//.........这里部分代码省略.........
//Get the membership status
if (!empty($value['membership_status'])) {
$value['status_id'] = $value['membership_status'];
unset($value['membership_status']);
}
if (empty($customFields)) {
// membership type custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
}
//check for custom data
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId);
if (!empty($value['financial_type'])) {
$value['financial_type_id'] = $value['financial_type'];
}
if (!empty($value['payment_instrument'])) {
$value['payment_instrument_id'] = $value['payment_instrument'];
}
// handle soft credit
if (is_array(CRM_Utils_Array::value('soft_credit_contact_id', $params)) && !empty($params['soft_credit_contact_id'][$key]) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) {
$value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
$value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
}
if (!empty($value['receive_date'])) {
$value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
}
$params['actualBatchTotal'] += $value['total_amount'];
unset($value['financial_type']);
unset($value['payment_instrument']);
$value['batch_id'] = $this->_batchId;
$value['skipRecentView'] = TRUE;
// make entry in line item for contribution
$editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
$editedResults = array();
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
if (!empty($editedResults)) {
unset($this->_priceSet['fields']);
$this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
unset($this->_priceSet['fields'][$editedResults['id']]['options']);
$fid = $editedResults['id'];
$editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
$editedResults = array();
CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
if (!empty($value['total_amount'])) {
$this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
}
$fieldID = key($this->_priceSet['fields']);
$value['price_' . $fieldID] = $editedResults['id'];
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
//CRM-11529 for backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
foreach ($lineItem[$priceSetId] as &$values) {
$values['financial_type_id'] = $value['financial_type_id'];
}
}
$value['lineItems'] = $lineItem;
$value['processPriceSet'] = TRUE;
}
// end of contribution related section
unset($value['membership_type']);
unset($value['membership_start_date']);
unset($value['membership_end_date']);
$value['is_renew'] = false;
if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
$this->_params = $params;
$value['is_renew'] = true;
$membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']);
// make contribution entry
CRM_Member_BAO_Membership::recordMembershipContribution(array_merge($value, array('membership_id' => $membership->id)));
} else {
$membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
}
//process premiums
if (!empty($value['product_name'])) {
if ($value['product_name'][0] > 0) {
list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
$value['hidden_Premium'] = 1;
$value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]);
$premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $value['contribution_id'], 'product_option' => $value['product_option'], 'quantity' => 1);
CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
}
}
// end of premium
//send receipt mail.
if ($membership->id && !empty($value['send_receipt'])) {
// add the domain email id
$domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
$domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>";
$value['from_email_address'] = $domainEmail;
$value['membership_id'] = $membership->id;
CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
}
}
}
return TRUE;
}
示例7: postProcess
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Member_BAO_Membership::del($this->_id);
return;
}
$allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
$allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
$isTest = $this->_mode == 'test' ? 1 : 0;
$lineItems = NULL;
if (!empty($this->_lineItem)) {
$lineItems = $this->_lineItem;
}
$config = CRM_Core_Config::singleton();
// get the submitted form values.
$this->_params = $formValues = $this->controller->exportValues($this->_name);
$this->convertDateFieldsToMySQL($formValues);
$params = $softParams = $ids = array();
$membershipTypeValues = array();
foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType]['membership_type_id'] = $memType;
}
//take the required membership recur values.
if ($this->_mode && !empty($this->_params['auto_renew'])) {
$params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE;
$mapping = array('frequency_interval' => 'duration_interval', 'frequency_unit' => 'duration_unit');
$count = 0;
foreach ($this->_memTypeSelected as $memType) {
$recurMembershipTypeValues = CRM_Utils_Array::value($memType, $this->_recurMembershipTypes, array());
foreach ($mapping as $mapVal => $mapParam) {
$membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
if (!$count) {
$this->_params[$mapVal] = $formValues[$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
}
}
$count++;
}
}
// process price set and get total amount and line items.
$lineItem = array();
$priceSetId = NULL;
if (!($priceSetId = CRM_Utils_Array::value('price_set_id', $formValues))) {
CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
}
$isQuickConfig = 0;
if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
$isQuickConfig = 1;
}
$termsByType = array();
if ($priceSetId) {
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
$params['tax_amount'] = $this->_params['tax_amount'];
}
$params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
if (!empty($lineItem[$priceSetId])) {
foreach ($lineItem[$priceSetId] as &$li) {
if (!empty($li['membership_type_id'])) {
if (!empty($li['membership_num_terms'])) {
$termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
}
}
///CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if ($isQuickConfig && $submittedFinancialType) {
$li['financial_type_id'] = $submittedFinancialType;
}
}
}
}
$this->storeContactFields($formValues);
$params['contact_id'] = $this->_contactID;
$fields = array('status_id', 'source', 'is_override', 'campaign_id');
foreach ($fields as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
// fix for CRM-3724
// when is_override false ignore is_admin statuses during membership
// status calculation. similarly we did fix for import in CRM-3570.
if (empty($params['is_override'])) {
$params['exclude_is_admin'] = TRUE;
}
// process date params to mysql date format.
$dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate');
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]);
}
$memTypeNumTerms = empty($termsByType) ? CRM_Utils_Array::value('num_terms', $formValues) : NULL;
$calcDates = array();
foreach ($this->_memTypeSelected as $memType) {
if (empty($memTypeNumTerms)) {
$memTypeNumTerms = CRM_Utils_Array::value($memType, $termsByType, 1);
//.........这里部分代码省略.........
示例8: relAction
/**
* Perform create or delete action on related memberships.
*
* @param string $action
* Create or delete.
* @param array $owner
* Primary membership info (membership_id, contact_id, membership_type ...).
*/
public function relAction($action, $owner)
{
switch ($action) {
case 'delete':
$id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
$relatedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$relatedDisplayName = CRM_Contact_BAO_Contact::displayName($relatedContactId);
CRM_Member_BAO_Membership::del($id);
CRM_Core_Session::setStatus(ts('Related membership for %1 has been deleted.', array(1 => $relatedDisplayName)), ts('Membership Deleted'), 'success');
break;
case 'create':
$ids = array();
$params = array('contact_id' => CRM_Utils_Request::retrieve('rid', 'Positive', $this), 'membership_type_id' => $owner['membership_type_id'], 'owner_membership_id' => $owner['id'], 'join_date' => CRM_Utils_Date::processDate($owner['join_date'], NULL, TRUE, 'Ymd'), 'start_date' => CRM_Utils_Date::processDate($owner['start_date'], NULL, TRUE, 'Ymd'), 'end_date' => CRM_Utils_Date::processDate($owner['end_date'], NULL, TRUE, 'Ymd'), 'source' => ts('Manual Assignment of Related Membership'), 'is_test' => $owner['is_test'], 'campaign_id' => CRM_Utils_Array::value('campaign_id', $owner), 'status_id' => $owner['status_id'], 'skipStatusCal' => TRUE, 'createActivity' => TRUE);
CRM_Member_BAO_Membership::create($params, $ids);
$relatedDisplayName = CRM_Contact_BAO_Contact::displayName($params['contact_id']);
CRM_Core_Session::setStatus(ts('Related membership for %1 has been created.', array(1 => $relatedDisplayName)), ts('Membership Added'), 'success');
break;
default:
CRM_Core_Error::fatal(ts("Invalid action specified in URL"));
}
// Redirect back to membership view page for the owner, without the relAction parameters
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$owner['membership_id']}&cid={$owner['contact_id']}" . $this->addContext()));
}
示例9: createRelatedMemberships
/**
* function to create memberships for related contacts
*
* @param array $params array of key - value pairs
* @param object $membership membership object
*
* @return null|relatedMembership array of memberships if created
* @static
* @access public
*/
static function createRelatedMemberships(&$params, &$membership)
{
static $relatedContactIds = array();
// required since create method doesn't return all the
// parameters in the returned membership object
if (!$membership->find(true)) {
return;
}
require_once 'CRM/Member/PseudoConstant.php';
$deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus());
$allRelatedContacts = array();
$relatedContacts = array();
if (!is_a($membership, 'CRM_Core_Error')) {
$allRelatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membership->id, $membership->contact_id, CRM_Utils_Array::value('action', $params));
}
// check for loops. CRM-4213
// remove repeated related contacts, which already inherited membership.
$relatedContactIds[$membership->contact_id] = true;
foreach ($allRelatedContacts as $cid => $status) {
if (!CRM_Utils_Array::value($cid, $relatedContactIds)) {
$relatedContactIds[$cid] = true;
//don't create membership again for owner contact.
$nestedRelationship = false;
if ($membership->owner_membership_id) {
$nestedRelMembership = new CRM_Member_DAO_Membership();
$nestedRelMembership->id = $membership->owner_membership_id;
$nestedRelMembership->contact_id = $cid;
$nestedRelationship = $nestedRelMembership->find(true);
$nestedRelMembership->free();
}
if (!$nestedRelationship) {
$relatedContacts[$cid] = $status;
}
}
}
//lets cleanup related membership if any.
if (empty($relatedContacts)) {
require_once 'CRM/Member/BAO/Membership.php';
CRM_Member_BAO_Membership::deleteRelatedMemberships($membership->id);
} else {
// Edit the params array
unset($params['id']);
// Reminder should be sent only to the direct membership
unset($params['reminder_date']);
// unset the custom value ids
if (is_array(CRM_Utils_Array::value('custom', $params))) {
foreach ($params['custom'] as $k => $v) {
unset($params['custom'][$k]['id']);
}
}
if (!isset($params['membership_type_id'])) {
$params['membership_type_id'] = $membership->membership_type_id;
}
foreach ($relatedContacts as $contactId => $relationshipStatus) {
//use existing membership record.
$relMembership = new CRM_Member_DAO_Membership();
$relMembership->contact_id = $contactId;
$relMembership->owner_membership_id = $membership->id;
$relMemIds = array();
if ($relMembership->find(true)) {
$params['id'] = $relMemIds['membership'] = $relMembership->id;
}
$params['contact_id'] = $contactId;
$params['owner_membership_id'] = $membership->id;
// set status_id as it might have been changed for
// past relationship
$params['status_id'] = $membership->status_id;
if ($deceasedStatusId && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'is_deceased')) {
$params['status_id'] = $deceasedStatusId;
} else {
if (CRM_Utils_Array::value('action', $params) & CRM_Core_Action::UPDATE && $relationshipStatus == CRM_Contact_BAO_Relationship::PAST) {
// FIXME : While updating/ renewing the
// membership, if the relationship is PAST then
// the membership of the related contact must be
// expired.
// For that, getting Membership Status for which
// is_current_member is 0. It works for the
// generated data as there is only one membership
// status having is_current_member = 0.
// But this wont work exactly if there will be
// more than one status having is_current_member = 0.
require_once 'CRM/Member/DAO/MembershipStatus.php';
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
$membershipStatus->is_current_member = 0;
if ($membershipStatus->find(true)) {
$params['status_id'] = $membershipStatus->id;
}
}
}
//don't calculate status again in create( );
//.........这里部分代码省略.........
示例10: crm_update_contact_membership
/**
* Update an existing contact membership
*
* This api is used for updating an existing contact membership.
* Required parrmeters : id of a membership
*
* @param Array $params an associative array of name/value property values of civicrm_membership
*
* @return array of updated membership property values
* @access public
*/
function crm_update_contact_membership($params)
{
_crm_initialize();
if (!is_array($params)) {
return _crm_error('Params is not an array');
}
if (!isset($params['id'])) {
return _crm_error('Required parameter missing');
}
$changeFields = array('membership_start_date' => 'start_date', 'membership_end_date' => 'end_date', 'membership_source' => 'source');
foreach ($changeFields as $field => $requiredField) {
if (array_key_exists($field, $params)) {
$params[$requiredField] = $params[$field];
unset($params[$field]);
}
}
require_once 'CRM/Member/BAO/Membership.php';
$membershipBAO =& new CRM_Member_BAO_Membership();
$membershipBAO->id = $params['id'];
$membershipBAO->find(true);
$oldStatusID = $membershipBAO->status_id;
$membershipBAO->copyValues($params);
$datefields = array('start_date', 'end_date', 'join_date', 'reminder_date');
//fix the dates
foreach ($datefields as $value) {
$membershipBAO->{$value} = CRM_Utils_Date::customFormat($membershipBAO->{$value}, '%Y%m%d');
// Handle resetting date to 'null' (which is converted to 00000 by customFormat)
if ($membershipBAO->{$value} == '00000') {
$membershipBAO->{$value} = 'null';
}
$params[$value] = $membershipBAO->{$value};
}
$membershipBAO->save();
require_once "CRM/Core/Action.php";
// Check and add membership for related contacts
$relatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membershipBAO->id, (int) $membershipBAO->contact_id, CRM_Core_Action::UPDATE);
//delete all the related membership records before creating
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipBAO->id);
$params['membership_type_id'] = $membershipBAO->membership_type_id;
foreach ($relatedContacts as $contactId => $relationshipStatus) {
if ($relationshipStatus & CRM_Contact_BAO_Relationship::CURRENT) {
$params['contact_id'] = $contactId;
$params['owner_membership_id'] = $membershipBAO->id;
unset($params['id']);
CRM_Member_BAO_Membership::create($params, CRM_Core_DAO::$_nullArray);
}
}
// Create activity history record.
require_once "CRM/Member/PseudoConstant.php";
$membershipType = CRM_Member_PseudoConstant::membershipType($membershipBAO->membership_type_id);
if (!$membershipType) {
$membershipType = ts('Membership');
}
$activitySummary = $membershipType;
if ($membershipBAO->source != 'null') {
$activitySummary .= " - {$membershipBAO->source}";
}
if ($membershipBAO->owner_membership_id) {
$cid = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipBAO->owner_membership_id, 'contact_id');
$displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name');
$activitySummary .= " (by {$displayName})";
}
// create activity record only if there is change in the statusID (CRM-2521).
if ($oldStatusID != $membershipBAO->status_id) {
$activityParams = array('source_contact_id' => $membershipBAO->contact_id, 'source_record_id' => $membershipBAO->id, 'activity_type_id' => array_search('Membership Signup', CRM_Core_PseudoConstant::activityType()), 'subject' => $activitySummary, 'activity_date_time' => $params['join_date'], 'is_test' => $membershipBAO->is_test, 'status_id' => 2);
require_once 'api/v2/Activity.php';
if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) {
return false;
}
}
$membership = array();
_crm_object_to_array($membershipBAO, $membership);
$membershipBAO->free();
return $membership;
}
示例11: relatedMemberships
//.........这里部分代码省略.........
$targetContact = array();
if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
$contact = $contactId;
$targetContact = CRM_Utils_Array::value('contact_check', $params);
} else {
if ($action & CRM_Core_Action::UPDATE) {
$contact = $ids['contact'];
$targetContact = array($ids['contactTarget'] => 1);
}
}
// Build the 'values' array for
// 1. ContactA
// 2. ContactB
// This will allow us to check if either of the contacts in
// relationship have active memberships.
$values = array();
// 1. ContactA
$values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
// 2. ContactB
if (!empty($targetContact)) {
foreach ($targetContact as $cid => $donCare) {
$values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
$relTypeParams = array('id' => $relTypeId);
$relTypeValues = array();
require_once 'CRM/Contact/BAO/RelationshipType.php';
CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
$values[$cid]['relationshipTypeDirection'] = '_a_b';
} else {
$values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
}
}
}
// Now get the active memberships for all the contacts.
// If contact have any valid membership(s), then add it to
// 'values' array.
foreach ($values as $cid => $subValues) {
$memParams = array('contact_id' => $cid);
$memberships = array();
require_once 'CRM/Member/BAO/Membership.php';
CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
if (empty($memberships)) {
continue;
}
$values[$cid]['memberships'] = $memberships;
}
// done with 'values' array.
// Finally add / edit / delete memberships for the related contacts
foreach ($values as $cid => $details) {
if (!array_key_exists('memberships', $details)) {
continue;
}
require_once 'CRM/Member/BAO/MembershipType.php';
foreach ($details['memberships'] as $membershipId => $membershipValues) {
if ($action & CRM_Core_Action::DELETE) {
// delete memberships of the related contacts.
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId);
continue;
}
if ($action & CRM_Core_Action::UPDATE && $status & self::PAST && $membershipValues['owner_membership_id']) {
// If relationship is PAST and action is UPDATE
// then delete the RELATED membership
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']);
continue;
}
// add / edit the memberships for related
// contacts.
// Get the Membership Type Details.
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipValues['membership_type_id']);
if ("{$details['relationshipTypeId']}{$details['relationshipTypeDirection']}" == CRM_Utils_Array::value('relationship_type_id', $membershipType) . "_" . CRM_Utils_Array::value('relationship_direction', $membershipType)) {
// Check if relationship being created/updated is
// similar to that of membership type's
// relationship.
$membershipValues['owner_membership_id'] = $membershipId;
unset($membershipValues['id']);
unset($membershipValues['membership_contact_id']);
unset($membershipValues['contact_id']);
unset($membershipValues['membership_id']);
foreach ($details['relatedContacts'] as $relatedContactId => $donCare) {
$membershipValues['contact_id'] = $relatedContactId;
if ($action & CRM_Core_Action::UPDATE) {
//delete the membership record for related
//contact before creating new membership record.
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId);
}
CRM_Member_BAO_Membership::create($membershipValues, CRM_Core_DAO::$_nullArray);
}
} else {
if ($action & CRM_Core_Action::UPDATE) {
// if action is update and updated relationship do
// not match with the existing
// membership=>relationship then we need to
// delete the membership record created for
// previous relationship.
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $ids['contactTarget']);
}
}
}
}
}
示例12: postProcess
//.........这里部分代码省略.........
//insert contribution type name in receipt.
$formValues['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $formValues['contribution_type_id']);
}
if ($this->_mode) {
$params['total_amount'] = $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $params['membership_type_id'], 'minimum_fee');
$params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $params['membership_type_id'], 'contribution_type_id');
require_once 'CRM/Core/BAO/PaymentProcessor.php';
$this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode);
require_once "CRM/Contact/BAO/Contact.php";
$now = date('YmdHis');
$fields = array();
// set email for primary location.
$fields["email-Primary"] = 1;
$formValues["email-5"] = $formValues["email-Primary"] = $this->_contributorEmail;
$params['register_date'] = $now;
// now set the values for the billing location.
foreach ($this->_fields as $name => $dontCare) {
$fields[$name] = 1;
}
// also add location name to the array
$formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
$formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
$fields["address_name-{$this->_bltID}"] = 1;
$fields["email-{$this->_bltID}"] = 1;
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
$nameFields = array('first_name', 'middle_name', 'last_name');
foreach ($nameFields as $name) {
$fields[$name] = 1;
if (array_key_exists("billing_{$name}", $formValues)) {
$formValues[$name] = $formValues["billing_{$name}"];
$formValues['preserveDBName'] = true;
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contactID, null, null, $ctype);
// add all the additioanl payment params we need
$this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
$this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
$this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
$this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $params['total_amount'];
$this->_params['currencyID'] = $config->defaultCurrency;
$this->_params['payment_action'] = 'Sale';
$this->_params['invoiceID'] = md5(uniqid(rand(), true));
// at this point we've created a contact and stored its address etc
// all the payment processors expect the name and address to be in the
// so we copy stuff over to first_name etc.
$paymentParams = $this->_params;
if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
$paymentParams['email'] = $this->_contributorEmail;
}
require_once 'CRM/Core/Payment/Form.php';
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
$payment =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $this->_paymentProcessor, $this);
$result =& $payment->doDirectPayment($paymentParams);
if (is_a($result, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=add&cid={$this->_contactID}&context=&mode={$this->_mode}"));
}
if ($result) {
$this->_params = array_merge($this->_params, $result);
}
$params['contribution_status_id'] = 1;
$params['receive_date'] = $now;
$params['invoice_id'] = $this->_params['invoiceID'];
$params['contribution_source'] = ts('Online Membership: Admin Interface');
示例13: testGetRenewalDatesForMembershipType
function testGetRenewalDatesForMembershipType()
{
require_once 'CRM/Member/BAO/Membership.php';
$ids = array('memberOfContact' => $this->_orgContactID);
$params = array('name' => 'General', 'description' => null, 'minimum_fee' => 100, 'duration_unit' => 'year', 'period_type' => 'rolling', 'duration_interval' => 1, 'contribution_type_id' => $this->_contributionTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1);
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
$params = array('contact_id' => $this->_indiviContactID, 'membership_type_id' => $membershipType->id, 'join_date' => '2006-01-21', 'start_date' => '2006-01-21', 'end_date' => '2006-12-21', 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID);
$ids = array();
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$membershipRenewDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id);
$this->assertEquals($membershipRenewDates['start_date'], '20060121', 'Verify membership renewal start date.');
$this->assertEquals($membershipRenewDates['end_date'], '20071221', 'Verify membership renewal end date.');
}
示例14: testGet
/**
* Test civicrm_membershipcontributionlink_get - success expected.
*/
public function testGet()
{
$contactId = Contact::createIndividual();
$params = array('contact_id' => $contactId, 'currency' => 'USD', 'contribution_type_id' => $this->_contributionTypeID, 'contribution_status_id' => 1, 'contribution_page_id' => null, 'payment_instrument_id' => 1, 'id' => null, 'total_amount' => 200.0);
require_once 'CRM/Contribute/BAO/Contribution.php';
$contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
$params = array('contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID);
$ids = array();
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$params = array('contribution_id' => $contribution->id, 'membership_id' => $membership->id);
$Create = civicrm_membershipcontributionlink_create($params);
$GetParams = civicrm_membershipcontributionlink_get(&$params);
$this->assertEquals($GetParams[$Create['id']]['membership_id'], $membership->id, 'Check Membership Id');
$this->assertEquals($GetParams[$Create['id']]['contribution_id'], $contribution->id, 'Check Contribution Id');
}
示例15: testresetmodifiedId
/**
* Test resetmodified()
*/
function testresetmodifiedId()
{
$contactId = Contact::createIndividual();
$params = array('contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => '2009-01-21', 'start_date' => '2009-01-21', 'end_date' => '2009-12-21', 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_mebershipStatusID);
$ids = array();
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$contactId2 = Contact::createIndividual();
$this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactId2, 'modified_id', 'modified_id', 'Database check for NULL modified id.');
}