allow negative self-service hours
authorJon Goldberg <jon@megaphonetech.com>
Fri, 28 Aug 2020 02:00:09 +0000 (22:00 -0400)
committerJon Goldberg <jon@megaphonetech.com>
Sun, 30 Aug 2020 04:52:31 +0000 (00:52 -0400)
event #34 message improvement

fixes to message template

fixes

CRM/Event/BAO/Event.php
CRM/Event/BAO/Participant.php
CRM/Upgrade/Incremental/MessageTemplates.php
CRM/Upgrade/Incremental/sql/5.30.alpha1.mysql.tpl
templates/CRM/Event/Form/ManageEvent/Registration.hlp
tests/phpunit/CRM/Event/BAO/ParticipantTest.php
xml/schema/Event/Event.xml
xml/templates/message_templates/event_online_receipt_html.tpl
xml/templates/message_templates/event_online_receipt_text.tpl
xml/templates/message_templates/participant_confirm_html.tpl
xml/templates/message_templates/participant_confirm_text.tpl

index 794e5d14e5a4b00c469db67c7c42805fea015a8b..b583fdd09926938c387655857f44b8053d664546 100644 (file)
@@ -1158,6 +1158,8 @@ WHERE civicrm_event.is_active = 1
           'conference_sessions' => $sessions,
           'credit_card_number' => CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $participantParams)),
           'credit_card_exp_date' => CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $participantParams))),
+          'selfcancelxfer_time' => abs($values['event']['selfcancelxfer_time']),
+          'selfservice_preposition' => $values['event']['selfcancelxfer_time'] < 0 ? 'after' : 'before',
         ]);
 
         // CRM-13890 : NOTE wait list condition need to be given so that
index 1f19c32f74b48ffa0907baad6f8910d97578b107..f18198b2096152b5c67be0cf2e5f43f158626bff 100644 (file)
@@ -1877,7 +1877,6 @@ WHERE    civicrm_participant.contact_id = {$contactID} AND
    * Evaluate whether a participant record is eligible for self-service transfer/cancellation.  If so,
    * return additional participant/event details.
    *
-   * TODO: This function fails when the "hours until self-service" is less than zero.
    * @param int $participantId
    * @param string $url
    * @param bool $isBackOffice
@@ -1930,7 +1929,12 @@ WHERE    civicrm_participant.contact_id = {$contactID} AND
       $cancelDeadline = (new Datetime($start_date))->sub($cancelInterval);
       if ($timenow > $cancelDeadline) {
         $details['eligible'] = FALSE;
-        $details['ineligible_message'] = ts("Registration for this event cannot be cancelled or transferred less than %1 hours prior to the event's start time. Contact the event organizer if you have questions.", [1 => $time_limit]);
+        // Change the language of the status message based on whether the waitlist time limit is positive or negative.
+        $afterOrPrior = $time_limit < 0 ? 'after' : 'prior';
+        $moreOrLess = $time_limit < 0 ? 'more' : 'less';
+        $details['ineligible_message'] = ts("Registration for this event cannot be cancelled or transferred %1 than %2 hours %3 to the event's start time. Contact the event organizer if you have questions.",
+        [1 => $moreOrLess, 2 => $cancelHours, 3 => $afterOrPrior]);
+
       }
     }
     return $details;
index 0b86bc6a6dce72e55275d2fd4cafd1a0e7179c07..94f932a96e5038443eba0ce1bd68a0d0476d6123 100644 (file)
@@ -215,6 +215,16 @@ class CRM_Upgrade_Incremental_MessageTemplates {
           ['name' => 'contribution_invoice_receipt', 'type' => 'html'],
         ],
       ],
+      [
+        'version' => '5.30.alpha1',
+        'upgrade_descriptor' => ts('Support negative hours for cancellation/transfer'),
+        'templates' => [
+          ['name' => 'participant_confirm', 'type' => 'html'],
+          ['name' => 'participant_confirm', 'type' => 'text'],
+          ['name' => 'event_online_receipt', 'type' => 'html'],
+          ['name' => 'event_online_receipt', 'type' => 'text'],
+        ],
+      ],
 
     ];
   }
index 4f70e19a59d01356ad1acff3ac2117c2b7650758..3b0804b3c3fc5b60548ab5013575238c2be1d2ae 100644 (file)
@@ -1 +1,4 @@
 {* file to handle db changes in 5.30.alpha1 during upgrade *}
