Merge pull request #5020 from pratikshad/4.6-alpha4
[civicrm-core.git] / api / v3 / examples / UFField / Create.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using uf_field create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function uf_field_create_example() {
16 $params = array(
17 'field_name' => 'phone',
18 'field_type' => 'Contact',
19 'visibility' => 'Public Pages and Listings',
20 'weight' => 1,
21 'label' => 'Test Phone',
22 'is_searchable' => 1,
23 'is_active' => 1,
24 'location_type_id' => 1,
25 'phone_type_id' => 1,
26 'uf_group_id' => 11,
27 );
28
29 try{
30 $result = civicrm_api3('uf_field', 'create', $params);
31 }
32 catch (CiviCRM_API3_Exception $e) {
33 // Handle error here.
34 $errorMessage = $e->getMessage();
35 $errorCode = $e->getErrorCode();
36 $errorData = $e->getExtraParams();
37 return array(
38 'error' => $errorMessage,
39 'error_code' => $errorCode,
40 'error_data' => $errorData,
41 );
42 }
43
44 return $result;
45 }
46
47 /**
48 * Function returns array of result expected from previous function.
49 *
50 * @return array
51 * API result array
52 */
53 function uf_field_create_expectedresult() {
54
55 $expectedResult = array(
56 'is_error' => 0,
57 'version' => 3,
58 'count' => 1,
59 'id' => 1,
60 'values' => array(
61 '1' => array(
62 'id' => '1',
63 'uf_group_id' => '11',
64 'field_name' => 'phone',
65 'is_active' => '1',
66 'is_view' => '',
67 'is_required' => '',
68 'weight' => '1',
69 'help_post' => '',
70 'help_pre' => '',
71 'visibility' => 'Public Pages and Listings',
72 'in_selector' => '',
73 'is_searchable' => '1',
74 'location_type_id' => '1',
75 'phone_type_id' => '1',
76 'website_type_id' => '',
77 'label' => 'Test Phone',
78 'field_type' => 'Contact',
79 'is_reserved' => '',
80 'is_multi_summary' => '',
81 ),
82 ),
83 );
84
85 return $expectedResult;
86 }
87
88 /**
89 * This example has been generated from the API test suite.
90 * The test that created it is called
91 * testCreateUFField
92 * and can be found in
93 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php
94 *
95 * You can see the outcome of the API tests at
96 * https://test.civicrm.org/job/CiviCRM-master-git/
97 *
98 * To Learn about the API read
99 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
100 *
101 * Browse the api on your own site with the api explorer
102 * http://MYSITE.ORG/path/to/civicrm/api/explorer
103 *
104 * Read more about testing here
105 * http://wiki.civicrm.org/confluence/display/CRM/Testing
106 *
107 * API Standards documentation:
108 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
109 */