Merge pull request #16901 from eileenmcnaughton/settings
[civicrm-core.git] / Civi / Api4 / Generic / DAOGetAction.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
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 |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 * $Id$
18 *
19 */
20
21
19b53e5b
C
22namespace Civi\Api4\Generic;
23
3c7c8fa6
CW
24use Civi\Api4\Query\Api4SelectQuery;
25
19b53e5b 26/**
e3c6d5ff 27 * Retrieve $ENTITIES based on criteria specified in the `where` parameter.
19b53e5b 28 *
fc95d9a5 29 * Use the `select` param to determine which fields are returned, defaults to `[*]`.
19b53e5b
C
30 *
31 * Perform joins on other related entities using a dot notation.
32 */
33class DAOGetAction extends AbstractGetAction {
34 use Traits\DAOActionTrait;
35
39e0f675 36 /**
fc95d9a5 37 * Fields to return. Defaults to all non-custom fields `[*]`.
39e0f675 38 *
fc95d9a5 39 * Use the dot notation to perform joins in the select clause, e.g. selecting `['*', 'contact.*']` from `Email::get()`
39e0f675
CW
40 * will select all fields for the email + all fields for the related contact.
41 *
42 * @var array
43 * @inheritDoc
44 */
45 protected $select = [];
46
fba513f6
CW
47 /**
48 * Field(s) by which to group the results.
49 *
50 * @var array
51 */
52 protected $groupBy = [];
53
19b53e5b
C
54 public function _run(Result $result) {
55 $this->setDefaultWhereClause();
39e0f675 56 $this->expandSelectClauseWildcards();
19b53e5b
C
57 $result->exchangeArray($this->getObjects());
58 }
59
3c7c8fa6
CW
60 /**
61 * @return array|int
62 */
63 protected function getObjects() {
64 $query = new Api4SelectQuery($this);
65
66 $result = $query->run();
67 if (is_array($result)) {
68 \CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($result);
69 }
70 return $result;
71 }
72
fba513f6
CW
73 /**
74 * @return array
75 */
76 public function getGroupBy(): array {
77 return $this->groupBy;
78 }
79
80 /**
81 * @param array $groupBy
82 * @return $this
83 */
84 public function setGroupBy(array $groupBy) {
85 $this->groupBy = $groupBy;
86 return $this;
87 }
88
89 /**
90 * @param string $field
91 * @return $this
92 */
93 public function addGroupBy(string $field) {
94 $this->groupBy[] = $field;
95 return $this;
96 }
97
19b53e5b 98}