本文整理汇总了PHP中CRM_Member_BAO_Membership::deleteRelatedMemberships方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_Membership::deleteRelatedMemberships方法的具体用法?PHP CRM_Member_BAO_Membership::deleteRelatedMemberships怎么用?PHP CRM_Member_BAO_Membership::deleteRelatedMemberships使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Member_BAO_Membership
的用法示例。
在下文中一共展示了CRM_Member_BAO_Membership::deleteRelatedMemberships方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_membership_delete
/**
* Deletes an existing contact membership
*
* This API is used for deleting a contact membership
*
* @param Int $membershipID Id of the contact membership to be deleted
*
* @return null if successfull, object of CRM_Core_Error otherwise
* @access public
*/
function civicrm_membership_delete(&$membershipID)
{
_civicrm_initialize();
if (empty($membershipID)) {
return civicrm_create_error('Membership ID cannot be empty.');
}
require_once 'CRM/Member/BAO/Membership.php';
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipID);
$membership = new CRM_Member_BAO_Membership();
$result = $membership->deleteMembership($membershipID);
return $result ? civicrm_create_success() : civicrm_create_error('Error while deleting Membership');
}
示例2: civicrm_api3_membership_delete
/**
* Deletes an existing contact membership
*
* This API is used for deleting a contact membership
*
* @param $params array array holding id - Id of the contact membership to be deleted
*
* @return array api result
* {@getfields membership_delete}
* @access public
*/
function civicrm_api3_membership_delete($params)
{
// membershipID should be numeric
// this check should be done @ wrapper level
if (!is_numeric($params['id'])) {
return civicrm_api3_create_error('Input parameter should be numeric');
}
CRM_Member_BAO_Membership::deleteRelatedMemberships($params['id']);
$membership = new CRM_Member_BAO_Membership();
$result = $membership->deleteMembership($params['id']);
return $result ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting Membership');
}
示例3: relatedMemberships
//.........这里部分代码省略.........
if (empty($memberships)) {
continue;
}
//get ownerMembershipIds for related Membership
//this is to handle memberships being deleted and recreated
if (!empty($memberships['owner_membership_ids'])) {
$ownerMemIds[$cid] = $memberships['owner_membership_ids'];
unset($memberships['owner_membership_ids']);
}
$values[$cid]['memberships'] = $memberships;
}
$deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus());
// 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;
}
$relatedContacts = array_keys(CRM_Utils_Array::value('relatedContacts', $details, array()));
$mainRelatedContactId = reset($relatedContacts);
foreach ($details['memberships'] as $membershipId => $membershipValues) {
$relTypeIds = array();
if ($action & CRM_Core_Action::DELETE) {
// Delete memberships of the related contacts only if relationship type exists for membership type
$query = "\nSELECT relationship_type_id, relationship_direction\n FROM civicrm_membership_type\n WHERE id = {$membershipValues['membership_type_id']}";
$dao = CRM_Core_DAO::executeQuery($query);
$relTypeDirs = array();
while ($dao->fetch()) {
$relTypeId = $dao->relationship_type_id;
$relDirection = $dao->relationship_direction;
}
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $relTypeId);
if (in_array($values[$cid]['relationshipTypeId'], $relTypeIds) && !empty($membershipValues['owner_membership_id']) && !empty($values[$mainRelatedContactId]['memberships'][$membershipValues['owner_membership_id']])) {
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']);
}
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']);
// Check if contact's relationship type exists in membership type
$relTypeDirs = array();
if (!empty($membershipType['relationship_type_id'])) {
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
}
if (!empty($membershipType['relationship_direction'])) {
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
}
foreach ($relTypeIds as $key => $value) {
$relTypeDirs[] = $value . '_' . $relDirections[$key];
}
$relTypeDir = $details['relationshipTypeId'] . $details['relationshipTypeDirection'];
if (in_array($relTypeDir, $relTypeDirs)) {
// 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']);
示例4: 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( );
//.........这里部分代码省略.........
示例5: postProcess
/**
* Function to process the form
*
* @access public
*
* @return None
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Member_BAO_Membership::deleteRelatedMemberships($this->_id);
CRM_Member_BAO_Membership::deleteMembership($this->_id);
return;
}
$config = CRM_Core_Config::singleton();
// get the submitted form values.
$this->_params = $formValues = $this->controller->exportValues($this->_name);
$params = $ids = array();
$membershipTypeValues = array();
foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType]['membership_type_id'] = $memType;
}
//take the required membership recur values.
if ($this->_mode && CRM_Utils_Array::value('auto_renew', $this->_params)) {
$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++;
}
// unset send-receipt option, since receipt will be sent when ipn is received.
unset($this->_params['send_receipt'], $formValues['send_receipt']);
}
// 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);
}
if ($priceSetId) {
CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
$params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
}
$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 (!CRM_Utils_Array::value('is_override', $params)) {
$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]);
}
$dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
$calcDates = array();
foreach ($this->_memTypeSelected as $memType) {
$calcDates[$memType] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate);
}
foreach ($calcDates as $memType => $calcDate) {
foreach ($dates as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $formValues);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}
$membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date);
//$params[$d] = CRM_Utils_Date::processDate( $date );
}
}
if ($this->_id) {
$ids['membership'] = $params['id'] = $this->_id;
}
$session = CRM_Core_Session::singleton();
$ids['userId'] = $session->get('userID');
// membership type custom data
foreach ($this->_memTypeSelected as $memType) {
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $memType);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
$membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
}
foreach ($this->_memTypeSelected as $memType) {
$membershipTypes[$memType] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType);
}
$membershipType = implode(', ', $membershipTypes);
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
//.........这里部分代码省略.........
示例6: relatedMemberships
//.........这里部分代码省略.........
// 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();
CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
if (empty($memberships)) {
continue;
}
$values[$cid]['memberships'] = $memberships;
}
$deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus());
// 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;
}
$mainRelatedContactId = key(CRM_Utils_Array::value('relatedContacts', $details, array()));
foreach ($details['memberships'] as $membershipId => $membershipValues) {
$relTypeIds = array();
if ($action & CRM_Core_Action::DELETE) {
// Delete memberships of the related contacts only if relationship type exists for membership type
$query = "\nSELECT relationship_type_id, relationship_direction\n FROM civicrm_membership_type\n WHERE id = {$membershipValues['membership_type_id']}";
$dao = CRM_Core_DAO::executeQuery($query);
$relTypeDirs = array();
while ($dao->fetch()) {
$relTypeId = $dao->relationship_type_id;
$relDirection = $dao->relationship_direction;
}
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $relTypeId);
if (in_array($values[$cid]['relationshipTypeId'], $relTypeIds)) {
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $mainRelatedContactId);
}
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']);
// Check if contact's relationship type exists in membership type
$relTypeDirs = array();
if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
}
if (CRM_Utils_Array::value('relationship_direction', $membershipType)) {
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
}
foreach ($relTypeIds as $key => $value) {
$relTypeDirs[] = $value . '_' . $relDirections[$key];
}
$relTypeDir = $details['relationshipTypeId'] . $details['relationshipTypeDirection'];
if (in_array($relTypeDir, $relTypeDirs)) {
// 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']);
示例7: testdeleteRelatedMemberships
/**
* Delete related memberships.
*/
public function testdeleteRelatedMemberships()
{
$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->_membershipStatusID);
$ids = array();
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.');
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId);
$this->membershipDelete($membershipId);
Contact::delete($contactId);
}
示例8: 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;
}
$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)) {
$relatedContacts[$cid] = $status;
$relatedContactIds[$cid] = true;
}
}
if (!empty($relatedContacts)) {
// delete all the related membership records before creating
CRM_Member_BAO_Membership::deleteRelatedMemberships($membership->id);
// 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) {
$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 (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';
$membership = new CRM_Member_DAO_MembershipStatus();
$membership->is_current_member = 0;
if ($membership->find(true)) {
$params['status_id'] = $membership->id;
}
}
// we should not created contribution record for related contacts, CRM-3371
unset($params['contribution_status_id']);
CRM_Member_BAO_Membership::create($params, CRM_Core_DAO::$_nullArray);
}
}
}
示例9: crm_delete_membership
/**
* Deletes an existing contact membership
*
* This API is used for deleting a contact membership
*
* @param Int $membershipID Id of the contact membership to be deleted
*
* @return null if successfull, object of CRM_Core_Error otherwise
* @access public
*/
function crm_delete_membership($membershipID)
{
_crm_initialize();
if (empty($membershipID)) {
return _crm_error('Invalid value for membershipID');
}
require_once 'CRM/Member/BAO/Membership.php';
CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipID);
$membership = new CRM_Member_BAO_Membership();
$result = $membership->deleteMembership($membershipID);
return $result ? null : _crm_error('Error while deleting Membership');
}
示例10: relatedMemberships
/**
* Function to create / update / delete membership for related contacts.
*
* This function will create/update/delete membership for related
* contact based on 1) contact have active membership 2) that
* membership is is extedned by the same relationship type to that
* of the existing relationship.
*
* @param $contactId Int contact id
* @param $params array array of values submitted by POST
* @param $ids array array of ids
* @param $action which action called this function
*
* @static
*
*/
static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = true)
{
// Check the end date and set the status of the relationship
// accrodingly.
$status = self::CURRENT;
if (!empty($params['end_date'])) {
$endDate = CRM_Utils_Date::setDateDefaults($params['end_date'], null, 'Ymd');
$today = date('Ymd');
if ($today > $endDate) {
$status = self::PAST;
}
}
if ($action & CRM_Core_Action::ADD && $status & self::PAST) {
// if relationship is PAST and action is ADD, no qustion
// of creating RELATED membership and return back to
// calling method
return;
}
$rel = explode("_", $params['relationship_type_id']);
$relTypeId = $rel[0];
$relDirection = "_{$rel[1]}_{$rel[2]}";
$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']);
//.........这里部分代码省略.........
示例11: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
require_once 'CRM/Member/BAO/Membership.php';
require_once 'CRM/Member/BAO/MembershipType.php';
require_once 'CRM/Member/BAO/MembershipStatus.php';
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Member_BAO_Membership::deleteRelatedMemberships($this->_id);
CRM_Member_BAO_Membership::deleteMembership($this->_id);
return;
}
$config =& CRM_Core_Config::singleton();
// get the submitted form values.
$this->_params = $formValues = $this->controller->exportValues($this->_name);
$params = array();
$ids = array();
// set the contact, when contact is selected
if (CRM_Utils_Array::value('contact_select_id', $formValues)) {
$this->_contactID = CRM_Utils_Array::value('contact_select_id', $formValues);
}
$params['contact_id'] = $this->_contactID;
// we need to retrieve email address
if ($this->_context == 'standalone' && CRM_Utils_Array::value('send_receipt', $formValues)) {
require_once 'CRM/Contact/BAO/Contact/Location.php';
list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
}
$fields = array('status_id', 'source', 'is_override');
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 (!CRM_Utils_Array::value('is_override', $params)) {
$params['exclude_is_admin'] = true;
}
$params['membership_type_id'] = $formValues['membership_type_id'][1];
$joinDate = CRM_Utils_Date::processDate($formValues['join_date']);
$startDate = CRM_Utils_Date::processDate($formValues['start_date']);
$endDate = CRM_Utils_Date::processDate($formValues['end_date']);
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params['membership_type_id'], $joinDate, $startDate, $endDate);
$dates = array('join_date', 'start_date', 'end_date', 'reminder_date', 'receive_date');
$currentTime = getDate();
foreach ($dates as $d) {
if (isset($formValues[$d]) && !CRM_Utils_System::isNull($formValues[$d])) {
$params[$d] = CRM_Utils_Date::processDate($formValues[$d]);
} else {
if (isset($calcDates[$d])) {
$params[$d] = CRM_Utils_Date::processDate($calcDates[$d]);
}
}
}
if ($this->_id) {
$ids['membership'] = $params['id'] = $this->_id;
}
$session = CRM_Core_Session::singleton();
$ids['userId'] = $session->get('userID');
// membership type custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', false, false, CRM_Utils_Array::value('membership_type_id', $params));
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', false, false, null, null, true));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
require_once 'CRM/Contact/BAO/Contact/Location.php';
list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
if (CRM_Utils_Array::value('record_contribution', $formValues)) {
$recordContribution = array('total_amount', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'check_number');
foreach ($recordContribution as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
$membershipType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1]);
if (!$this->_onlinePendingContributionId) {
$params['contribution_source'] = "{$membershipType} Membership: Offline membership signup (by {$userName})";
}
if ($formValues['send_receipt']) {
$params['receipt_date'] = $params['receive_date'];
}
//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;
}
//.........这里部分代码省略.........