Move the participantCount logic to the template
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 1 Oct 2023 21:57:15 +0000 (10:57 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 1 Oct 2023 21:57:15 +0000 (10:57 +1300)
CRM/Contribute/WorkflowMessage/ContributionTrait.php
CRM/Event/WorkflowMessage/ParticipantTrait.php
xml/templates/message_templates/event_offline_receipt_html.tpl

index 81e32f49b42362874eadd9b4cacf540842fe7ac5..b7baed4edb37a53beee215811377c1f345c15536 100644 (file)
@@ -30,6 +30,18 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
    */
   public $isShowTax;
 
+  /**
+   * Is it a good idea to show the line item subtotal.
+   *
+   * This would be true if at least one line has a quantity > 1.
+   * Otherwise it is very repetitive.
+   *
+   * @var bool
+   *
+   * @scope tplParams
+   */
+  public $isShowLineSubtotal;
+
   /**
    * Line items associated with the contribution.
    *
@@ -109,6 +121,25 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
       return FALSE;
     }
     return !$this->order->getPriceSetMetadata()['is_quick_config'];
+    return $this->isShowLineItems;
+  }
+
+  /**
+   * Is it a good idea to show the line item subtotal.
+   *
+   * This would be true if at least one line has a quantity > 1.
+   * Otherwise it is very repetitive.
+   *
+   * @return bool
+   * @throws \CRM_Core_Exception
+   */
+  public function getIsShowLineSubtotal(): bool {
+    foreach ($this->getLineItems() as $lineItem) {
+      if ((int) $lineItem['qty'] > 1) {
+        return TRUE;
+      }
+    }
+    return FALSE;
   }
 
   /**
index 92d5409c3a55ba373743dda5d2f97ac4d75b581c..a25d5ac04521c4bb0517b7c847983f4f015b5300 100644 (file)
@@ -37,6 +37,19 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait {
    */
   public $isPrimary;
 
+  /**
+   * Should a participant count column be shown.
+   *
+   * This would be true if there is a line item on the receipt
+   * with more than one participant in it. Otherwise it's confusing to
+   * show.
+   *
+   * @var bool
+   *
+   * @scope tplParams as isShowParticipantCount
+   */
+  public $isShowParticipantCount;
+
   /**
    * @var int
    *
@@ -152,7 +165,26 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait {
   }
 
   /**
-   * Set contribution object.
+   * It is a good idea to show the participant count column.
+   *
+   * This would be true if there is a line item on the receipt
+   * with more than one participant in it. Otherwise it's confusing to
+   * show.
+   *
+   * @return bool
+   * @throws \CRM_Core_Exception
+   */
+  public function getIsShowParticipantCount(): bool {
+    foreach ($this->getLineItems() as $lineItem) {
+      if ((int) $lineItem['participant_count'] > 1) {
+        return TRUE;
+      }
+    }
+    return FALSE;
+  }
+
+  /**
+   * Set participant object.
    *
    * @param array $participant
    *
index 2226410129cdbf213d1d4a067d3af4bd4266f052..68b1b1ea32879c35903523cc4be4b6d586d2bcd9 100644 (file)
 
 
      {if {event.is_monetary|boolean}}
-
       <tr>
         <th {$headerStyle}>
             {event.fee_label}
                         <th>{ts}Tax Amount{/ts}</th>
                       {/if}
                       <th>{ts}Total{/ts}</th>
-                        {if !empty($pricesetFieldsCount)}
+                        {if $iShowParticipantCount}
                           <th>{ts}Total Participants{/ts}</th>
                         {/if}
                     </tr>
                         <td {$tdStyle}>
                             {$line.line_total+$line.tax_amount|crmMoney:$currency}
                         </td>
-                        {if !empty($pricesetFieldsCount)}
+                        {if $isShowParticipantCount}
                           <td {$tdStyle}>{$line.participant_count}</td>
                         {/if}
                       </tr>
               {contribution.total_amount} {if !empty($hookDiscount.message)}({$hookDiscount.message}){/if}
             </td>
           </tr>
-          {if !empty($pricesetFieldsCount)}
+          {if $isShowParticipantCount}
             <tr>
-              <td {$labelStyle}>
-                  {ts}Total Participants{/ts}</td>
-              <td {$valueStyle}>
-                  {assign var="count" value= 0}
-                  {foreach from=$lineItem item=pcount}
-                      {assign var="lineItemCount" value=0}
-                      {if $pcount neq 'skip'}
-                          {foreach from=$pcount item=p_count}
-                              {assign var="lineItemCount" value=$lineItemCount+$p_count.participant_count}
-                          {/foreach}
-                          {if $lineItemCount < 1}{assign var="lineItemCount" value=1}
-                          {/if}
-                          {assign var="count" value=$count+$lineItemCount}
-                      {/if}
-                  {/foreach}
-                  {$count}
-              </td>
+              <td {$labelStyle}>{ts}Total Participants{/ts}</td>
+              <td {$valueStyle}>{$line.participant_count}</td>
             </tr>
           {/if}
           {if {contribution.is_pay_later|boolean} && {contribution.balance_amount|boolean}}