Simplify event title retrieval, use cache, add test
authoreileen <emcnaughton@wikimedia.org>
Mon, 20 Jan 2020 21:33:52 +0000 (10:33 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 20 Jan 2020 21:33:52 +0000 (10:33 +1300)
CRM/Event/Form/Participant.php
tests/phpunit/CRM/Event/Form/ParticipantTest.php

index 54a75290af27fe14c86c26913b82add0f4678ae6..f73ea52b24ca2ed421402f59b8ec711892aa250a 100644 (file)
@@ -1026,19 +1026,11 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     $now = date('YmdHis');
 
     if ($this->_mode) {
-
-      $eventTitle
-        = CRM_Core_DAO::getFieldValue(
-          'CRM_Event_DAO_Event',
-          $params['event_id'],
-          'title'
-        );
-
       // set source if not set
       if (empty($params['source'])) {
         $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', [
           1 => $userName,
-          2 => $eventTitle,
+          2 => $this->getEventValue('title'),
         ]);
       }
       else {
@@ -1242,13 +1234,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         }
       }
 
-      if (isset($params['event_id'])) {
-        $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
-          $params['event_id'],
-          'title'
-        );
-      }
-
       if ($this->_single) {
         $this->_contactIds[] = $this->_contactId;
       }
@@ -1273,7 +1258,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         if (!$this->_onlinePendingContributionId) {
           if (empty($params['source'])) {
             $contributionParams['source'] = ts('%1 : Offline registration (by %2)', [
-              1 => $eventTitle,
+              1 => $this->getEventValue('title'),
               2 => $userName,
             ]);
           }
index 69c720d52b0c956c0936f8b52820349fe6dcbc8a..0cc443494b88cc13c74c965d5ba484416d4d3340 100644 (file)
@@ -188,8 +188,8 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
     $form->_quickConfig = TRUE;
     $paymentProcessorID = $this->processorCreate(['is_test' => 0]);
     $form->submit($this->getSubmitParams($form->_eventId, $paymentProcessorID));
-    $participants = $this->callAPISuccess('Participant', 'get', []);
-    $this->assertEquals(1, $participants['count']);
+    $participant = $this->callAPISuccessGetSingle('Participant', []);
+    $this->assertEquals('Offline Registration for Event: Annual CiviCRM meet by: ', $participant['participant_source']);
     $contribution = $this->callAPISuccessGetSingle('Contribution', []);
     $this->assertEquals(1550.55, $contribution['total_amount']);
     $this->assertEquals('Debit Card', $contribution['payment_instrument']);