CRM-17745 Make maximum additional participants configurable
authorJKingsnorth <john@johnkingsnorth.co.uk>
Wed, 23 Dec 2015 13:51:13 +0000 (13:51 +0000)
committerJKingsnorth <john@johnkingsnorth.co.uk>
Wed, 23 Dec 2015 13:51:13 +0000 (13:51 +0000)
CRM/Event/Form/ManageEvent/Registration.php
CRM/Event/Form/Registration/Register.php
CRM/Upgrade/Incremental/sql/4.8.alpha1.mysql.tpl [new file with mode: 0644]
templates/CRM/Event/Form/ManageEvent/Registration.hlp
templates/CRM/Event/Form/ManageEvent/Registration.tpl
xml/schema/Event/Event.xml

index ef10c0b50c3f40dc54bf862ebd0ef55c8dc46dd5..8ad22bdc3c844313aef4cfea5064034b7564c3bb 100644 (file)
@@ -134,6 +134,11 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
 
       $this->assign('profilePostMultiple', CRM_Utils_Array::value('custom_post', $defaults));
 
+      // CRM-17745: Make max additional participants configurable
+      if (empty($defaults['max_additional_participants'])) {
+        $defaults['max_additional_participants'] = 9;
+      }
+
       if (!empty($defaults['is_multiple_registrations'])) {
         // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
 
@@ -264,6 +269,10 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
       ts('Register multiple participants?')
     );
 
