Add countFetched and countMatched outputs to API4 AJAX
[civicrm-core.git] / CRM / Api4 / Page / AJAX.php
index 64edf46f44f8039e1dab45fecacc46d6aff23373..4816ea9c97d9261c355bf6d2e3e9304ddc2d6d3a 100644 (file)
@@ -142,6 +142,12 @@ class CRM_Api4_Page_AJAX extends CRM_Core_Page {
     }
     unset($vals['rowCount']);
     $vals['count'] = $result->count();
+    $vals['countFetched'] = $result->countFetched();
+    if (in_array('row_count', $params['select'] ?? [])) {
+      // We can only return countMatched (whose value is independent of LIMIT clauses) if row_count was in the select.
+      $vals['countMatched'] = $result->count();
+    }
+
     return $vals;
   }