Show disabled membership types on contact tab
authorMatthew Wire <mjw@mjwconsult.co.uk>
Thu, 21 Jan 2021 16:50:27 +0000 (16:50 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 29 Jan 2021 09:43:19 +0000 (09:43 +0000)
CRM/Member/BAO/Membership.php
CRM/Member/Page/Tab.php
ext/financialacls/financialacls.php
tests/phpunit/api/v3/FinancialTypeACLTest.php

index 16da9bbb35383efc6e167ccbc2b4b3c1d4af338a..2d6af50517c2c1062b1543a16a7ce537fe2ef172 100644 (file)
@@ -1575,11 +1575,15 @@ WHERE  civicrm_membership.contact_id = civicrm_contact.id
    * @return null|string
    */
   public static function getContactMembershipCount($contactID, $activeOnly = FALSE) {
-    CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($membershipTypes);
+    $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)) . ")";
     }
+
     $select = "SELECT count(*) FROM civicrm_membership ";
     $where = "WHERE civicrm_membership.contact_id = {$contactID} AND civicrm_membership.is_test = 0 ";
 
index 584497abaa05f417d19f150f10d5a8b59355cff9..3d418592fc987e26f47b30c791aa397e9eacc3f5 100644 (file)
@@ -32,7 +32,10 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
    */
   public function browse() {
     $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
-    CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($membershipTypes);
+    $membershipTypes = \Civi\Api4\MembershipType::get(TRUE)
+      ->execute()
+      ->indexBy('id')
+      ->column('name');
     $addWhere = "membership_type_id IN (0)";
     if (!empty($membershipTypes)) {
       $addWhere = "membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")";
index 93a7755a56c5bcafa98a06ce157c1cad26e0d4f2..8fd88f4ba8433517bfec9f0e5a2aeddef9840449 100644 (file)
@@ -188,15 +188,20 @@ function financialacls_civicrm_selectWhereClause($entity, &$clauses) {
   if (!financialacls_is_acl_limiting_enabled()) {
     return;
   }
-  if ($entity === 'LineItem') {
-    $types = [];
-    CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
-    if ($types) {
-      $clauses['financial_type_id'] = 'IN (' . implode(',', array_keys($types)) . ')';
-    }
-    else {
-      $clauses['financial_type_id'] = '= 0';
-    }
+
+  switch ($entity) {
+    case 'LineItem':
+    case 'MembershipType':
+      $types = [];
+      CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
+      if ($types) {
+        $clauses['financial_type_id'] = 'IN (' . implode(',', array_keys($types)) . ')';
+      }
+      else {
+        $clauses['financial_type_id'] = '= 0';
+      }
+      break;
+
   }
 
 }
index 036960b09009f41a0d89f7f95ca8afea0ddb6793..e78f9fe5cbf811725789794b59ccb1deeca89f25 100644 (file)
@@ -316,12 +316,13 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase {
     $this->assertEquals($contribution['count'], 1);
   }
 
-  public function testMembersipTypeACLFinancialTypeACL() {
+  public function testMembershipTypeACLFinancialTypeACL() {
     $contactID = $this->individualCreate();
     $this->contactMembershipCreate(['contact_id' => $contactID]);
     $this->enableFinancialACLs();
     $this->setPermissions([
       'access CiviCRM',
+      'access CiviMember',
       'access CiviContribute',
       'view all contacts',
       'add contributions of type Donation',