Fixed fatal error for Event Participants custom search if price set field option...
authorPradeep Nayak <pradpnayak@gmail.com>
Sat, 11 May 2019 09:30:36 +0000 (10:30 +0100)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 25 Mar 2020 00:15:33 +0000 (11:15 +1100)
Fix test failure and parametise queries

CRM/Contact/Form/Search/Custom/PriceSet.php

index 740d8a35e83aa095f34235169b26f972ab19ca58..56f5c5e53c387cbf63afe1f4cb8f6206e186d0cc 100644 (file)
@@ -87,28 +87,33 @@ FROM   civicrm_contact c,
        civicrm_participant p
 WHERE  p.contact_id = c.id
   AND  p.is_test    = 0
-  AND  p.event_id = {$this->_eventID}
+  AND  p.event_id = %1
   AND  p.status_id NOT IN (4,11,12)
   AND  ( c.is_deleted = 0 OR c.is_deleted IS NULL )
 ";
-    CRM_Core_DAO::executeQuery($sql);
+    CRM_Core_DAO::executeQuery($sql, [1 => [$this->_eventID, 'Positive']]);
 
     $sql = "
-SELECT c.id as contact_id,
-       p.id as participant_id,
-       l.price_field_value_id as price_field_value_id,
-       l.qty
-FROM   civicrm_contact c,
-       civicrm_participant  p,
-       civicrm_line_item    l
-WHERE  c.id = p.contact_id
-AND    p.event_id = {$this->_eventID}
-AND    p.id = l.entity_id
-AND    l.entity_table ='civicrm_participant'
-ORDER BY c.id, l.price_field_value_id;
-";
-
-    $dao = CRM_Core_DAO::executeQuery($sql);
+      SELECT c.id as contact_id,
+        p.id as participant_id,
+        l.price_field_value_id AS price_field_value_id,
+        l.qty
+      FROM civicrm_contact c
+        INNER JOIN civicrm_participant p
+          ON p.contact_id = c.id AND c.is_deleted = 0
+        INNER JOIN civicrm_line_item l
+          ON p.id = l.entity_id AND l.entity_table ='civicrm_participant'
+        INNER JOIN civicrm_price_field_value cpfv
+          ON cpfv.id = l.price_field_value_id AND cpfv.is_active = 1
+        INNER JOIN civicrm_price_field cpf
+          ON cpf.id = l.price_field_id AND cpf.is_active = 1
+        INNER JOIN civicrm_price_set cps
+          ON cps.id = cpf.price_set_id AND cps.is_active = 1
+      WHERE  p.event_id = %1
+      ORDER BY c.id, l.price_field_value_id;
+    ";
+
+    $dao = CRM_Core_DAO::executeQuery($sql, [1 => [$this->_eventID, 'Positive']]);
 
     // first store all the information by option value id
     $rows = [];