当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Member_BAO_Membership::add方法代码示例

本文整理汇总了PHP中CRM_Member_BAO_Membership::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_Membership::add方法的具体用法?PHP CRM_Member_BAO_Membership::add怎么用?PHP CRM_Member_BAO_Membership::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Member_BAO_Membership的用法示例。


在下文中一共展示了CRM_Member_BAO_Membership::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: relatedMemberships


//.........这里部分代码省略.........
         }
         $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']);
                 unset($membershipValues['contact_id']);
                 unset($membershipValues['membership_id']);
                 foreach ($details['relatedContacts'] as $relatedContactId => $donCare) {
                     $membershipValues['contact_id'] = $relatedContactId;
                     if ($deceasedStatusId && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $relatedContactId, 'is_deceased')) {
                         $membershipValues['status_id'] = $deceasedStatusId;
                         $membershipValues['skipStatusCal'] = TRUE;
                     }
                     foreach (array('join_date', 'start_date', 'end_date') as $dateField) {
                         if (!empty($membershipValues[$dateField])) {
                             $membershipValues[$dateField] = CRM_Utils_Date::processDate($membershipValues[$dateField]);
                         }
                     }
                     if ($action & CRM_Core_Action::UPDATE) {
                         //if updated relationship is already related to contact don't delete existing inherited membership
                         if (in_array($relTypeId, $relTypeIds) && !empty($values[$relatedContactId]['memberships']) && !empty($ownerMemIds) && in_array($membershipValues['owner_membership_id'], $ownerMemIds[$relatedContactId])) {
                             continue;
                         }
                         //delete the membership record for related
                         //contact before creating new membership record.
                         CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId);
                     }
                     // check whether we have some related memberships still available
                     $query = "\nSELECT count(*)\n  FROM civicrm_membership\n    LEFT JOIN civicrm_membership_status ON (civicrm_membership_status.id = civicrm_membership.status_id)\n WHERE membership_type_id = {$membershipValues['membership_type_id']} AND owner_membership_id = {$membershipValues['owner_membership_id']}\n    AND is_current_member = 1";
                     $result = CRM_Core_DAO::singleValueQuery($query);
                     if ($result < CRM_Utils_Array::value('max_related', $membershipValues, PHP_INT_MAX)) {
                         CRM_Member_BAO_Membership::create($membershipValues, CRM_Core_DAO::$_nullArray);
                     }
                 }
             } elseif ($action & CRM_Core_Action::UPDATE) {
                 // if action is update and updated relationship do
                 // not match with the existing
                 // membership=>relationship then we need to
                 // change the status of the membership record to expired for
                 // previous relationship -- CRM-12078.
                 // CRM-16087 we need to pass ownerMembershipId to isRelatedMembershipExpired function
                 if (empty($params['relationship_ids']) && !empty($params['id'])) {
                     $relIds = array($params['id']);
                 } else {
                     $relIds = CRM_Utils_Array::value('relationship_ids', $params);
                 }
                 if (self::isRelatedMembershipExpired($relTypeIds, $contactId, $mainRelatedContactId, $relTypeId, $relIds) && !empty($membershipValues['owner_membership_id']) && !empty($values[$mainRelatedContactId]['memberships'][$membershipValues['owner_membership_id']])) {
                     $membershipValues['status_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', 'Expired', 'id', 'label');
                     $type = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $membershipValues['membership_type_id'], 'name', 'id');
                     CRM_Member_BAO_Membership::add($membershipValues);
                     CRM_Core_Session::setStatus(ts("Inherited membership {$type} status was changed to Expired due to the change in relationship type."), ts('Record Updated'), 'alert');
                 }
             }
         }
     }
 }
开发者ID:scardinius,项目名称:civicrm-core,代码行数:101,代码来源:Relationship.php

