Merge pull request #1631 from josephlacey/bookkeeping-report-updates
[civicrm-core.git] / api / v3 / examples / ProfileGetFields.php
CommitLineData
9dec4e61 1<?php
2/**
3 * Test Generated example of using profile getfields API
4 * demonstrates retrieving profile fields passing in an id *
5 */
6function profile_getfields_example(){
7$params = array(
8 'action' => 'submit',
c3d3e837 9 'profile_id' => 27,
9dec4e61 10);
11
12try{
13 $result = civicrm_api3('profile', 'getfields', $params);
14}
15catch (CiviCRM_API3_Exception $e) {
16 // handle error here
17 $errorMessage = $e->getMessage();
18 $errorCode = $e->getErrorCode();
19 $errorData = $e->getExtraParams();
20 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
21}
22
23return $result;
24}
25
26/**
27 * Function returns array of result expected from previous function
28 */
29function profile_getfields_expectedresult(){
30
31 $expectedResult = array(
32 'is_error' => 0,
33 'version' => 3,
34 'count' => 9,
35 'values' => array(
36 'first_name' => array(
c3d3e837
E
37 'api.required' => '1',
38 'title' => 'First Name',
39 'help_pre' => '',
40 'help_post' => '',
41 'entity' => 'Contact',
9dec4e61 42 'name' => 'first_name',
43 'type' => 2,
9dec4e61 44 'maxlength' => 64,
45 'size' => 30,
46 'import' => true,
47 'where' => 'civicrm_contact.first_name',
48 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
49 'dataPattern' => '/^\w+$/',
50 'export' => true,
51 ),
52 'last_name' => array(
c3d3e837
E
53 'api.required' => '1',
54 'title' => 'Last Name',
55 'help_pre' => '',
56 'help_post' => '',
57 'entity' => 'Contact',
9dec4e61 58 'name' => 'last_name',
59 'type' => 2,
9dec4e61 60 'maxlength' => 64,
61 'size' => 30,
62 'import' => true,
63 'where' => 'civicrm_contact.last_name',
64 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
65 'dataPattern' => '/^\w+(\s\w+)?+$/',
66 'export' => true,
67 ),
c3d3e837
E
68 'email-primary' => array(
69 'api.required' => 1,
70 'title' => 'Email',
71 'help_pre' => '',
72 'help_post' => '',
73 'entity' => 'Email',
74 'api.aliases' => array(
75 '0' => 'email-Primary',
76 ),
9dec4e61 77 'name' => 'email',
78 'type' => 2,
c3d3e837 79 'maxlength' => 254,
9dec4e61 80 'size' => 20,
81 'import' => true,
82 'where' => 'civicrm_email.email',
83 'headerPattern' => '/e.?mail/i',
84 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/',
85 'export' => true,
86 'rule' => 'email',
9dec4e61 87 ),
88 'phone-1-1' => array(
c3d3e837
E
89 'api.required' => 1,
90 'title' => 'Phone',
91 'help_pre' => '',
92 'help_post' => '',
93 'entity' => 'Phone',
9dec4e61 94 'name' => 'phone',
95 'type' => 2,
9dec4e61 96 'maxlength' => 32,
97 'size' => 20,
98 'import' => true,
99 'where' => 'civicrm_phone.phone',
100 'headerPattern' => '/phone/i',
101 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
102 'export' => true,
9dec4e61 103 ),
104 'country-1' => array(
c3d3e837
E
105 'api.required' => '1',
106 'title' => 'Country',
107 'help_pre' => '',
108 'help_post' => '',
109 'entity' => 'Address',
9dec4e61 110 'name' => 'country_id',
111 'type' => 1,
9dec4e61 112 'FKClassName' => 'CRM_Core_DAO_Country',
113 'pseudoconstant' => array(
114 'table' => 'civicrm_country',
115 'keyColumn' => 'id',
116 'labelColumn' => 'name',
117 'nameColumn' => 'iso_code',
118 ),
119 ),
120 'state_province-1' => array(
c3d3e837
E
121 'api.required' => '1',
122 'title' => 'State',
123 'help_pre' => '',
124 'help_post' => '',
125 'entity' => 'Address',
9dec4e61 126 'name' => 'state_province_id',
127 'type' => 1,
9dec4e61 128 'FKClassName' => 'CRM_Core_DAO_StateProvince',
129 'pseudoconstant' => array(
130 'table' => 'civicrm_state_province',
131 'keyColumn' => 'id',
132 'labelColumn' => 'name',
133 ),
134 ),
135 'postal_code-1' => array(
c3d3e837
E
136 'api.required' => 0,
137 'title' => 'Postal Code',
138 'help_pre' => '',
139 'help_post' => '',
140 'entity' => 'Address',
9dec4e61 141 'name' => 'postal_code',
142 'type' => 2,
9dec4e61 143 'maxlength' => 12,
144 'size' => 12,
145 'import' => true,
146 'where' => 'civicrm_address.postal_code',
147 'headerPattern' => '/postal|zip/i',
148 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
149 'export' => true,
150 ),
151 'custom_1' => array(
c3d3e837
E
152 'api.required' => '1',
153 'title' => 'first_name',
154 'help_pre' => '',
155 'help_post' => '',
156 'entity' => 'Contact',
9dec4e61 157 'label' => '_addCustomFieldToProfile',
158 'groupTitle' => '_addCustomFie',
159 'data_type' => 'String',
160 'html_type' => 'Text',
161 'default_value' => 'defaultValue',
162 'text_length' => '',
163 'options_per_line' => '',
164 'custom_group_id' => '1',
165 'extends' => 'Contact',
166 'is_search_range' => 0,
167 'extends_entity_column_value' => '',
168 'extends_entity_column_id' => '',
169 'is_view' => 0,
170 'is_multiple' => 0,
171 'option_group_id' => '',
172 'date_format' => '',
173 'time_format' => '',
174 'name' => 'custom_1',
4bcfd71f 175 'type' => 2,
9dec4e61 176 ),
177 'profile_id' => array(
178 'api.required' => true,
179 ),
180 ),
181);
182
183 return $expectedResult;
184}
185
186
187/*
188* This example has been generated from the API test suite. The test that created it is called
189*
190* testGetFields and can be found in
191* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ProfileTest.php
192*
193* You can see the outcome of the API tests at
194* http://tests.dev.civicrm.org/trunk/results-api_v3
195*
196* To Learn about the API read
197* http://book.civicrm.org/developer/current/techniques/api/
198*
199* and review the wiki at
200* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
201*
202* Read more about testing here
203* http://wiki.civicrm.org/confluence/display/CRM/Testing
204*
205* API Standards documentation:
206* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
207*/