Skip to content

Commit

Permalink
event#34: allow negative self-service/transfer time
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaphoneJon committed Aug 5, 2020
1 parent da6c68c commit 14b7bf1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CRM/Event/BAO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,6 @@ public static function formatFieldsAndSetProfileDefaults($contactId, &$form) {
* 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
Expand Down Expand Up @@ -1930,7 +1929,12 @@ public static function getSelfServiceEligibility(int $participantId, string $url
$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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/DAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Event/Event.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:331a210ceb36b5e9460705dbfbe71abf)
* (GenCodeChecksum:5f01b2be07ae960dffdbaa5249f23783)
*/

/**
Expand Down
3 changes: 3 additions & 0 deletions CRM/Upgrade/Incremental/sql/5.29.alpha1.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ SET body_text = '{ts escape="sql" 1=$unsubgroup 2=$actresub 3=$actresuburl}You h
WHERE component_type = 'Unsubscribe'
AND (body_text = '{ts escape="sql" 1=$unsubgroup 2=$actresub}You have been un-subscribed from the following groups: %1. You can re-subscribe by mailing %2 or clicking %3{/ts}'
OR body_text = '{ts escape="sql" 1=$unsubgroup 2=$actresub}You have been un-subscribed from the following groups: %1. You can re-subscribe by mailing %2 or clicking {/ts}');

-- Allow self-service/transfer to have a negative time.
ALTER TABLE civicrm_event MODIFY COLUMN selfcancelxfer_time INT;
9 changes: 9 additions & 0 deletions tests/phpunit/CRM/Event/BAO/ParticipantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ public function selfServiceScenarios() {
'isBackOffice' => FALSE,
'successExpected' => FALSE,
];
// Cancellation deadline is < 0 hours
$scenarios[] = [
'selfSvcEnabled' => 1,
'selfSvcHours' => -12,
'hoursToEvent' => 4,
'participantStatusId' => 1,
'isBackOffice' => FALSE,
'successExpected' => TRUE,
];
return $scenarios;
}

Expand Down
2 changes: 1 addition & 1 deletion xml/schema/Event/Event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@
</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>
Expand Down

0 comments on commit 14b7bf1

Please sign in to comment.