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
20 namespace Civi\Api4\Generic
;
22 use Civi\Api4\Query\Api4SelectQuery
;
25 * Retrieve $ENTITIES based on criteria specified in the `where` parameter.
27 * Use the `select` param to determine which fields are returned, defaults to `[*]`.
29 * Perform joins on other related entities using a dot notation.
31 * @method $this setHaving(array $clauses)
32 * @method array getHaving()
34 class DAOGetAction
extends AbstractGetAction
{
35 use Traits\DAOActionTrait
;
38 * Fields to return. Defaults to all non-custom fields `[*]`.
40 * Use the dot notation to perform joins in the select clause, e.g. selecting `['*', 'contact.*']` from `Email::get()`
41 * will select all fields for the email + all fields for the related contact.
46 protected $select = [];
49 * Joins to other entities.
56 * Field(s) by which to group the results.
60 protected $groupBy = [];
63 * Clause for filtering results after grouping and filters are applied.
65 * Each expression should correspond to an item from the SELECT array.
69 protected $having = [];
71 public function _run(Result
$result) {
72 $this->setDefaultWhereClause();
73 $this->expandSelectClauseWildcards();
74 $result->exchangeArray($this->getObjects());
80 protected function getObjects() {
81 $query = new Api4SelectQuery($this);
83 $result = $query->run();
84 if (is_array($result)) {
85 \CRM_Utils_API_HTMLInputCoder
::singleton()->decodeRows($result);
93 public function getGroupBy(): array {
94 return $this->groupBy
;
98 * @param array $groupBy
101 public function setGroupBy(array $groupBy) {
102 $this->groupBy
= $groupBy;
107 * @param string $field
110 public function addGroupBy(string $field) {
111 $this->groupBy
[] = $field;
116 * @param string $expr
118 * @param mixed $value
120 * @throws \API_Exception
122 public function addHaving(string $expr, string $op, $value = NULL) {
123 if (!in_array($op, \CRM_Core_DAO
::acceptedSQLOperators())) {
124 throw new \
API_Exception('Unsupported operator');
126 $this->having
[] = [$expr, $op, $value];
131 * @param string $entity
132 * @param bool $required
133 * @param array ...$conditions
134 * @return DAOGetAction
136 public function addJoin(string $entity, bool $required = FALSE, ...$conditions): DAOGetAction
{
137 array_unshift($conditions, $entity, $required);
138 $this->join
[] = $conditions;
144 * @return DAOGetAction
146 public function setJoin(array $join): DAOGetAction
{
154 public function getJoin(): array {