<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
*/
static function &add(&$params, &$ids) {
- // get activity types for use in activity record creation
- $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
-
if (CRM_Utils_Array::value('membership', $ids)) {
CRM_Utils_Hook::pre('edit', 'Membership', $ids['membership'], $params);
$oldStatus = NULL;
$membership->save();
$membership->free();
- $session = CRM_Core_Session::singleton();
if (empty($membership->contact_id) || empty($membership->status_id)) {
// this means we are in renewal mode and are just updating the membership
// record or this is an API update call and all fields are not present in the update record
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);
}
* @static
*/
static function &create(&$params, &$ids, $skipRedirect = FALSE, $activityType = 'Membership Signup') {
- $membershipID = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membership', $ids));
// always calculate status if is_override/skipStatusCal is not true.
// giving respect to is_override during import. CRM-4012
) {
$dates = array('start_date', 'end_date', 'join_date');
foreach ($dates as $date) {
- // see notes below if id is not passed in we will calc the dates, not sure impact of not
- // changing the return null if doing an update so being cautious
- // and leaving behaviour unchanged if id exists (null doesn't seem valid...)
- $returnNull = TRUE;
- if(!$membershipID) {
- $returnNull = FALSE;
- }
- $$date = CRM_Utils_Date::processDate(CRM_Utils_Array::value($date, $params), NULL, $returnNull, 'Ymd');
- if(!empty($$date)) {
- $params[$date] = $$date;
- }
- }
- /*
- * if we have not been given the start date or the end date we will calculate them.
- * In the interests of being cautious we won't do this if 'id' is set
- * even though skipStatusCal is the default from the api when id is set
- * AND the forms currently take care of the dates
- * this could possibly be revised to a less cautious approach
- */
- if(!$membershipID && (empty($start_date) || empty($end_date))) {
- $defaults = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params['membership_type_id'],
- $join_date, $start_date, $end_date
- );
- $params = array_merge($defaults, $params);
+ $$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
$excludeIsAdmin = TRUE;
}
- $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($params['start_date'], $params['end_date'], $params['join_date'],
+ $calcStatus = $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($start_date, $end_date, $join_date,
'today', $excludeIsAdmin
);
if (empty($calcStatus)) {
//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( array_merge($params, array('membership_id' => $membership->id)), $ids);
+ $memInfo = array_merge($params, array('membership_id' => $membership->id));
+ $params['contribution'] = self::recordMembershipContribution($memInfo, $ids);
}
//insert payment record for this membership
*/
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();
'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
}
/**
+ * @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.
// 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) ||
$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,
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();
// echo ".";
$processCount++;
- /**
- $count++;
- echo $dao->contact_id . ', '. CRM_Utils_System::memory( ) . "<p>\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,