X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FMember%2FBAO%2FMembership.php;h=5ba8d740fc1dea05300ad38f32a019a7cc9a7938;hb=50710ed22c213a7ffa8f6c83ac31e5f983b165f3;hp=0e10c56b90fea64d943c8b8d527ae8a7d2cd90f7;hpb=98febc67fca1349bf4b086c8fa5d3152c4d98777;p=civicrm-core.git diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 0e10c56b90..5ba8d740fc 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1,7 +1,7 @@ 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 @@ -142,40 +138,32 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { if (CRM_Utils_Array::value('membership', $ids)) { if ($membership->status_id != $oldStatus) { - $allStatus = CRM_Member_PseudoConstant::membershipStatus(); + $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get'); $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), + 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Membership Status'), '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); + civicrm_api3('activity', 'create', $activityParam); } if (isset($membership->membership_type_id) && $membership->membership_type_id != $oldType) { - $membershipTypes = CRM_Member_PseudoConstant::membershipType(); + $membershipTypes = CRM_Member_BAO_Membership::buildOptions('membership_type_id', 'get'); $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), + 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Membership Type'), '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); + civicrm_api3('activity', 'create', $activityParam); } CRM_Utils_Hook::post('edit', 'Membership', $membership->id, $membership); } @@ -248,7 +236,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { ) { $dates = array('start_date', 'end_date', 'join_date'); foreach ($dates as $date) { - $$date = CRM_Utils_Date::processDate(CRM_Utils_Array::value($date, $params), NULL, TRUE, 'Ymd'); + $$date = $params[$date] = CRM_Utils_Date::processDate(CRM_Utils_Array::value($date, $params), NULL, TRUE, 'Ymd'); } //fix for CRM-3570, during import exclude the statuses those having is_admin = 1 @@ -261,7 +249,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { $excludeIsAdmin = TRUE; } - $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($start_date, $end_date, $join_date, + $calcStatus = $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($start_date, $end_date, $join_date, 'today', $excludeIsAdmin ); if (empty($calcStatus)) { @@ -275,7 +263,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { 'legacy_redirect_path' => 'civicrm/contact/view', 'legacy_redirect_query' => "reset=1&force=1&cid={$params['contact_id']}&selectedChild=member", ); - throw new CRM_Core_Exception(ts('The membership cannot be saved.'), 0, $errorParams); + throw new CRM_Core_Exception(ts('The membership cannot be saved because the status cannot be calculated.'), 0, $errorParams); } $params['status_id'] = $calcStatus['id']; } @@ -322,7 +310,8 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { //record contribution for this membership if (CRM_Utils_Array::value('contribution_status_id', $params) && !CRM_Utils_Array::value('relate_contribution_id', $params)) { - $params['contribution'] = self::recordMembershipContribution( $params, $ids, $membership->id ); + $memInfo = array_merge($params, array('membership_id' => $membership->id)); + $params['contribution'] = self::recordMembershipContribution($memInfo, $ids); } //insert payment record for this membership @@ -579,9 +568,9 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty static function del($membershipId) { //delete related first and then delete parent. self::deleteRelatedMemberships($membershipId); - return self::deleteMembership($membershipId); + return self::deleteMembership($membershipId); } - + /** * Function to delete membership. * @@ -721,23 +710,16 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty */ static function buildMembershipBlock(&$form, $pageID, + $cid, $formItems = FALSE, $selectedMembershipTypeID = NULL, $thankPage = FALSE, - $isTest = NULL, - $memberContactId = NULL + $isTest = NULL ) { $separateMembershipPayment = FALSE; if ($form->_membershipBlock) { $form->_currentMemberships = array(); - if (!$memberContactId) { - $session = CRM_Core_Session::singleton(); - $cid = $session->get('userID'); - } - else { - $cid = $memberContactId; - } $membershipBlock = $form->_membershipBlock; $membershipTypeIds = $membershipTypes = $radio = array(); @@ -1463,7 +1445,7 @@ AND civicrm_membership.is_test = %2"; 'legacy_redirect_path' => 'civicrm/contribute/transact', 'legacy_redirect_query' => "_qf_Main_display=true&qfKey={$form->_params['qfKey']}", ); - throw new CiviCRM_Exception($message, 0, $errorParams); + throw new CRM_Core_Exception($message, 0, $errorParams); } // CRM-7851 @@ -1505,6 +1487,10 @@ AND civicrm_membership.is_test = %2"; } /** + * @todo - this form method needs to have the interaction with the form layer removed from it + * as a BAO function. Note that the api now supports membership renewals & it is not clear this function does anything + * not done by the membership.create api (with a lot less unit tests) + * * This method will renew / create the membership depending on * whether the given contact has a membership or not. And will add * the modified dates for membership and in the log table. @@ -1544,6 +1530,8 @@ AND civicrm_membership.is_test = %2"; // check is it pending. - CRM-4555 $pending = FALSE; + //@todo this is a BAO function & should not inspect the form - the form should do this + // & pass required params to the BAO if (CRM_Utils_Array::value('minimum_fee', $membershipTypeDetails) > 0.0) { if (((isset($form->_contributeMode) && $form->_contributeMode == 'notify') || CRM_Utils_Array::value('is_pay_later', $form->_params) || @@ -2476,6 +2464,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND $allTypes = CRM_Member_PseudoConstant::membershipType(); $contribStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); + // get only memberships with active membership types $query = " SELECT civicrm_membership.id as membership_id, civicrm_membership.is_override as is_override, @@ -2491,6 +2480,8 @@ SELECT civicrm_membership.id as membership_id, civicrm_membership.contribution_recur_id as recur_id FROM civicrm_membership INNER JOIN civicrm_contact ON ( civicrm_membership.contact_id = civicrm_contact.id ) +INNER JOIN civicrm_membership_type ON + (civicrm_membership.membership_type_id = civicrm_membership_type.id AND civicrm_membership_type.is_active = 1) WHERE civicrm_membership.is_test = 0"; $params = array(); @@ -2506,20 +2497,6 @@ WHERE civicrm_membership.is_test = 0"; // echo "."; $processCount++; - /** - $count++; - echo $dao->contact_id . ', '. CRM_Utils_System::memory( ) . "

\n"; - - CRM_Core_Error::debug( 'fBegin', count( $GLOBALS['_DB_DATAOBJECT']['RESULTS'] ) ); - if ( $count > 2 ) { - foreach ( $GLOBALS['_DB_DATAOBJECT']['RESULTS'] as $r ) { - CRM_Core_Error::debug( 'r', $r->query ); - } - // CRM_Core_Error::debug( 'f', $GLOBALS['_DB_DATAOBJECT']['RESULTS'] ); - exit( ); - } - **/ - // Put common parameters into array for easy access $memberParams = array( 'id' => $dao->membership_id, @@ -2676,13 +2653,13 @@ WHERE civicrm_membership.is_test = 0"; * Function to record contribution record associated with membership * * @param array $params array of submitted params - * @param array $ids array of ids - * @param object $membershipId membership id + * @param array $ids (param in process of being removed - try to use params) array of ids * * @return void * @static */ - static function recordMembershipContribution( &$params, &$ids, $membershipId ) { + static function recordMembershipContribution( &$params, $ids = array()) { + $membershipId = $params['membership_id']; $contributionParams = array(); $config = CRM_Core_Config::singleton(); $contributionParams['currency'] = $config->defaultCurrency;