Convert register_date to datepicker
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Fri, 19 Oct 2018 18:11:08 +0000 (19:11 +0100)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Tue, 23 Oct 2018 21:24:37 +0000 (22:24 +0100)
CRM/Event/Form/Participant.php
templates/CRM/Event/Form/Participant.tpl
tests/phpunit/CRM/Event/Form/ParticipantTest.php

index ec7863ccac2a4982ac34282bd8dda7febc9c161a..3d4e75ddb70f69e2fb25bcf1f898721605a06995 100644 (file)
@@ -213,6 +213,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    * Set variables up before form is built.
    *
    * @return void
+   * @throws \CRM_Core_Exception
    */
   public function preProcess() {
     parent::preProcess();
@@ -420,8 +421,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    * This function sets the default values for the form in edit/view mode
    * the default values are retrieved from the database
    *
-   *
-   * @return void
+   * @return array
+   * @throws \CRM_Core_Exception
    */
   public function setDefaultValues() {
     if ($this->_showFeeBlock) {
@@ -467,15 +468,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
     }
 
-    if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
-      $inactiveNeeded = TRUE;
-      $viewMode = TRUE;
-    }
-    else {
-      $viewMode = FALSE;
-      $inactiveNeeded = FALSE;
-    }
-
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
       $statuses = array_flip(CRM_Event_PseudoConstant::participantStatus());
@@ -513,6 +505,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       if (!empty($submittedEvent[0])) {
         $eventID = $submittedEvent[0];
       }
+      $defaults[$this->_id]['register_date'] = date('Y-m-d H:i:s');
     }
     else {
       $defaults[$this->_id]['record_contribution'] = 0;
@@ -532,9 +525,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
     }
 
-    list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time'])
-      = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime');
-
     //assign event and role id, this is needed for Custom data building
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     if (!empty($defaults[$this->_id]['participant_role_id'])) {
@@ -586,6 +576,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    * Build the form object.
    *
    * @return void
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function buildQuickForm() {
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
@@ -680,8 +672,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
-
-    $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
+    $this->add('datepicker', 'register_date', ts('Registration Date'), [], TRUE, array('time' => TRUE));
 
     if ($this->_id) {
       $this->assign('entityID', $this->_id);
@@ -780,7 +771,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   /**
    * Add local and global form rules.
    *
-   *
    * @return void
    */
   public function addRules() {
@@ -972,7 +962,9 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    *
    * @param array $params
    *
-   * @return array
+   * @return string
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function submit($params) {
     $participantStatus = CRM_Event_PseudoConstant::participantStatus();
@@ -1027,12 +1019,9 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
       else {
 
-        //check if discount is selected
-        if (!empty($params['discount_id'])) {
-          $discountId = $params['discount_id'];
-        }
-        else {
-          $discountId = $params['discount_id'] = 'null';
+        // check that discount_id is set
+        if (empty($params['discount_id'])) {
+          $params['discount_id'] = 'null';
         }
 
         //lets carry currency, CRM-4453
@@ -1100,8 +1089,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       $amountOwed = $params['amount'];
       unset($params['amount']);
     }
-    $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
-    $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params), CRM_Utils_Array::value('receive_date_time', $params));
     $params['contact_id'] = $this->_contactId;
 
     // overwrite actual payment amount if entered
@@ -1123,6 +1110,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     $this->_params['participant_register_date'] = $params['register_date'];
     $roleIdWithSeparator = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['participant_role_id']);
 
+    $now = date('YmdHis');
+
     if ($this->_mode) {
       if (!$this->_isPaidEvent) {
         CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
@@ -1150,7 +1139,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'],
         $this->_mode
       );
-      $now = date('YmdHis');
       $fields = array();
 
       // set email for primary location.
@@ -1273,9 +1261,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
       $this->set('params', $this->_params);
       $this->assign('trxn_id', $result['trxn_id']);
-      $this->assign('receive_date',
-        CRM_Utils_Date::processDate($this->_params['receive_date'])
-      );
+      $this->assign('receive_date', $this->_params['receive_date']);
 
       //add contribution record
       $this->_params['financial_type_id']
@@ -1387,8 +1373,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         $contributionParams['non_deductible_amount'] = 'null';
         $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
         $contributionParams['contact_id'] = $this->_contactID;
-        // @todo change receive_date to datepicker field. Strip out all wrangling.
-        $contributionParams['receive_date'] = $params['receive_date'];
+        $contributionParams['receive_date'] = CRM_Utils_Array::value('receive_date', $params, 'null');
 
         $recordContribution = array(
           'financial_type_id',
@@ -1623,7 +1608,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       }
 
       $this->assign('register_date', $params['register_date']);
-      if ($params['receive_date']) {
+      if (isset($params['receive_date'])) {
         $this->assign('receive_date', $params['receive_date']);
       }
 
@@ -1633,7 +1618,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         $participant[] = array('participant_test', '=', 1, 0, 0);
       }
 
-      $template = CRM_Core_Smarty::singleton();
       $customGroup = array();
       //format submitted data
       foreach ($params['custom'] as $fieldID => $values) {
index 3fb2212b7b326949546088a627f4d6c411571c79..df55a17d2f944c615373669aa802255441f735d5 100644 (file)
           </tr>
           <tr class="crm-participant-form-block-register_date">
             <td class="label">{$form.register_date.label}</td>
-            <td>
-              {if $hideCalendar neq true}
-                    {include file="CRM/common/jcalendar.tpl" elementName=register_date}
-                  {else}
-                    {$form.register_date.value|crmDate}
-                  {/if}
-            </td>
+            <td>{$form.register_date.html}</td>
           </tr>
           <tr class="crm-participant-form-block-status_id">
             <td class="label">{$form.status_id.label}</td>
index 90fc34bbffbfce58945d7a15b86ca24f752d61f8..4ed8844c0f5ccccaa28c97e7d87e82ca1c855d80 100644 (file)
@@ -21,8 +21,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
   public function testSubmit() {
     $form = $this->getForm();
     $form->submit(array(
-      'register_date' => 'now',
-      'register_date_time' => '00:00:00',
+      'register_date' => date('Ymd'),
       'status_id' => 1,
       'role_id' => 1,
       'event_id' => $form->_eventId,
@@ -36,7 +35,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
    *
    * @throws \Exception
    */
-  public function testSubmitUpaidPriceChangeWhileStillPending() {
+  public function testSubmitUnpaidPriceChangeWhileStillPending() {
     $form = $this->getForm(array('is_monetary' => 1, 'financial_type_id' => 1));
     $form->_quickConfig = TRUE;
 
@@ -66,8 +65,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
     $form->setAction(CRM_Core_Action::ADD);
     $form->_priceSetId = $this->_ids['price_set'];
     $form->submit(array(
-      'register_date' => 'now',
-      'register_date_time' => '00:00:00',
+      'register_date' => date('Ymd'),
       'status_id' => 5,
       'role_id' => 1,
       'event_id' => $form->_eventId,
@@ -135,8 +133,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
       'from_email_id' => array('abc@gmail.com' => 1),
     );
     $form->submit(array(
-      'register_date' => 'now',
-      'register_date_time' => '00:00:00',
+      'register_date' => date('Ymd'),
       'status_id' => 1,
       'role_id' => 1,
       'event_id' => $form->_eventId,