Merge pull request #15870 from eileenmcnaughton/init_set
[civicrm-core.git] / CRM / Event / Form / EventFees.php
index f4caf280f5ac2e23211603a6716cb2591fe20063..0910640104bb49c8bb6694e92e2bb589808a6dc0 100644 (file)
@@ -1,27 +1,11 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
- |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
@@ -29,7 +13,7 @@
  *
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
 /**
@@ -71,12 +55,12 @@ class CRM_Event_Form_EventFees {
    * @return array
    */
   public static function setDefaultValues(&$form) {
-    $defaults = array();
+    $defaults = [];
 
     if ($form->_eventId) {
       //get receipt text and financial type
-      $returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date');
-      $details = array();
+      $returnProperities = ['confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date'];
+      $details = [];
       CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
       if (!empty($details[$form->_eventId]['financial_type_id'])) {
         $defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
@@ -84,12 +68,12 @@ class CRM_Event_Form_EventFees {
     }
 
     if ($form->_pId) {
-      $ids = array();
-      $params = array('id' => $form->_pId);
+      $ids = [];
+      $params = ['id' => $form->_pId];
 
       CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
       if ($form->_action == CRM_Core_Action::UPDATE) {
-        $discounts = array();
+        $discounts = [];
         if (!empty($form->_values['discount'])) {
           foreach ($form->_values['discount'] as $key => $value) {
             $value = current($value);
@@ -173,11 +157,11 @@ class CRM_Event_Form_EventFees {
     if ($priceSetId) {
       // get price set default values, CRM-4090
       if (in_array(get_class($form),
-        array(
+        [
           'CRM_Event_Form_Participant',
           'CRM_Event_Form_Registration_Register',
           'CRM_Event_Form_Registration_AdditionalParticipant',
-        )
+        ]
       )) {
         $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
         if (!empty($priceSetValues)) {
@@ -224,13 +208,13 @@ class CRM_Event_Form_EventFees {
       $contribution = new CRM_Contribute_DAO_Contribution();
       $contribution->id = $contriId;
       $contribution->find(TRUE);
-      foreach (array(
-                 'financial_type_id',
-                 'payment_instrument_id',
-                 'contribution_status_id',
-                 'receive_date',
-                 'total_amount',
-               ) as $f) {
+      foreach ([
+        'financial_type_id',
+        'payment_instrument_id',
+        'contribution_status_id',
+        'receive_date',
+        'total_amount',
+      ] as $f) {
         $defaults[$form->_pId][$f] = $contribution->$f;
       }
     }
@@ -247,7 +231,7 @@ class CRM_Event_Form_EventFees {
    * @return array
    */
   public static function setDefaultPriceSet($participantID, $eventID = NULL, $includeQtyZero = TRUE) {
-    $defaults = array();
+    $defaults = [];
     if (!$eventID && $participantID) {
       $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'event_id');
     }
@@ -268,7 +252,7 @@ class CRM_Event_Form_EventFees {
       !CRM_Utils_System::isNull($lineItems[$participantID])
     ) {
 
-      $priceFields = $htmlTypes = $optionValues = array();
+      $priceFields = $htmlTypes = $optionValues = [];
       foreach ($lineItems[$participantID] as $lineId => $items) {
         $priceFieldId = CRM_Utils_Array::value('price_field_id', $items);
         $priceOptionId = CRM_Utils_Array::value('price_field_value_id', $items);
@@ -338,7 +322,7 @@ SELECT  id, html_type
       // make sure this is for backoffice registration.
       if ($form->getName() == 'Participant') {
         $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
-        $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
+        $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, ['id' => 'hidden_eventFullMsg']);
       }
     }
 
@@ -347,19 +331,19 @@ SELECT  id, html_type
         $form->_pId, 'contribution_id', 'participant_id'
       )
       ) {
-        $form->_online = TRUE;
+        $form->_online = !$form->isBackOffice;
       }
     }
 
     if ($form->_isPaidEvent) {
-      $params = array('id' => $form->_eventId);
+      $params = ['id' => $form->_eventId];
       CRM_Event_BAO_Event::retrieve($params, $event);
 
       //retrieve custom information
-      $form->_values = array();
+      $form->_values = [];
       CRM_Event_Form_Registration::initEventFee($form, $event['id']);
       CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
-      $lineItem = array();
+      $lineItem = [];
       $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
       $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
       $totalTaxAmount = 0;
@@ -373,7 +357,7 @@ SELECT  id, html_type
         $form->assign('totalTaxAmount', $totalTaxAmount);
       }
       $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
-      $discounts = array();
+      $discounts = [];
       if (!empty($form->_values['discount'])) {
         foreach ($form->_values['discount'] as $key => $value) {
           $value = current($value);
@@ -382,11 +366,11 @@ SELECT  id, html_type
 
         $element = $form->add('select', 'discount_id',
           ts('Discount Set'),
-          array(
+          [
             0 => ts('- select -'),
-          ) + $discounts,
+          ] + $discounts,
           FALSE,
-          array('class' => "crm-select2")
+          ['class' => "crm-select2"]
         );
 
         if ($form->_online) {
@@ -404,7 +388,7 @@ SELECT  id, html_type
       CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE, self::getDefaultPaymentInstrumentId());
       if (!$form->_mode) {
         $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL,
-          array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);")
+          ['onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"]
         );
         // Check permissions for financial type first
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
@@ -416,15 +400,15 @@ SELECT  id, html_type
 
         $form->add('select', 'financial_type_id',
           ts('Financial Type'),
-          array('' => ts('- select -')) + $financialTypes
+          ['' => ts('- select -')] + $financialTypes
         );
 
-        $form->add('datepicker', 'receive_date', ts('Received'), array(), FALSE, array('time' => TRUE));
+        $form->add('datepicker', 'receive_date', ts('Received'), [], FALSE, ['time' => TRUE]);
 
         $form->add('select', 'payment_instrument_id',
           ts('Payment Method'),
-          array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
-          FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
+          ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::paymentInstrument(),
+          FALSE, ['onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"]
         );
         // don't show transaction id in batch update mode
         $path = CRM_Utils_System::currentPath();
@@ -432,7 +416,7 @@ SELECT  id, html_type
         if ($path != 'civicrm/contact/search/basic') {
           $form->add('text', 'trxn_id', ts('Transaction ID'));
           $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'),
-            'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id')
+            'objectExists', ['CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id']
           );
           $form->assign('showTransactionId', TRUE);
         }
@@ -460,7 +444,7 @@ SELECT  id, html_type
     $form->addElement('checkbox',
       'send_receipt',
       ts('Send Confirmation?'), NULL,
-      array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);")
+      ['onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"]
     );
 
     $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);