CRM-15932 - Major cleanup of ConfirmRepeatMode
[civicrm-core.git] / CRM / Event / Form / Search.php
index d83b0345bedd3d05cf3d63893148891590da18a4..1f6b35ca40109b0cefb1bf523eb617a77eac4c91 100644 (file)
@@ -193,16 +193,26 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
       if (count($eventIds) == 1) {
         //convert form values to clause.
         $seatClause = array();
+        if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') {
+          $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
+        }
+        if (!empty($this->_formValues['participant_status_id'])) {
+          $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', (array) $this->_formValues['participant_status_id']) . ' ) )';
+        }
+        if (!empty($this->_formValues['participant_role_id'])) {
+          $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', (array) $this->_formValues['participant_role_id']) . ' ) )';
+        }
+
         // CRM-15379
-        $clause = NULL;
         if (!empty($this->_formValues['participant_fee_id'])) {
           $participant_fee_id = $this->_formValues['participant_fee_id'];
           $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label');
           $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel));
-          $clause = " ( participant.fee_level LIKE '%$feeLabel%' ) ";
+          $seatClause[] = "( participant.fee_level LIKE '%$feeLabel%' )";
         }
 
-        $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $clause);
+        $seatClause = implode(' AND ', $seatClause);
+        $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause);
       }
       $this->assign('participantCount', $participantCount);
       $this->assign('lineItems', $lineItems);
@@ -253,12 +263,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
 
     if (!empty($_POST)) {
       $this->_formValues = $this->controller->exportValues($this->_name);
-      foreach (array('participant_status_id', 'participant_role_id') as $element) {
-        $value = CRM_Utils_Array::value($element, $this->_formValues);
-        if ($value && is_array($value)) {
-          $this->_formValues[$element] = array('IN' => $value);
-        }
-      }
     }
 
     if (empty($this->_formValues)) {
@@ -386,14 +390,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 0");
       }
       elseif (is_numeric($status)) {
-        $status = (int) $status;
-        $statusTypes = array($status => CRM_Event_PseudoConstant::participantStatus($status));
+        $statusTypes = (int) $status;
       }
-      $status = array();
-      foreach ($statusTypes as $key => $value) {
-        $status[$key] = 1;
-      }
-      $this->_formValues['participant_status_id'] = $status;
+      $this->_formValues['participant_status_id'] = is_array($statusTypes) ? array_keys($statusTypes) : $statusTypes;
     }
 
     $role = CRM_Utils_Request::retrieve('role', 'String',
@@ -408,14 +407,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
         $roleTypes = CRM_Event_PseudoConstant::participantRole(NULL, "filter = 0");
       }
       elseif (is_numeric($role)) {
-        $role = (int) $role;
-        $roleTypes = array($role => CRM_Event_PseudoConstant::participantRole($role));
-      }
-      $role = array();
-      foreach ($roleTypes as $key => $value) {
-        $role[$key] = 1;
+        $roleTypes = (int) $role;
       }
-      $this->_formValues['participant_role_id'] = $role;
+      $this->_formValues['participant_role_id'] = is_array($roleTypes) ? array_keys($roleTypes) : $roleTypes;
     }
 
     $type = CRM_Utils_Request::retrieve('type', 'Positive',