示例2: postProcess

 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     if (isset($params['field'])) {
         $customFields = array();
         foreach ($params['field'] as $key => $value) {
             $ids['membership'] = $key;
             if ($value['membership_source']) {
                 $value['source'] = $value['membership_source'];
             }
             unset($value['membership_source']);
             //Get the membership status
             $membership =& new CRM_Member_BAO_Membership();
             $membership->id = CRM_Utils_Array::value('membership', $ids);
             $membership->find(true);
             $membership->free();
             $value['status_id'] = $membership->status_id;
             if (empty($customFields)) {
                 // membership type custom data
                 $customFields = CRM_Core_BAO_CustomField::getFields('Membership', false, false, $membership->membership_type_id);
                 $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', $membership->membership_type_id);
             $membership = CRM_Member_BAO_Membership::add($value, $ids);
             // add custom field values
             if (CRM_Utils_Array::value('custom', $value) && is_array($value['custom'])) {
                 require_once 'CRM/Core/BAO/CustomValueTable.php';
                 CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_membership', $membership->id);
             }
         }
         CRM_Core_Session::setStatus("Your updates have been saved.");
     } else {
         CRM_Core_Session::setStatus("No updates have been saved.");
     }
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:42,代码来源:Batch.php

示例3: postProcess

 /**
  * Process the form after the input has been submitted and validated.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $dates = array('join_date', 'membership_start_date', 'membership_end_date');
     if (isset($params['field'])) {
         $customFields = array();
         foreach ($params['field'] as $key => $value) {
             $ids['membership'] = $key;
             if (!empty($value['membership_source'])) {
                 $value['source'] = $value['membership_source'];
             }
             if (!empty($value['membership_type'])) {
                 $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
             }
             unset($value['membership_source']);
             unset($value['membership_type']);
             //Get the membership status
             $value['status_id'] = CRM_Utils_Array::value('membership_status', $value) ? $value['membership_status'] : CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $key, 'status_id');
             unset($value['membership_status']);
             foreach ($dates as $val) {
                 if (isset($value[$val])) {
                     $value[$val] = CRM_Utils_Date::processDate($value[$val]);
                 }
             }
             if (empty($customFields)) {
                 if (empty($value['membership_type_id'])) {
                     $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $key, 'membership_type_id');
                 }
                 // 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], $key, 'Membership', $membershipTypeId);
             $membership = CRM_Member_BAO_Membership::add($value, $ids);
             // add custom field values
             if (!empty($value['custom']) && is_array($value['custom'])) {
                 CRM_Core_BAO_CustomValueTable::store($value['custom'], 'civicrm_membership', $membership->id);
             }
         }
         CRM_Core_Session::setStatus(ts("Your updates have been saved."), ts('Saved'), 'success');
     } else {
         CRM_Core_Session::setStatus(ts("No updates have been saved."), ts('Not Saved'), 'alert');
     }
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:51,代码来源:Batch.php

示例4: moveRecurringRecord

 public function moveRecurringRecord($submittedValues)
 {
     // Move recurring record to another contact
     if (!empty($submittedValues['contact_id']) && $submittedValues['contact_id'] != $this->_contactID) {
         $selected_cid = $submittedValues['contact_id'];
         // FIXME: Not getting the below value in $submittedValues
         // So taking the value from $_POST
         if (isset($_POST['membership_record'])) {
             $membership_record = $_POST['membership_record'];
         }
         // Update contact id in civicrm_contribution_recur table
         $recurring = new CRM_Contribute_BAO_ContributionRecur();
         $recurring->id = $this->_id;
         if ($recurring->find(TRUE)) {
             $recurParams = (array) $recurring;
             $recurParams['contact_id'] = $selected_cid;
             CRM_Contribute_BAO_ContributionRecur::create($recurParams);
         }
         // Update contact id in civicrm_contribution table, if 'Move Existing Contributions?' is ticked
         if (isset($submittedValues['move_existing_contributions']) && $submittedValues['move_existing_contributions'] == 1) {
             $contribution = new CRM_Contribute_DAO_Contribution();
             $contribution->contribution_recur_id = $this->_id;
             $contribution->find();
             while ($contribution->fetch()) {
                 $contributionParams = (array) $contribution;
                 $contributionParams['contact_id'] = $selected_cid;
                 // Update contact_id of contributions
                 // related to the recurring contribution
                 CRM_Contribute_BAO_Contribution::create($contributionParams);
             }
         }
     }
     if (!empty($membership_record)) {
         // Remove the contribution_recur_id from existing membership
         if (!empty($this->_membershipID)) {
             $membership = new CRM_Member_DAO_Membership();
             $membership->id = $this->_membershipID;
             if ($membership->find(TRUE)) {
                 $membershipParams = (array) $membership;
                 $membershipParams['contribution_recur_id'] = 'NULL';
                 CRM_Member_BAO_Membership::add($membershipParams);
             }
         }
         // Update contribution_recur_id to the new membership
         $membership = new CRM_Member_DAO_Membership();
         $membership->id = $membership_record;
         if ($membership->find(TRUE)) {
             $membershipParams = (array) $membership;
             $membershipParams['contribution_recur_id'] = $this->_id;
             CRM_Member_BAO_Membership::add($membershipParams);
         }
     }
 }
开发者ID:Kajakaran,项目名称:uk.co.vedaconsulting.offlinerecurringcontributions,代码行数:53,代码来源:ContributionRecur.php


注:本文中的CRM_Member_BAO_Membership::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。