+-- Allow self-service/transfer to have a negative time.
+ALTER TABLE civicrm_event MODIFY COLUMN selfcancelxfer_time INT;
+
index 2aa4f62db7de9fa010f1db254a93da413d3ac6d0..8fba9c56a980bd8add2c3ec8ba9d9e795f34db3c 100644 (file)
@@ -89,5 +89,5 @@
   {ts}Cancellation or Transfer Time Limit{/ts}
 {/htxt}
 {htxt id="id-selfcancelxfer_time"}
-  {ts}Number of hours prior to event start date to allow self-service cancellation or transfer. Enter 0 (or leave empty) to allow cancellation or transfer up until the event has started.{/ts}
+  {ts}Number of hours prior to event start date to allow self-service cancellation or transfer. Enter a negative number of hours to allow cancellation after the event starts. Enter 0 (or leave empty) to allow cancellation or transfer up until the event has started.{/ts}
 {/htxt}
index eb8dc5700842b0a681e17e3baeeedf799c3716ce..4dc15134dc0aa0581c791be1f1de3cd90309ffca 100644 (file)
@@ -493,6 +493,15 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase {
       'isBackOffice' => FALSE,
       'successExpected' => FALSE,
     ];
+    // Cancellation deadline is < 0 hours
+    $scenarios[] = [
+      'selfSvcEnabled' => 1,
+      'selfSvcHours' => -12,
+      'hoursToEvent' => 4,
+      'participantStatusId' => 1,
+      'isBackOffice' => FALSE,
+      'successExpected' => TRUE,
+    ];
     return $scenarios;
   }
 
index 4593c92d4e5630c15b493c4279e78cfae0413dd4..979a84df4de453565b0df4caeee064e77a763763 100644 (file)
   </field>
   <field>
     <name>selfcancelxfer_time</name>
-    <type>int unsigned</type>
+    <type>int</type>
     <default>0</default>
     <title>Self-service Cancellation or Transfer Time</title>
     <comment>Number of hours prior to event start date to allow self-service cancellation or transfer.</comment>
index c9e0806256758b4ee211926e4ee31c794b33da98..b9fdec15b4439318ce6f4251931307a35bf7f219 100644 (file)
     {if $event.allow_selfcancelxfer }
      <tr>
       <td colspan="2" {$valueStyle}>
-        {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}<br />
+        {ts 1=$selfcancelxfer_time 2=$selfservice_preposition}You may transfer your registration to another participant or cancel your registration up to %1 hours %2 the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}<br />
         {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}"  h=0 a=1 fe=1}{/capture}
         <a href="{$selfService}">{ts}Click here to transfer or cancel your registration.{/ts}</a>
       </td>
index dbd5f1ba880383930183619d10706e17109ee9b3..05be6dff34a71d549e655fd1704e3339317a60e9 100644 (file)
@@ -291,7 +291,7 @@ You were registered by: {$payer.name}
 {/if}
 
 {if $event.allow_selfcancelxfer }
-{ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
+{ts 1=$selfcancelxfer_time 2=$selfservice_preposition}You may transfer your registration to another participant or cancel your registration up to %1 hours %2 the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
    {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}"  h=0 a=1 fe=1}{/capture}
 {ts}Transfer or cancel your registration:{/ts} {$selfService}
 {/if}
index ed1d2b7b0db90d4d9f71837e27f653c073aedf6f..c4075a04bbb64bd797925d7fbc535142608424e5 100644 (file)
   {if $event.allow_selfcancelxfer }
    <tr>
      <td colspan="2" {$valueStyle}>
-       {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}<br />
+       {ts 1=$selfcancelxfer_time 2=$selfservice_preposition}You may transfer your registration to another participant or cancel your registration up to %1 hours %2 the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}<br />
          {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}"  h=0 a=1 fe=1}{/capture}
        <a href="{$selfService}">{ts}Click here to transfer or cancel your registration.{/ts}</a>
      </td>
index 6296b4594d76321131102b3a0876341451759be4..2c459e66e29fae1203f20663c35453397060d175 100644 (file)
@@ -13,7 +13,7 @@ Click this link to go to a web page where you can confirm your registration onli
 {$confirmUrl}
 {/if}
 {if $event.allow_selfcancelxfer }
-{ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
+{ts 1=$selfcancelxfer_time 2=$selfservice_preposition}You may transfer your registration to another participant or cancel your registration up to %1 hours %2 the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
    {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}"  h=0 a=1 fe=1}{/capture}
 {ts}Transfer or cancel your registration:{/ts} {$selfService}
 {/if}