From 464f67174ea69255d908a03c70533b8b745dd3eb Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Tue, 10 Oct 2023 18:28:40 +0100 Subject: [PATCH] Add option to control display of calendar links --- CRM/Event/DAO/Event.php | 34 ++++++++++++++++++- CRM/Event/Form/ManageEvent/EventInfo.php | 2 ++ CRM/Event/Tokens.php | 7 ++-- CRM/Upgrade/Incremental/php/FiveSixtyNine.php | 2 ++ .../CRM/Event/Form/ManageEvent/EventInfo.tpl | 4 +++ .../CRM/Event/Form/Registration/ThankYou.tpl | 6 ++-- templates/CRM/Event/Page/EventInfo.tpl | 2 +- .../Event/Form/Registration/ConfirmTest.php | 27 +++++++++++++-- xml/schema/Event/Event.xml | 12 +++++++ .../event_offline_receipt_html.tpl | 2 +- .../event_online_receipt_html.tpl | 2 +- .../event_online_receipt_text.tpl | 2 +- 12 files changed, 90 insertions(+), 12 deletions(-) diff --git a/CRM/Event/DAO/Event.php b/CRM/Event/DAO/Event.php index e1bc30cb40..4d09de0d57 100644 --- a/CRM/Event/DAO/Event.php +++ b/CRM/Event/DAO/Event.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Event/Event.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:a1c6fa263d5a0c98d03e270a5759dd35) + * (GenCodeChecksum:fd75d47cd23c3893174a0b55ba831894) */ /** @@ -675,6 +675,15 @@ class CRM_Event_DAO_Event extends CRM_Core_DAO { */ public $is_billing_required; + /** + * If true then calendar links are shown for this event. + * + * @var bool|string + * (SQL type: tinyint) + * Note that values will be retrieved from the database as a string. + */ + public $is_show_calendar_links; + /** * Class constructor. */ @@ -2365,6 +2374,29 @@ class CRM_Event_DAO_Event extends CRM_Core_DAO { ], 'add' => '4.6', ], + 'is_show_calendar_links' => [ + 'name' => 'is_show_calendar_links', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Are calendar links shown?'), + 'description' => ts('If true then calendar links are shown for this event.'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_event.is_show_calendar_links', + 'default' => '1', + 'table_name' => 'civicrm_event', + 'entity' => 'Event', + 'bao' => 'CRM_Event_BAO_Event', + 'localizable' => 0, + 'html' => [ + 'type' => 'CheckBox', + ], + 'add' => '5.68', + ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index dd1009bca4..82a28c5e66 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -161,6 +161,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { $this->addElement('checkbox', 'is_public', ts('Public Event')); $this->addElement('checkbox', 'is_share', ts('Add footer region with Twitter, Facebook and LinkedIn share buttons and scripts?')); $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location')); + $this->addElement('checkbox', 'is_show_calendar_links', ts('Show Calendar Links')); $this->add('datepicker', 'start_date', ts('Start'), [], !$this->_isTemplate, ['time' => TRUE]); $this->add('datepicker', 'end_date', ts('End'), [], FALSE, ['time' => TRUE]); @@ -222,6 +223,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { $params['is_active'] = $params['is_active'] ?? FALSE; $params['is_public'] = $params['is_public'] ?? FALSE; $params['is_share'] = $params['is_share'] ?? FALSE; + $params['is_show_calendar_links'] = $params['is_show_calendar_links'] ?? FALSE; $params['default_role_id'] = $params['default_role_id'] ?? FALSE; $params['id'] = $this->_id; //merge params with defaults from templates diff --git a/CRM/Event/Tokens.php b/CRM/Event/Tokens.php index ed4f806656..35b653b3a6 100644 --- a/CRM/Event/Tokens.php +++ b/CRM/Event/Tokens.php @@ -204,6 +204,7 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { 'pay_later_text', 'pay_later_receipt', 'fee_label', + 'is_show_calendar_links:label', 'custom.*', ], $this->getExposedFields())) ->execute()->first(); @@ -271,6 +272,7 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { 'confirm_email_text', 'is_monetary', 'fee_label', + 'is_show_calendar_links', ]; } @@ -287,10 +289,11 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { */ protected function getTokenMetadataOverrides(): array { return [ + 'allow_selfcancelxfer' => ['audience' => 'sysadmin'], + 'is_monetary' => ['audience' => 'sysadmin'], 'is_public' => ['audience' => 'sysadmin'], + 'is_show_calendar_links' => ['audience' => 'sysadmin'], 'is_show_location' => ['audience' => 'sysadmin'], - 'is_monetary' => ['audience' => 'sysadmin'], - 'allow_selfcancelxfer' => ['audience' => 'sysadmin'], 'selfcancelxfer_time' => ['audience' => 'sysadmin'], ]; } diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyNine.php b/CRM/Upgrade/Incremental/php/FiveSixtyNine.php index 1b924ccf58..0c3422ce31 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyNine.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyNine.php @@ -29,6 +29,8 @@ class CRM_Upgrade_Incremental_php_FiveSixtyNine extends CRM_Upgrade_Incremental_ */ public function upgrade_5_69_alpha1($rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('Add is_show_calendar_links column to Event table', 'addColumn', 'civicrm_event', 'is_show_calendar_links', + 'tinyint NOT NULL DEFAULT 1 COMMENT "If true, calendar links are shown for this event"'); } } diff --git a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl index 9bfff190cc..326ef4aa00 100644 --- a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl +++ b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl @@ -105,6 +105,10 @@   {$form.is_active.html} {$form.is_active.label} + +   + {$form.is_show_calendar_links.html} {$form.is_show_calendar_links.label} + {if $eventID AND !$isTemplate} diff --git a/templates/CRM/Event/Form/Registration/ThankYou.tpl b/templates/CRM/Event/Form/Registration/ThankYou.tpl index 14fe56cfa5..d90910595e 100644 --- a/templates/CRM/Event/Form/Registration/ThankYou.tpl +++ b/templates/CRM/Event/Form/Registration/ThankYou.tpl @@ -196,13 +196,13 @@ {ts 1=$event.event_title}Back to "%1" event information{/ts} - {if $event.is_public} + {if $event.is_public and $event.is_show_calendar_links} {/if} {if $event.is_share} - {capture assign=eventUrl}{crmURL p='civicrm/event/info' q="id=`$event.id`&reset=1" a=1 fe=1 h=1}{/capture} - {include file="CRM/common/SocialNetwork.tpl" url=$eventUrl title=$event.title pageURL=$eventUrl} + {capture assign=eventUrl}{crmURL p='civicrm/event/info' q="id=`$event.id`&reset=1" a=1 fe=1 h=1}{/capture} + {include file="CRM/common/SocialNetwork.tpl" url=$eventUrl title=$event.title pageURL=$eventUrl} {/if} diff --git a/templates/CRM/Event/Page/EventInfo.tpl b/templates/CRM/Event/Page/EventInfo.tpl index 4d09752578..ed71354dc4 100644 --- a/templates/CRM/Event/Page/EventInfo.tpl +++ b/templates/CRM/Event/Page/EventInfo.tpl @@ -222,7 +222,7 @@ {/if} {/crmRegion} - {if $event.is_public} + {if $event.is_public and $event.is_show_calendar_links} diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index b01d35b706..7ccd71382c 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -43,6 +43,28 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $this->assertStringContainsString($string, $this->sentMail[0]); } + /** + * Test mail does not have calendar links if 'is_show_calendar_links = FALSE' + */ + public function testNoCalendarLinks() : void { + $this->submitPaidEvent(['is_show_calendar_links' => FALSE]); + $this->assertSentMailNotHasStrings([ + 'Download iCalendar entry for this event', + 'Add event to Google Calendar', + 'civicrm/event/ical', + ]); + } + + public function assertSentMailNotHasStrings(array $strings): void { + foreach ($strings as $string) { + $this->assertSentMailNotHasString($string); + } + } + + public function assertSentMailNotHasString(string $string): void { + $this->assertStringNotContainsString($string, $this->sentMail[0]); + } + /** * Initial test of submit function for paid event. * @@ -557,12 +579,13 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { /** * Submit a paid event with some default values. * + * @param array $eventParams * @param array $submitValues */ - protected function submitPaidEvent(array $submitValues = []): void { + protected function submitPaidEvent(array $eventParams = [], array $submitValues = []): void { $mailUtil = new CiviMailUtils($this, TRUE); $this->dummyProcessorCreate(); - $event = $this->eventCreatePaid(['payment_processor' => [$this->ids['PaymentProcessor']['dummy_live']], 'confirm_email_text' => '', 'is_pay_later' => FALSE, 'start_date' => '2022-09-16 12:00', 'end_date' => '2022-09-17 12:00']); + $event = $this->eventCreatePaid(['payment_processor' => [$this->ids['PaymentProcessor']['dummy_live']], 'confirm_email_text' => '', 'is_pay_later' => FALSE, 'start_date' => '2022-09-16 12:00', 'end_date' => '2022-09-17 12:00'] + $eventParams); $this->submitForm($event['id'], array_merge([ 'email-Primary' => 'demo@example.com', 'credit_card_number' => '4111111111111111', diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index 194c97ecc8..f2dfe5141c 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -929,4 +929,16 @@ CheckBox + + is_show_calendar_links + Are calendar links shown? + boolean + true + 1 + If true then calendar links are shown for this event. + 5.68 + + CheckBox + + diff --git a/xml/templates/message_templates/event_offline_receipt_html.tpl b/xml/templates/message_templates/event_offline_receipt_html.tpl index 8fad146e4b..b728711482 100644 --- a/xml/templates/message_templates/event_offline_receipt_html.tpl +++ b/xml/templates/message_templates/event_offline_receipt_html.tpl @@ -134,7 +134,7 @@ {/if} {/if} - {if {event.is_public|boolean}} + {if {event.is_public|boolean} and {event.is_show_calendar_links|boolean}} {capture assign=icalFeed}{crmURL p='civicrm/event/ical' q="reset=1&id={event.id}" h=0 a=1 fe=1}{/capture} diff --git a/xml/templates/message_templates/event_online_receipt_html.tpl b/xml/templates/message_templates/event_online_receipt_html.tpl index 30b451ca27..5cbff73e50 100644 --- a/xml/templates/message_templates/event_online_receipt_html.tpl +++ b/xml/templates/message_templates/event_online_receipt_html.tpl @@ -142,7 +142,7 @@ {/if} {/if} - {if {event.is_public|boolean}} + {if {event.is_public|boolean} and {event.is_show_calendar_links|boolean}} {capture assign=icalFeed}{crmURL p='civicrm/event/ical' q="reset=1&id={event.id}" h=0 a=1 fe=1}{/capture} diff --git a/xml/templates/message_templates/event_online_receipt_text.tpl b/xml/templates/message_templates/event_online_receipt_text.tpl index 1eb6b86c06..dc06ad1a78 100644 --- a/xml/templates/message_templates/event_online_receipt_text.tpl +++ b/xml/templates/message_templates/event_online_receipt_text.tpl @@ -70,7 +70,7 @@ {if {event.loc_block_id.email_2_id.email|boolean}} {ts}Email {/ts}{event.loc_block_id.email_2_id.email}{/if} {/if} -{if {event.is_public|boolean}} +{if {event.is_public|boolean} and {event.is_show_calendar_links|boolean}} {capture assign=icalFeed}{crmURL p='civicrm/event/ical' q="reset=1&id={event.id}" h=0 a=1 fe=1}{/capture} {ts}Download iCalendar entry for this event.{/ts} {$icalFeed} {capture assign=gCalendar}{crmURL p='civicrm/event/ical' q="gCalendar=1&reset=1&id={event.id}" h=0 a=1 fe=1}{/capture} -- 2.25.1