preliminary tidy up
[civicrm-core.git] / CRM / Event / BAO / Query.php
index 7da21df5212ddd1785d04b253893497014e975e9..6137a052487f38113af5aa8275ac844ca4fc8a3f 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
@@ -24,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -56,7 +55,7 @@ class CRM_Event_BAO_Query {
   }
 
   /**
-   * Build select for CiviEvent
+   * Build select for CiviEvent.
    *
    * @param $query
    *
@@ -244,7 +243,7 @@ class CRM_Event_BAO_Query {
    */
   public static function whereClauseSingle(&$values, &$query) {
     list($name, $op, $value, $grouping, $wildcard) = $values;
-    $fields = array_merge(self::fields(), CRM_Event_BAO_Event::fields(), CRM_Event_BAO_Participant::exportableFields());
+    $fields = array_merge(CRM_Event_BAO_Event::fields(), CRM_Event_BAO_Participant::exportableFields());
 
     switch ($name) {
       case 'event_start_date_low':
@@ -297,6 +296,11 @@ class CRM_Event_BAO_Query {
         $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
         return;
 
+      case 'participant_is_test':
+        $key = array_search('civicrm_participant.is_test = 0', $query->_where[$grouping]);
+        if (!empty($key)) {
+          unset($query->_where[$grouping][$key]);
+        }
       case 'participant_test':
         // We dont want to include all tests for sql OR CRM-7827
         if (!$value || $query->getOperator() != 'OR') {
@@ -336,16 +340,18 @@ class CRM_Event_BAO_Query {
       case 'participant_source':
       case 'participant_id':
       case 'participant_contact_id':
-      case 'participant_pay_later':
+      case 'participant_is_pay_later':
       case 'participant_fee_amount':
       case 'participant_fee_level':
         $qillName = $name;
-        if (in_array($name, array('participant_status_id', 'participant_role_id', 'participant_source', 'participant_id', 'participant_contact_id', 'participant_fee_amount', 'participant_fee_level'))) {
+        if (in_array($name, array('participant_status_id', 'participant_role_id', 'participant_source', 'participant_id', 'participant_contact_id', 'participant_fee_amount', 'participant_fee_level', 'participant_is_pay_later'))) {
           $name = str_replace('participant_', '', $name);
-        }
-        if ($name == 'participant_pay_later') {
-          $name = str_replace('participant', 'is', $name);
-          $qillName = 'participant_' . $name;
+          if ($name == 'is_pay_later') {
+            $qillName = $name;
+          }
+          if ($name == 'participant_role_id') {
+            $qillName = str_replace('_id', '', $name);
+          }
         }
 
         $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
@@ -368,11 +374,17 @@ class CRM_Event_BAO_Query {
         return;
 
       case 'event_id':
+      case 'participant_event_id':
+        $name = str_replace('participant_', '', $name);
       case 'event_is_public':
       case 'event_type_id':
 
         $qillName = $name;
-        if (in_array($name, array('event_id',  'event_is_public'))) {
+        if (in_array($name, array(
+              'event_id',
+              'event_is_public',
+            )
+          )) {
           $name = str_replace('event_', '', $name);
         }
         $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
@@ -445,7 +457,7 @@ class CRM_Event_BAO_Query {
   }
 
   /**
-   * Getter for the qill object
+   * Getter for the qill object.
    *
    * @return string
    */
@@ -459,7 +471,7 @@ class CRM_Event_BAO_Query {
    *
    * @return array|null
    */
-  static function defaultReturnProperties(
+  public  static function defaultReturnProperties(
     $mode,
     $includeCustomFields = TRUE
   ) {
@@ -545,7 +557,7 @@ class CRM_Event_BAO_Query {
     );
 
     $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE);
-    $form->addYesNo('participant_pay_later', ts('Participant is Pay Later?'), TRUE);
+    $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE);
     $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
 
@@ -591,4 +603,5 @@ class CRM_Event_BAO_Query {
       $tables = array_merge(array('civicrm_participant' => 1), $tables);
     }
   }
+
 }