dev/core/issues/708, Fix Qill for Added by and Modified By
[civicrm-core.git] / CRM / Contact / BAO / Query.php
index 4f8a2ac69afb4601e79b5490ccc3d3a9cbde2b13..3c99db2d6a58ce2a766d068c65d66b1729753acc 100644 (file)
@@ -2039,6 +2039,18 @@ class CRM_Contact_BAO_Query {
         // check for both id and contact_id
         if ($this->_params[$id][0] == 'id' || $this->_params[$id][0] == 'contact_id') {
           $this->_where[0][] = self::buildClause("contact_a.id", $this->_params[$id][1], $this->_params[$id][2]);
+          $field = CRM_Utils_Array::value('id', $this->_fields);
+          list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(
+            'CRM_Contact_BAO_Contact',
+            "contact_a.id",
+            $this->_params[$id][2],
+            $this->_params[$id][1]
+          );
+          $this->_qill[0][] = ts("%1 %2 %3", [
+            1 => $field['title'],
+            2 => $qillop,
+            3 => $qillVal
+          ]);
         }
         else {
           $this->whereClauseSingle($this->_params[$id], $apiEntity);
@@ -3887,7 +3899,21 @@ WHERE  $smartGroupClause
     $name = $targetName[4] ? "%$name%" : $name;
     $this->_where[$grouping][] = "contact_b_log.sort_name LIKE '%$name%'";
     $this->_tables['civicrm_log'] = $this->_whereTables['civicrm_log'] = 1;
-    $this->_qill[$grouping][] = ts('Modified By') . " $name";
+    $fieldTitle = ts('Added By');
+    foreach ($this->_params as $params) {
+      if ($params[0] == 'log_date') {
+        if ($params[2] == 2) {
+          $fieldTitle = ts('Modified By');
+        }
+        break;
+      }
+    }
+    list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, 'changed_by', $name, 'LIKE');
+    $this->_qill[$grouping][] = ts("%1 %2 %3", [
+      1 => $fieldTitle,
+      2 => $qillop,
+      3 => $qillVal,
+    ]);
   }
 
   /**
@@ -4904,7 +4930,7 @@ civicrm_relationship.start_date > {$today}
     //      MySQL expect the columns present in GROUP BY, must be present in SELECT clause and that results into error, needless to have other columns.
     //   2. When GROUP BY columns are present then disable FGB otherwise it demands to add ORDER BY columns in GROUP BY and eventually in SELECT
     //     clause. This will impact the search query output.
-    $disableFullGroupByMode = ($sortByChar || !empty($groupByCols));
+    $disableFullGroupByMode = ($sortByChar || !empty($groupByCols) || $groupContacts);
 
     if ($disableFullGroupByMode) {
       CRM_Core_DAO::disableFullGroupByMode();