Commit | Line | Data |
---|---|---|
fb32de45 | 1 | <?php |
2 | /** | |
50fb255d | 3 | * @file |
4 | * Test Generated API Example. | |
5 | * See bottom of this file for more detail. | |
fb32de45 | 6 | */ |
fb32de45 | 7 | |
50fb255d | 8 | /** |
9 | * Test Generated example of using tag getfields API. | |
10 | * | |
11 | * demonstrate use of getfields to interrogate api | |
12 | * | |
13 | * @return array | |
14 | * API result array | |
15 | */ | |
16 | function tag_getfields_example() { | |
17 | $params = array( | |
18 | 'action' => 'create', | |
19 | ); | |
20 | ||
21 | try{ | |
22 | $result = civicrm_api3('tag', 'getfields', $params); | |
23 | } | |
24 | catch (CiviCRM_API3_Exception $e) { | |
25 | // Handle error here. | |
26 | $errorMessage = $e->getMessage(); | |
27 | $errorCode = $e->getErrorCode(); | |
28 | $errorData = $e->getExtraParams(); | |
29 | return array( | |
30 | 'error' => $errorMessage, | |
31 | 'error_code' => $errorCode, | |
32 | 'error_data' => $errorData, | |
33 | ); | |
34 | } | |
fb32de45 | 35 | |
50fb255d | 36 | return $result; |
fb32de45 | 37 | } |
38 | ||
39 | /** | |
50fb255d | 40 | * Function returns array of result expected from previous function. |
41 | * | |
42 | * @return array | |
43 | * API result array | |
fb32de45 | 44 | */ |
50fb255d | 45 | function tag_getfields_expectedresult() { |
fb32de45 | 46 | |
47 | $expectedResult = array( | |
50fb255d | 48 | 'is_error' => 0, |
49 | 'version' => 3, | |
50 | 'count' => 10, | |
51 | 'values' => array( | |
fb32de45 | 52 | 'id' => array( |
50fb255d | 53 | 'name' => 'id', |
54 | 'type' => 1, | |
55 | 'title' => 'Tag ID', | |
56 | 'required' => TRUE, | |
57 | 'api.aliases' => array( | |
58 | '0' => 'tag', | |
fb32de45 | 59 | ), |
50fb255d | 60 | ), |
fb32de45 | 61 | 'name' => array( |
50fb255d | 62 | 'name' => 'name', |
63 | 'type' => 2, | |
64 | 'title' => 'Tag Name', | |
65 | 'required' => TRUE, | |
66 | 'maxlength' => 64, | |
67 | 'size' => 30, | |
68 | 'api.required' => 1, | |
69 | ), | |
fb32de45 | 70 | 'description' => array( |
50fb255d | 71 | 'name' => 'description', |
72 | 'type' => 2, | |
73 | 'title' => 'Description', | |
74 | 'maxlength' => 255, | |
75 | 'size' => 45, | |
76 | ), | |
fb32de45 | 77 | 'parent_id' => array( |
50fb255d | 78 | 'name' => 'parent_id', |
79 | 'type' => 1, | |
80 | 'title' => 'Parent Tag', | |
81 | 'default' => 'NULL', | |
82 | 'FKClassName' => 'CRM_Core_DAO_Tag', | |
83 | 'FKApiName' => 'Tag', | |
84 | ), | |
fb32de45 | 85 | 'is_selectable' => array( |
50fb255d | 86 | 'name' => 'is_selectable', |
87 | 'type' => 16, | |
88 | 'title' => 'Display Tag?', | |
89 | 'default' => '1', | |
90 | ), | |
fb32de45 | 91 | 'is_reserved' => array( |
50fb255d | 92 | 'name' => 'is_reserved', |
93 | 'type' => 16, | |
94 | 'title' => 'Reserved', | |
95 | ), | |
fb32de45 | 96 | 'is_tagset' => array( |
50fb255d | 97 | 'name' => 'is_tagset', |
98 | 'type' => 16, | |
99 | 'title' => 'Tagset', | |
100 | ), | |
fb32de45 | 101 | 'used_for' => array( |
50fb255d | 102 | 'name' => 'used_for', |
103 | 'type' => 2, | |
104 | 'title' => 'Used For', | |
105 | 'maxlength' => 64, | |
106 | 'size' => 30, | |
107 | 'default' => 'NULL', | |
108 | 'html' => array( | |
109 | 'type' => 'Select', | |
fb32de45 | 110 | ), |
50fb255d | 111 | 'pseudoconstant' => array( |
112 | 'optionGroupName' => 'tag_used_for', | |
fb32de45 | 113 | ), |
50fb255d | 114 | 'api.default' => 'civicrm_contact', |
115 | ), | |
116 | 'created_id' => array( | |
117 | 'name' => 'created_id', | |
118 | 'type' => 1, | |
119 | 'title' => 'Tag Created By', | |
120 | 'FKClassName' => 'CRM_Contact_DAO_Contact', | |
121 | 'FKApiName' => 'Contact', | |
122 | ), | |
fb32de45 | 123 | 'created_date' => array( |
50fb255d | 124 | 'name' => 'created_date', |
125 | 'type' => 12, | |
126 | 'title' => 'Tag Created Date', | |
127 | ), | |
fb32de45 | 128 | ), |
50fb255d | 129 | ); |
fb32de45 | 130 | |
131 | return $expectedResult; | |
132 | } | |
133 | ||
50fb255d | 134 | /** |
135 | * This example has been generated from the API test suite. | |
136 | * The test that created it is called | |
137 | * testTagGetfields | |
138 | * and can be found in | |
69d79249 | 139 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TagTest.php |
fb32de45 | 140 | * |
141 | * You can see the outcome of the API tests at | |
69d79249 | 142 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
fb32de45 | 143 | * |
144 | * To Learn about the API read | |
69d79249 | 145 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
fb32de45 | 146 | * |
69d79249 E |
147 | * Browse the api on your own site with the api explorer |
148 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
fb32de45 | 149 | * |
150 | * Read more about testing here | |
151 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
152 | * | |
153 | * API Standards documentation: | |
154 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 155 | */ |