Merge pull request #17111 from seamuslee001/master
[civicrm-core.git] / Civi / Api4 / Generic / DAOGetAction.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace Civi\Api4\Generic;
23
24 use Civi\Api4\Query\Api4SelectQuery;
25
26 /**
27 * Retrieve $ENTITIES based on criteria specified in the `where` parameter.
28 *
29 * Use the `select` param to determine which fields are returned, defaults to `[*]`.
30 *
31 * Perform joins on other related entities using a dot notation.
32 *
33 * @method $this setHaving(array $clauses)
34 * @method array getHaving()
35 */
36 class DAOGetAction extends AbstractGetAction {
37 use Traits\DAOActionTrait;
38
39 /**
40 * Fields to return. Defaults to all non-custom fields `[*]`.
41 *
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.
44 *
45 * @var array
46 * @inheritDoc
47 */
48 protected $select = [];
49
50 public function _run(Result $result) {
51 $this->setDefaultWhereClause();
52 $this->expandSelectClauseWildcards();
53 $result->exchangeArray($this->getObjects());
54 }
55
56 /**
57 * @return array|int
58 */
59 protected function getObjects() {
60 $query = new Api4SelectQuery($this);
61
62 $result = $query->run();
63 if (is_array($result)) {
64 \CRM_Utils_API_HTMLInputCoder::singleton()->decodeRows($result);
65 }
66 return $result;
67 }
68
69 }