CiviCRM
  1. CiviCRM
  2. CRM-10012

Limit the number of related memberships

    Details

    • Is MIH?:
      No
    • Code Sprint:
      No

      Description

      === Please vote or comment on this proposed improvement so I can judge community interest and prioritize accordingly ===

      Very often membership privileges should be granted to only a fixed number of company representatives (ex: our Corporate members can designate 8 company representatives). Yet with CiviCRM all employees of the member organization inherit the membership if configured as such, without limits.

      I am proposing to implement the following changes:

      a) in the 'Create/Edit Membership Type' form, add a 'Max Related Members' field (optional, defaults to 0) right after the 'Relationship Type' field

      b) in the CRM_Member_DAO_Membership::createRelatedMemberships function, check for max_related_members > 0 and if so limit the number of related memberships we create to the above (ie. related memberships would be created for the first x related contacts only)

      c) in the 'Create/Edit Membership' form, add a section only displayed when max_related_members > 0 that lists all related contacts with checkboxes next to each. Clicking the checkbox would create the related membership record, unclicking would delete. A counter (x/m) could also be displayed and updated as checkboxes are changed. I would let the users create more related membership than the value of max_related_memberships to allow for manual overrides.

        Activity

        Hide
        David Greenberg added a comment -
        Committed revision 45938.
        We really should have some test coverage on max_related. Can you create a unit test for CRM_Contact_BAO_Relationship::relatedMembers which exercises this a bit?
        Show
        David Greenberg added a comment - Committed revision 45938. We really should have some test coverage on max_related. Can you create a unit test for CRM_Contact_BAO_Relationship::relatedMembers which exercises this a bit?
        Hide
        Nicolas Ganivet added a comment -
        One more minor correction prior to 4.3 release. This is to correct a display issue when a membership is assigned to a contact that has been deleted.

        File CRM/Member/Page/Tab.php, around line 150, change:
                $query = "
        SELECT COUNT(m.id)
           FROM civicrm_membership m
             LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
          WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1";

        To:
                $query = "
        SELECT COUNT(m.id)
           FROM civicrm_membership m
             LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
             LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id
          WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
        Show
        Nicolas Ganivet added a comment - One more minor correction prior to 4.3 release. This is to correct a display issue when a membership is assigned to a contact that has been deleted. File CRM/Member/Page/Tab.php, around line 150, change:         $query = " SELECT COUNT(m.id)    FROM civicrm_membership m      LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id   WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1"; To:         $query = " SELECT COUNT(m.id)    FROM civicrm_membership m      LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id      LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id   WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
        Hide
        Nicolas Ganivet added a comment -
        Please implement the change in the comment prior to 4.3 release. You can then reassign to me for the QA / creating the unit testing.
        Show
        Nicolas Ganivet added a comment - Please implement the change in the comment prior to 4.3 release. You can then reassign to me for the QA / creating the unit testing.
        Hide
        Coleman Watts added a comment -
        OK I have pushed up your change.
        Show
        Coleman Watts added a comment - OK I have pushed up your change.
        Show
        David Greenberg added a comment - https://github.com/civicrm/civicrm-core/pull/361

          People

          • Assignee:
            Nicolas Ganivet
            Reporter:
            Nicolas Ganivet
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 2 days
              2d
              Remaining:
              Remaining Estimate - 2 days
              2d
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development