+    // CRM-17745: Make maximum additional participants configurable
+    $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 9);
+    $this->add('select', 'max_additional_participants', ts('Maximum additional participants'), $numericOptions, FALSE, array('class' => 'required'));
+
     $this->addElement('checkbox',
       'allow_same_participant_emails',
       ts('Same email address?')
index 9571508678ca87d7a66c71ca11e0530f3f3f5721..930345595f63ba50aa1ec29e47c688ac5abe8da0 100644 (file)
@@ -310,20 +310,13 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     if ($this->_values['event']['is_multiple_registrations']) {
       // don't allow to add additional during confirmation if not preregistered.
       if (!$this->_allowConfirmation || $this->_additionalParticipantIds) {
-        // Hardcode maximum number of additional participants here for now. May need to make this configurable per event.
+        // CRM-17745: Make maximum additional participants configurable
         // Label is value + 1, since the code sees this is ADDITIONAL participants (in addition to "self")
-        $additionalOptions = array(
-          '' => '1',
-          1 => '2',
-          2 => '3',
-          3 => '4',
-          4 => '5',
-          5 => '6',
-          6 => '7',
-          7 => '8',
-          8 => '9',
-          9 => '10',
-        );
+        $additionalOptions = array();
+        $additionalOptions[''] = 1;
+        for ($i=1; $i <= $this->_values['event']['max_additional_participants']; $i++) {
+          $additionalOptions[$i] = $i + 1;
+        }
         $this->add('select', 'additional_participants',
           ts('How many people are you registering?'),
           $additionalOptions,
diff --git a/CRM/Upgrade/Incremental/sql/4.8.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.8.alpha1.mysql.tpl
new file mode 100644 (file)
index 0000000..f9c02f8
--- /dev/null
@@ -0,0 +1,11 @@
+{* file to handle db changes in 4.8.alpha1 during upgrade *}
+
+-- CRM-17745: Make maximum additional participants configurable
+ALTER TABLE civicrm_event
+  ADD COLUMN max_additional_participants int(10) unsigned
+  DEFAULT 0
+  COMMENT 'Maximum number of additional participants that can be registered on a single booking'
+  AFTER is_multiple_registrations;
+UPDATE civicrm_event
+  SET max_additional_participants = 9
+  WHERE is_multiple_registrations = 1;
\ No newline at end of file
index 42e438bbbc7e52d88a48170d1ce5089e5a7d985e..cdcd12a6baf5ac1fff35653d0a1eee354afb39a6 100644 (file)
 <p>{ts}You can use different profile for the person who is registering than for "Additional Participants". For example, you may want to require an email address from the person entering the registration while not requiring (or even requesting) emails for additional participants (i.e. their "guests").{/ts}</p>
 {/htxt}
 
+{htxt id="id-max_additional-title"}
+  {ts}Maximum Additional Participants{/ts}
+{/htxt}
+{htxt id="id-max_additional"}
+  <p>{ts}Limit the number of additional participants that can be registered in a single booking.{/ts}</p>
+  <p>{ts}Eg: if you choose '2' then the lead booker can bring 2 guests; there would be a limit of 3 participants in total per booking.{/ts}</p>
+{/htxt}
+
 {htxt id="id-allow_same_email-title"}
   {ts}Allow Shared Email{/ts}
 {/htxt}
index 02164b343a9f9781e54fa4d9c912aaa4003ad988..e33d4753de2134bc4847907515a044313d13ff0c 100644 (file)
     <td scope="row" class="label" width="20%">{$form.is_multiple_registrations.label}</td>
     <td>{$form.is_multiple_registrations.html} {help id="id-allow_multiple"}</td>
   </tr>
+  <tr class="crm-event-manage-registration-form-block-maximum_additional_participants" id="id-max-additional-participants">
+    <td scope="row" class="label" width="20%">{$form.max_additional_participants.label}</td>
+    <td>{$form.max_additional_participants.html} {help id="id-max_additional"}</td>
+  </tr>
   <tr class="crm-event-manage-registration-form-block-allow_same_participant_emails">
     <td scope="row" class="label" width="20%">{$form.allow_same_participant_emails.label}</td>
     <td>{$form.allow_same_participant_emails.html} {help id="id-allow_same_email"}</td>
@@ -391,14 +395,6 @@ target_element_type ="block"
 field_type          ="radio"
 invert              = 0
 }
-{include file="CRM/common/showHideByFieldValue.tpl"
-trigger_field_id    ="is_multiple_registrations"
-trigger_value       =""
-target_element_id   ="additional_profile_pre|additional_profile_post"
-target_element_type ="table-row"
-field_type          ="radio"
-invert              = 0
-}
 {if $form.requires_approval}
 {include file="CRM/common/showHideByFieldValue.tpl"
     trigger_field_id    ="requires_approval"
@@ -473,18 +469,17 @@ $(function($) {
 
     var allow_multiple = $("#is_multiple_registrations");
     if ( !allow_multiple.prop('checked') ) {
-        $('#additional_profile_pre,#additional_profile_post').hide();
+        $('#additional_profile_pre,#additional_profile_post,#id-max-additional-participants').hide();
     }
     allow_multiple.change( function( ) {
         if ( !$(this).prop('checked') ) {
             $("#additional_custom_pre_id,#additional_custom_post_id").val('');
             $(".crm-event-manage-registration-form-block-additional_custom_post_multiple").hide();
-            $('#additional_profile_pre,#additional_profile_post').hide();
+            $('#additional_profile_pre,#additional_profile_post,#id-max-additional-participants').hide();
         } else {
             $(".crm-event-manage-registration-form-block-additional_custom_post_multiple").show();
-            $('#additional_profile_pre,#additional_profile_post').show();
+            $('#additional_profile_pre,#additional_profile_post,#id-max-additional-participants').show();
         }
-
     });
 
     var allow_selfCancel = $("#allow_selfcancelxfer");
index 25bd248e214fe43e99f6214afdff384e99ef3941..b6c8509d1eb4e90f936b59512d842f729baab004 100644 (file)
       <type>CheckBox</type>
     </html>
   </field>
+  <field>
+    <name>max_additional_participants</name>
+    <type>int unsigned</type>
+    <title>Maximum number of additional participants per registration</title>
+    <default>0</default>
+    <comment>Maximum number of additional participants that can be registered on a single booking</comment>
+    <add>4.8</add>
+  </field>
   <field>
     <name>allow_same_participant_emails</name>
     <type>boolean</type>