an old membership is also valid for discussion
authorAndrew Engelbrecht <andrew@fsf.org>
Tue, 25 Apr 2023 20:28:38 +0000 (16:28 -0400)
committerroot <root@login0d.fsf.org>
Tue, 25 Apr 2023 20:28:38 +0000 (16:28 -0400)
(along with a current membership)

docs/fsf-drupal-auth.md
lib/Auth/Source/FSFDrupalAuth.php

index aeda9288acba55eb36ec6a9970414bb25cc5b72f..4209ba2232fef4d37e2657bcedcb403426cbee47 100644 (file)
@@ -24,6 +24,7 @@ SQL queries in `config/authsources.php` should be something like the following:
         'query_nomination_process_gift_receipt' => "select count(*) as gift_memberships_count from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_contribution d on c.id=d.contact_id where a.name = :username and d.contribution_page_id = :gift_redeem_page_id and d.receive_date > :start_date and d.receive_date < :end_date;",
         'query_nomination_process_adhoc' => "select count(*) as is_adhoc_member from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_group_contact d on c.id=d.contact_id where a.name=:username and a.status=1 and c.is_deleted=0 and d.group_id = :adhoc_access_group_id and d.status = 'Added' limit 1;",
 
+        'query_discussion_process_old_membership' => "select count(*) from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.status = 1 and d.is_deleted = 0 and c.status_id is not NULL and a.name = :username and d.end_date > :start_date and d.start_date < :end_date and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) order by c.status_id limit 10;",
         'query_discussion_process_donations' => "select d.total_amount as amount, d.receive_date as receive_date, f.membership_type_id as member_type_id from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_contribution d on c.id=d.contact_id left join civicrm.civicrm_membership_payment e on d.id=e.contribution_id left join civicrm.civicrm_membership f on e.membership_id=f.id where a.name = :username and d.contribution_status_id = 1 and d.receive_date > :start_date and d.receive_date < :end_date;",
         'query_discussion_process_gift_receipt' => "select count(*) as gift_memberships_count from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_contribution d on c.id=d.contact_id where a.name = :username and d.contribution_page_id = :gift_redeem_page_id and d.receive_date > :start_date and d.receive_date < :end_date;",
         'query_discussion_process_adhoc' => "select count(*) as is_adhoc_member from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_group_contact d on c.id=d.contact_id where a.name=:username and a.status=1 and c.is_deleted=0 and d.group_id = :adhoc_access_group_id and d.status = 'Added' limit 1;",
index b9b808af2bd3c1beb2813b814b990a8344770ce6..4f365ca625a6b2e4c294c1c6975cde2597b5d399 100644 (file)
@@ -49,6 +49,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase
     private $query_nomination_process_gift_receipt;
     private $query_nomination_process_adhoc;
 
+    private $query_discussion_process_old_membership;
     private $query_discussion_process_donations;
     private $query_discussion_process_gift_receipt;
     private $query_discussion_process_adhoc;
@@ -110,6 +111,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase
                'membership_monthly_rate',
                'student_membership_monthly_rate',
 
+               'query_discussion_process_old_membership',
                'query_discussion_process_donations',
                'query_discussion_process_gift_receipt',
                'query_discussion_process_adhoc',
@@ -340,6 +342,8 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase
                return $this->query_db($query_name, $parameters);
        };
 
+       $old_membership_query = $donation_query;
+
        $compare_res = function ($result, $amount) {
                foreach ($result[0] as $key => $value) {
                        if (intval($value) >= $amount) {
@@ -468,6 +472,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase
        //
 
        $donation_params    = ['start_date' => $discussion_process_start_date, 'end_date' => $discussion_process_end_date];
+       $old_member_params  = $donation_params;
        $gift_member_params = ['start_date' => $discussion_process_start_date, 'end_date' => $discussion_process_end_date, 'gift_redeem_page_id' => intval($this->gift_redeem_page_id)];
        $adhoc_params       = ['adhoc_access_group_id' => intval($this->discussion_process_adhoc_access_group_id)];
        $adhoc_params_no    = ['adhoc_access_group_id' => intval($this->discussion_process_adhoc_no_access_group_id)];
@@ -488,7 +493,8 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase
                        ': Not eligible for board nominee discussion process.');
                $attributes['discussion_process'] = ['false'];
 
-       } elseif ($discussion_process_analyze_history($donation_query('query_discussion_process_donations', $donation_params))
+       } elseif ($compare_res($old_membership_query('query_discussion_process_old_membership', $old_member_params), 1)
+               || $discussion_process_analyze_history($donation_query('query_discussion_process_donations', $donation_params))
                || $compare_res($donation_query('query_discussion_process_gift_receipt', $gift_member_params), 1)) {
 
                $attributes['discussion_process'] = ['true'];