Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/mail#89 Fix unreleased regression where civimember is not permitted/enabled #19594

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ public static function getCountComponent($component, $contactId, $tableName = NU
return CRM_Contribute_BAO_Contribution::contributionCount($contactId);

case 'membership':
return CRM_Member_BAO_Membership::getContactMembershipCount($contactId, TRUE);
return CRM_Member_BAO_Membership::getContactMembershipCount((int) $contactId, TRUE);

case 'participant':
return CRM_Event_BAO_Participant::getContactParticipantCount($contactId);
Expand Down
47 changes: 28 additions & 19 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
+--------------------------------------------------------------------+
*/

use Civi\API\Exception\UnauthorizedException;
use Civi\Api4\MembershipType;

/**
*
* @package CRM
Expand Down Expand Up @@ -1572,29 +1575,35 @@ public static function buildMembershipTypeValues($form, $membershipTypeID = [],
* @param int $contactID
* @param bool $activeOnly
*
* @return null|string
* @return int
* @throws \API_Exception
*/
public static function getContactMembershipCount($contactID, $activeOnly = FALSE) {
$membershipTypes = \Civi\Api4\MembershipType::get(TRUE)
->execute()
->indexBy('id')
->column('name');
$addWhere = " AND membership_type_id IN (0)";
if (!empty($membershipTypes)) {
$addWhere = " AND membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")";
}
public static function getContactMembershipCount(int $contactID, $activeOnly = FALSE): int {
try {
$membershipTypes = MembershipType::get(TRUE)
->execute()
->indexBy('id')
->column('name');
$addWhere = " AND membership_type_id IN (0)";
if (!empty($membershipTypes)) {
$addWhere = " AND membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")";
}

$select = "SELECT count(*) FROM civicrm_membership ";
$where = "WHERE civicrm_membership.contact_id = {$contactID} AND civicrm_membership.is_test = 0 ";
$select = "SELECT COUNT(*) FROM civicrm_membership ";
$where = "WHERE civicrm_membership.contact_id = {$contactID} AND civicrm_membership.is_test = 0 ";

// CRM-6627, all status below 3 (active, pending, grace) are considered active
if ($activeOnly) {
$select .= " INNER JOIN civicrm_membership_status ON civicrm_membership.status_id = civicrm_membership_status.id ";
$where .= " and civicrm_membership_status.is_current_member = 1";
}
// CRM-6627, all status below 3 (active, pending, grace) are considered active
if ($activeOnly) {
$select .= " INNER JOIN civicrm_membership_status ON civicrm_membership.status_id = civicrm_membership_status.id ";
$where .= " and civicrm_membership_status.is_current_member = 1";
}

$query = $select . $where . $addWhere;
return CRM_Core_DAO::singleValueQuery($query);
$query = $select . $where . $addWhere;
return (int) CRM_Core_DAO::singleValueQuery($query);
}
catch (UnauthorizedException $e) {
return 0;
}
}

/**
Expand Down