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