4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace Civi\Api4\Generic
;
24 use Civi\Api4\Query\Api4SelectQuery
;
27 * Retrieve $ENTITIES based on criteria specified in the `where` parameter.
29 * Use the `select` param to determine which fields are returned, defaults to `[*]`.
31 * Perform joins on other related entities using a dot notation.
33 * @method $this setHaving(array $clauses)
34 * @method array getHaving()
36 class DAOGetAction
extends AbstractGetAction
{
37 use Traits\DAOActionTrait
;
40 * Fields to return. Defaults to all non-custom fields `[*]`.
42 * Use the dot notation to perform joins in the select clause, e.g. selecting `['*', 'contact.*']` from `Email::get()`
43 * will select all fields for the email + all fields for the related contact.
48 protected $select = [];
51 * Field(s) by which to group the results.
55 protected $groupBy = [];
58 * Clause for filtering results after grouping and filters are applied.
60 * Each expression should correspond to an item from the SELECT array.
64 protected $having = [];
66 public function _run(Result
$result) {
67 $this->setDefaultWhereClause();
68 $this->expandSelectClauseWildcards();
69 $result->exchangeArray($this->getObjects());
75 protected function getObjects() {
76 $query = new Api4SelectQuery($this);
78 $result = $query->run();
79 if (is_array($result)) {
80 \CRM_Utils_API_HTMLInputCoder
::singleton()->decodeRows($result);
88 public function getGroupBy(): array {
89 return $this->groupBy
;
93 * @param array $groupBy
96 public function setGroupBy(array $groupBy) {
97 $this->groupBy
= $groupBy;
102 * @param string $field
105 public function addGroupBy(string $field) {
106 $this->groupBy
[] = $field;
111 * @param string $expr
113 * @param mixed $value
115 * @throws \API_Exception
117 public function addHaving(string $expr, string $op, $value = NULL) {
118 if (!in_array($op, \CRM_Core_DAO
::acceptedSQLOperators())) {
119 throw new \
API_Exception('Unsupported operator');
121 $this->having
[] = [$expr, $op, $value];