Add option to control display of calendar links
authorAidan Saunders <aidan.saunders@squiffle.uk>
Tue, 10 Oct 2023 17:28:40 +0000 (18:28 +0100)
committerAidan Saunders <aidan.saunders@squiffle.uk>
Wed, 8 Nov 2023 17:31:28 +0000 (17:31 +0000)
12 files changed:
CRM/Event/DAO/Event.php
CRM/Event/Form/ManageEvent/EventInfo.php
CRM/Event/Tokens.php
CRM/Upgrade/Incremental/php/FiveSixtyNine.php
templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
templates/CRM/Event/Form/Registration/ThankYou.tpl
templates/CRM/Event/Page/EventInfo.tpl
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
xml/schema/Event/Event.xml
xml/templates/message_templates/event_offline_receipt_html.tpl
xml/templates/message_templates/event_online_receipt_html.tpl
xml/templates/message_templates/event_online_receipt_text.tpl

index e1bc30cb40e101014fe4a15e2096211b6b31f469..4d09de0d5721f3d4b19c04a1f57346246666ccc7 100644 (file)
@@ -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']);
     }
index dd1009bca4acef83d0bedf3caa80a8368c06ecb0..82a28c5e66f2cd1fd1d190678edb83584666f5c6 100644 (file)
@@ -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
index ed4f8066560628437b4c6298c6c911b25a029406..35b653b3a66dc5d7818814190ecea85c789161e6 100644 (file)
@@ -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'],
     ];
   }
index 1b924ccf58b51dd36e50d57e8c81d680f6bc999a..0c3422ce31480bd9a7013a18350fafe7625c32bf 100644 (file)
@@ -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"');
   }
 
 }
index 9bfff190ccaea48de54df714a71c867581d073c7..326ef4aa007b60d6c8f89121df4bfc03af7891f6 100644 (file)
       <td>&nbsp;</td>
       <td>{$form.is_active.html} {$form.is_active.label}</td>
     </tr>
+    <tr class="crm-event-manage-eventinfo-form-block-is_show_calendar_links">
+      <td>&nbsp;</td>
+      <td>{$form.is_show_calendar_links.html} {$form.is_show_calendar_links.label}</td>
+    </tr>
 
     {if $eventID AND !$isTemplate}
       <tr class="crm-event-manage-eventinfo-form-block-info_link">
index 14fe56cfa54253e4718aaecf8a84c7ee6a508fec..d90910595e712cad0f802532ce04a96330f9161b 100644 (file)
         <a href="{crmURL p='civicrm/event/info' q="reset=1&id=`$event.id`"}"><i class="crm-i fa-chevron-left" aria-hidden="true"></i> {ts 1=$event.event_title}Back to "%1" event information{/ts}</a>
     </div>
 
-    {if $event.is_public}
+    {if $event.is_public and $event.is_show_calendar_links}
       <div class="action-link section iCal_links-section">
         {include file="CRM/Event/Page/iCalLinks.tpl"}
       </div>
     {/if}
     {if $event.is_share}
-    {capture assign=eventUrl}{crmURL p='civicrm/event/info' q="id=`$event.id`&amp;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`&amp;reset=1" a=1 fe=1 h=1}{/capture}
+      {include file="CRM/common/SocialNetwork.tpl" url=$eventUrl title=$event.title pageURL=$eventUrl}
     {/if}
 </div>
index 4d0975257808bf2fef857fae0af121b9ba5a40f2..ed71354dc4bd30a1b132bc01f2501a468a2c3072 100644 (file)
         {/if}
       {/crmRegion}
     </div>
-    {if $event.is_public}
+    {if $event.is_public and $event.is_show_calendar_links}
         <div class="action-link section iCal_links-section">
           {include file="CRM/Event/Page/iCalLinks.tpl"}
         </div>
index b01d35b706af1f73172ea46527c977ad0c4afc38..7ccd71382cc92c6810d0f8a54500a08d3a387bdd 100644 (file)
@@ -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',
index 194c97ecc8176d6932041e7af5f95a65755c4fc3..f2dfe5141c5ba5c416c27cf51272ca7d36f0f301 100644 (file)
       <type>CheckBox</type>
     </html>
   </field>
+  <field>
+    <name>is_show_calendar_links</name>
+    <title>Are calendar links shown?</title>
+    <type>boolean</type>
+    <required>true</required>
+    <default>1</default>
+    <comment>If true then calendar links are shown for this event.</comment>
+    <add>5.68</add>
+    <html>
+      <type>CheckBox</type>
+    </html>
+  </field>
 </table>
index 8fad146e4b9469b79a330bf8f17e8d683704e8f1..b72871148258dffadd544035cb1ce48f1dae0a71 100644 (file)
        {/if}
      {/if}
 
-     {if {event.is_public|boolean}}
+     {if {event.is_public|boolean} and {event.is_show_calendar_links|boolean}}
       <tr>
        <td colspan="2" {$valueStyle}>
         {capture assign=icalFeed}{crmURL p='civicrm/event/ical' q="reset=1&id={event.id}" h=0 a=1 fe=1}{/capture}
index 30b451ca2754dbb284f94545de54d43462370649..5cbff73e5024fdf3ad9c6b53df6e6f8f335960f5 100644 (file)
           {/if}
         {/if}
 
-        {if {event.is_public|boolean}}
+        {if {event.is_public|boolean} and {event.is_show_calendar_links|boolean}}
           <tr>
             <td colspan="2" {$valueStyle}>
               {capture assign=icalFeed}{crmURL p='civicrm/event/ical' q="reset=1&id={event.id}" h=0 a=1 fe=1}{/capture}
index 1eb6b86c0691d369265cb505b9f8dcf44b39252f..dc06ad1a78fdbfa54e06b58358e5df438d2a7d1c 100644 (file)
@@ -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}