Merge pull request #15572 from civicrm/5.19
[civicrm-core.git] / api / v3 / examples / Tag / GetFields.ex.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Tag.getfields API.
4 *
5 * Demonstrate use of getfields to interrogate api.
6 *
7 * @return array
8 * API result array
9 */
10 function tag_getfields_example() {
11 $params = [
12 'action' => 'create',
13 ];
14
15 try{
16 $result = civicrm_api3('Tag', 'getfields', $params);
17 }
18 catch (CiviCRM_API3_Exception $e) {
19 // Handle error here.
20 $errorMessage = $e->getMessage();
21 $errorCode = $e->getErrorCode();
22 $errorData = $e->getExtraParams();
23 return [
24 'is_error' => 1,
25 'error_message' => $errorMessage,
26 'error_code' => $errorCode,
27 'error_data' => $errorData,
28 ];
29 }
30
31 return $result;
32 }
33
34 /**
35 * Function returns array of result expected from previous function.
36 *
37 * @return array
38 * API result array
39 */
40 function tag_getfields_expectedresult() {
41
42 $expectedResult = [
43 'is_error' => 0,
44 'version' => 3,
45 'count' => 11,
46 'values' => [
47 'id' => [
48 'name' => 'id',
49 'type' => 1,
50 'title' => 'Tag ID',
51 'description' => 'Tag ID',
52 'required' => TRUE,
53 'where' => 'civicrm_tag.id',
54 'table_name' => 'civicrm_tag',
55 'entity' => 'Tag',
56 'bao' => 'CRM_Core_BAO_Tag',
57 'localizable' => 0,
58 'is_core_field' => TRUE,
59 'api.aliases' => [
60 '0' => 'tag',
61 ],
62 ],
63 'name' => [
64 'name' => 'name',
65 'type' => 2,
66 'title' => 'Tag Name',
67 'description' => 'Name of Tag.',
68 'required' => TRUE,
69 'maxlength' => 64,
70 'size' => 30,
71 'where' => 'civicrm_tag.name',
72 'table_name' => 'civicrm_tag',
73 'entity' => 'Tag',
74 'bao' => 'CRM_Core_BAO_Tag',
75 'localizable' => 0,
76 'is_core_field' => TRUE,
77 'api.required' => 1,
78 ],
79 'description' => [
80 'name' => 'description',
81 'type' => 2,
82 'title' => 'Description',
83 'description' => 'Optional verbose description of the tag.',
84 'maxlength' => 255,
85 'size' => 45,
86 'where' => 'civicrm_tag.description',
87 'table_name' => 'civicrm_tag',
88 'entity' => 'Tag',
89 'bao' => 'CRM_Core_BAO_Tag',
90 'localizable' => 0,
91 'is_core_field' => TRUE,
92 ],
93 'parent_id' => [
94 'name' => 'parent_id',
95 'type' => 1,
96 'title' => 'Parent Tag',
97 'description' => 'Optional parent id for this tag.',
98 'where' => 'civicrm_tag.parent_id',
99 'default' => 'NULL',
100 'table_name' => 'civicrm_tag',
101 'entity' => 'Tag',
102 'bao' => 'CRM_Core_BAO_Tag',
103 'localizable' => 0,
104 'FKClassName' => 'CRM_Core_DAO_Tag',
105 'is_core_field' => TRUE,
106 'FKApiName' => 'Tag',
107 ],
108 'is_selectable' => [
109 'name' => 'is_selectable',
110 'type' => 16,
111 'title' => 'Display Tag?',
112 'description' => 'Is this tag selectable / displayed',
113 'where' => 'civicrm_tag.is_selectable',
114 'default' => '1',
115 'table_name' => 'civicrm_tag',
116 'entity' => 'Tag',
117 'bao' => 'CRM_Core_BAO_Tag',
118 'localizable' => 0,
119 'is_core_field' => TRUE,
120 ],
121 'is_reserved' => [
122 'name' => 'is_reserved',
123 'type' => 16,
124 'title' => 'Reserved',
125 'where' => 'civicrm_tag.is_reserved',
126 'table_name' => 'civicrm_tag',
127 'entity' => 'Tag',
128 'bao' => 'CRM_Core_BAO_Tag',
129 'localizable' => 0,
130 'is_core_field' => TRUE,
131 ],
132 'is_tagset' => [
133 'name' => 'is_tagset',
134 'type' => 16,
135 'title' => 'Tagset',
136 'where' => 'civicrm_tag.is_tagset',
137 'table_name' => 'civicrm_tag',
138 'entity' => 'Tag',
139 'bao' => 'CRM_Core_BAO_Tag',
140 'localizable' => 0,
141 'is_core_field' => TRUE,
142 ],
143 'used_for' => [
144 'name' => 'used_for',
145 'type' => 2,
146 'title' => 'Used For',
147 'maxlength' => 64,
148 'size' => 30,
149 'where' => 'civicrm_tag.used_for',
150 'default' => 'NULL',
151 'table_name' => 'civicrm_tag',
152 'entity' => 'Tag',
153 'bao' => 'CRM_Core_BAO_Tag',
154 'localizable' => 0,
155 'serialize' => 5,
156 'html' => [
157 'type' => 'Select',
158 'maxlength' => 64,
159 'size' => 30,
160 ],
161 'pseudoconstant' => [
162 'optionGroupName' => 'tag_used_for',
163 'optionEditPath' => 'civicrm/admin/options/tag_used_for',
164 ],
165 'is_core_field' => TRUE,
166 'api.default' => 'civicrm_contact',
167 ],
168 'created_id' => [
169 'name' => 'created_id',
170 'type' => 1,
171 'title' => 'Tag Created By',
172 'description' => 'FK to civicrm_contact, who created this tag',
173 'where' => 'civicrm_tag.created_id',
174 'table_name' => 'civicrm_tag',
175 'entity' => 'Tag',
176 'bao' => 'CRM_Core_BAO_Tag',
177 'localizable' => 0,
178 'FKClassName' => 'CRM_Contact_DAO_Contact',
179 'is_core_field' => TRUE,
180 'FKApiName' => 'Contact',
181 ],
182 'color' => [
183 'name' => 'color',
184 'type' => 2,
185 'title' => 'Color',
186 'description' => 'Hex color value e.g. #ffffff',
187 'maxlength' => 255,
188 'size' => 45,
189 'where' => 'civicrm_tag.color',
190 'default' => 'NULL',
191 'table_name' => 'civicrm_tag',
192 'entity' => 'Tag',
193 'bao' => 'CRM_Core_BAO_Tag',
194 'localizable' => 0,
195 'is_core_field' => TRUE,
196 ],
197 'created_date' => [
198 'name' => 'created_date',
199 'type' => 12,
200 'title' => 'Tag Created Date',
201 'description' => 'Date and time that tag was created.',
202 'where' => 'civicrm_tag.created_date',
203 'table_name' => 'civicrm_tag',
204 'entity' => 'Tag',
205 'bao' => 'CRM_Core_BAO_Tag',
206 'localizable' => 0,
207 'is_core_field' => TRUE,
208 ],
209 ],
210 ];
211
212 return $expectedResult;
213 }
214
215 /*
216 * This example has been generated from the API test suite.
217 * The test that created it is called "testTagGetfields"
218 * and can be found at:
219 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TagTest.php
220 *
221 * You can see the outcome of the API tests at
222 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
223 *
224 * To Learn about the API read
225 * https://docs.civicrm.org/dev/en/latest/api/
226 *
227 * Browse the API on your own site with the API Explorer. It is in the main
228 * CiviCRM menu, under: Support > Development > API Explorer.
229 *
230 * Read more about testing here
231 * https://docs.civicrm.org/dev/en/latest/testing/
232 *
233 * API Standards documentation:
234 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
235 */