Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-08-28-20-20-34
[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' => 25,
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 'name' => 'first_name',
38 'type' => 2,
39 'title' => 'First Name',
40 'maxlength' => 64,
41 'size' => 30,
42 'import' => true,
43 'where' => 'civicrm_contact.first_name',
44 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
45 'dataPattern' => '/^\w+$/',
46 'export' => true,
47 ),
48 'last_name' => array(
49 'name' => 'last_name',
50 'type' => 2,
51 'title' => 'Last Name',
52 'maxlength' => 64,
53 'size' => 30,
54 'import' => true,
55 'where' => 'civicrm_contact.last_name',
56 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
57 'dataPattern' => '/^\w+(\s\w+)?+$/',
58 'export' => true,
59 ),
60 'email' => array(
61 'name' => 'email',
62 'type' => 2,
63 'title' => 'Email',
64 'maxlength' => 64,
65 'size' => 20,
66 'import' => true,
67 'where' => 'civicrm_email.email',
68 'headerPattern' => '/e.?mail/i',
69 '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]$/',
70 'export' => true,
71 'rule' => 'email',
72 'api.required' => 1,
73 ),
74 'phone-1-1' => array(
75 'name' => 'phone',
76 'type' => 2,
77 'title' => 'Phone',
78 'maxlength' => 32,
79 'size' => 20,
80 'import' => true,
81 'where' => 'civicrm_phone.phone',
82 'headerPattern' => '/phone/i',
83 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
84 'export' => true,
85 'api.required' => 1,
86 ),
87 'country-1' => array(
88 'name' => 'country_id',
89 'type' => 1,
90 'title' => 'Country',
91 'FKClassName' => 'CRM_Core_DAO_Country',
92 'pseudoconstant' => array(
93 'table' => 'civicrm_country',
94 'keyColumn' => 'id',
95 'labelColumn' => 'name',
96 'nameColumn' => 'iso_code',
97 ),
98 ),
99 'state_province-1' => array(
100 'name' => 'state_province_id',
101 'type' => 1,
102 'title' => 'State',
103 'FKClassName' => 'CRM_Core_DAO_StateProvince',
104 'pseudoconstant' => array(
105 'table' => 'civicrm_state_province',
106 'keyColumn' => 'id',
107 'labelColumn' => 'name',
108 ),
109 ),
110 'postal_code-1' => array(
111 'name' => 'postal_code',
112 'type' => 2,
113 'title' => 'Postal Code',
114 'maxlength' => 12,
115 'size' => 12,
116 'import' => true,
117 'where' => 'civicrm_address.postal_code',
118 'headerPattern' => '/postal|zip/i',
119 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
120 'export' => true,
121 ),
122 'custom_1' => array(
123 'label' => '_addCustomFieldToProfile',
124 'groupTitle' => '_addCustomFie',
125 'data_type' => 'String',
126 'html_type' => 'Text',
127 'default_value' => 'defaultValue',
128 'text_length' => '',
129 'options_per_line' => '',
130 'custom_group_id' => '1',
131 'extends' => 'Contact',
132 'is_search_range' => 0,
133 'extends_entity_column_value' => '',
134 'extends_entity_column_id' => '',
135 'is_view' => 0,
136 'is_multiple' => 0,
137 'option_group_id' => '',
138 'date_format' => '',
139 'time_format' => '',
140 'name' => 'custom_1',
141 'type' => 2,
142 ),
143 'profile_id' => array(
144 'api.required' => true,
145 ),
146 ),
147 );
148
149 return $expectedResult;
150 }
151
152
153 /*
154 * This example has been generated from the API test suite. The test that created it is called
155 *
156 * testGetFields and can be found in
157 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ProfileTest.php
158 *
159 * You can see the outcome of the API tests at
160 * http://tests.dev.civicrm.org/trunk/results-api_v3
161 *
162 * To Learn about the API read
163 * http://book.civicrm.org/developer/current/techniques/api/
164 *
165 * and review the wiki at
166 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
167 *
168 * Read more about testing here
169 * http://wiki.civicrm.org/confluence/display/CRM/Testing
170 *
171 * API Standards documentation:
172 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
173 */