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