Merge pull request #2133 from colemanw/master
[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' => '',
29fbb90a 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,
29fbb90a 51 'api.aliases' => array(),
9dec4e61 52 ),
53 'last_name' => array(
c3d3e837
E
54 'api.required' => '1',
55 'title' => 'Last Name',
56 'help_pre' => '',
57 'help_post' => '',
29fbb90a 58 'entity' => 'contact',
9dec4e61 59 'name' => 'last_name',
60 'type' => 2,
9dec4e61 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,
29fbb90a 68 'api.aliases' => array(),
9dec4e61 69 ),
c3d3e837
E
70 'email-primary' => array(
71 'api.required' => 1,
72 'title' => 'Email',
73 'help_pre' => '',
74 'help_post' => '',
29fbb90a 75 'entity' => 'email',
c3d3e837
E
76 'api.aliases' => array(
77 '0' => 'email-Primary',
78 ),
9dec4e61 79 'name' => 'email',
80 'type' => 2,
c3d3e837 81 'maxlength' => 254,
9dec4e61 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',
9dec4e61 89 ),
90 'phone-1-1' => array(
c3d3e837
E
91 'api.required' => 1,
92 'title' => 'Phone',
93 'help_pre' => '',
94 'help_post' => '',
29fbb90a 95 'entity' => 'phone',
9dec4e61 96 'name' => 'phone',
97 'type' => 2,
9dec4e61 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,
29fbb90a 105 'api.aliases' => array(),
9dec4e61 106 ),
107 'country-1' => array(
c3d3e837
E
108 'api.required' => '1',
109 'title' => 'Country',
110 'help_pre' => '',
111 'help_post' => '',
29fbb90a 112 'entity' => 'address',
9dec4e61 113 'name' => 'country_id',
114 'type' => 1,
9dec4e61 115 'FKClassName' => 'CRM_Core_DAO_Country',
116 'pseudoconstant' => array(
117 'table' => 'civicrm_country',
118 'keyColumn' => 'id',
119 'labelColumn' => 'name',
120 'nameColumn' => 'iso_code',
121 ),
29fbb90a 122 'api.aliases' => array(),
9dec4e61 123 ),
124 'state_province-1' => array(
c3d3e837
E
125 'api.required' => '1',
126 'title' => 'State',
127 'help_pre' => '',
128 'help_post' => '',
29fbb90a 129 'entity' => 'address',
9dec4e61 130 'name' => 'state_province_id',
131 'type' => 1,
9dec4e61 132 'FKClassName' => 'CRM_Core_DAO_StateProvince',
133 'pseudoconstant' => array(
134 'table' => 'civicrm_state_province',
135 'keyColumn' => 'id',
136 'labelColumn' => 'name',
137 ),
29fbb90a 138 'api.aliases' => array(),
9dec4e61 139 ),
140 'postal_code-1' => array(
c3d3e837
E
141 'api.required' => 0,
142 'title' => 'Postal Code',
143 'help_pre' => '',
144 'help_post' => '',
29fbb90a 145 'entity' => 'address',
9dec4e61 146 'name' => 'postal_code',
147 'type' => 2,
9dec4e61 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,
29fbb90a 155 'api.aliases' => array(),
9dec4e61 156 ),
157 'custom_1' => array(
c3d3e837
E
158 'api.required' => '1',
159 'title' => 'first_name',
160 'help_pre' => '',
161 'help_post' => '',
29fbb90a 162 'entity' => 'contact',
9dec4e61 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',
4bcfd71f 181 'type' => 2,
29fbb90a 182 'api.aliases' => array(),
9dec4e61 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*/