Merge pull request #23470 from eileenmcnaughton/import_dataform
[civicrm-core.git] / Civi / Api4 / Generic / DAOGetAction.php
index f374047486b853dea3bf37222471b2999a097f0a..0c33d2acc0bf8a34b19c33727df4a89d320b87ed 100644 (file)
@@ -29,9 +29,11 @@ class DAOGetAction extends AbstractGetAction {
   use Traits\DAOActionTrait;
 
   /**
-   * Fields to return. Defaults to all non-custom fields `['*']`.
+   * Fields to return. Defaults to all standard (non-custom, non-extra) fields `['*']`.
    *
-   * The keyword `"custom.*"` selects all custom fields. So to select all core + custom fields, select `['*', 'custom.*']`.
+   * The keyword `"custom.*"` selects all custom fields (except those belonging to multi-record custom field sets). So to select all standard + custom fields, select `['*', 'custom.*']`.
+   *
+   * Multi-record custom field sets are represented as their own entity, so join to that entity to get those custom fields.
    *
    * Use the dot notation to perform joins in the select clause, e.g. selecting `['*', 'contact.*']` from `Email::get()`
    * will select all fields for the email + all fields for the related contact.
@@ -107,22 +109,47 @@ class DAOGetAction extends AbstractGetAction {
     $onlyCount = $this->getSelect() === ['row_count'];
 
     if (!$onlyCount) {
+      // Typical case: fetch various fields.
       $query = new Api4SelectQuery($this);
       $rows = $query->run();
       \CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($rows);
       $result->exchangeArray($rows);
+
       // No need to fetch count if we got a result set below the limit
       if (!$this->getLimit() || count($rows) < $this->getLimit()) {
-        $result->rowCount = count($rows) + $this->getOffset();
-        $getCount = FALSE;
+        if ($getCount) {
+          $result->setCountMatched(count($rows) + $this->getOffset());
+          $getCount = FALSE;
+        }
+        else {
+          // Set rowCount for backward compatibility.
+          $result->rowCount = count($rows) + $this->getOffset();
+        }
       }
     }
+
     if ($getCount) {
       $query = new Api4SelectQuery($this);
-      $result->rowCount = $query->getCount();
+      $result->setCountMatched($query->getCount());
     }
   }
 
+  /**
+   * @param string $fieldName
+   * @param string $op
+   * @param mixed $value
+   * @param bool $isExpression
+   * @return $this
+   * @throws \API_Exception
+   */
+  public function addWhere(string $fieldName, string $op, $value = NULL, bool $isExpression = FALSE) {
+    if (!in_array($op, CoreUtil::getOperators())) {
+      throw new \API_Exception('Unsupported operator');
+    }
+    $this->where[] = [$fieldName, $op, $value, $isExpression];
+    return $this;
+  }
+
   /**
    * @return array
    */