APIv4 - Add SQL expression handling and aggregate functions
[civicrm-core.git] / Civi / Api4 / Generic / DAOGetFieldsAction.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\Service\Spec\SpecFormatter;
25
26 /**
27 * @inheritDoc
28 * @method bool getIncludeCustom()
29 */
30 class DAOGetFieldsAction extends BasicGetFieldsAction {
31
32 /**
33 * Include custom fields for this entity, or only core fields?
34 *
35 * @var bool
36 */
37 protected $includeCustom = TRUE;
38
39 /**
40 * Get fields for a DAO-based entity.
41 *
42 * @return array
43 */
44 protected function getRecords() {
45 $fields = $this->_itemsToGet('name');
46 /** @var \Civi\Api4\Service\Spec\SpecGatherer $gatherer */
47 $gatherer = \Civi::container()->get('spec_gatherer');
48 // Any fields name with a dot in it is custom
49 if ($fields) {
50 $this->includeCustom = strpos(implode('', $fields), '.') !== FALSE;
51 }
52 $spec = $gatherer->getSpec($this->getEntityName(), $this->getAction(), $this->includeCustom, $this->values);
53 return SpecFormatter::specToArray($spec->getFields($fields), $this->loadOptions, $this->values);
54 }
55
56 public function fields() {
57 $fields = parent::fields();
58 $fields[] = [
59 'name' => 'help_pre',
60 'data_type' => 'String',
61 ];
62 $fields[] = [
63 'name' => 'help_post',
64 'data_type' => 'String',
65 ];
66 $fields[] = [
67 'name' => 'column_name',
68 'data_type' => 'String',
69 ];
70 $fields[] = [
71 'name' => 'custom_field_id',
72 'data_type' => 'Integer',
73 ];
74 $fields[] = [
75 'name' => 'custom_group_id',
76 'data_type' => 'Integer',
77 ];
78 return $fields;
79 }
80
81 }