Short array syntax - auto-convert api dir
[civicrm-core.git] / api / v3 / examples / Tag / GetList.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Tag.getlist API.
4 *
5 * Demonstrates use of api.getlist for autocomplete and quicksearch applications.
6 *
7 * @return array
8 * API result array
9 */
10 function tag_getlist_example() {
11 $params = [
12 'input' => 'New Tag3',
13 'extra' => [
14 '0' => 'used_for',
15 ],
16 ];
17
18 try{
19 $result = civicrm_api3('Tag', 'getlist', $params);
20 }
21 catch (CiviCRM_API3_Exception $e) {
22 // Handle error here.
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
26 return [
27 'is_error' => 1,
28 'error_message' => $errorMessage,
29 'error_code' => $errorCode,
30 'error_data' => $errorData,
31 ];
32 }
33
34 return $result;
35 }
36
37 /**
38 * Function returns array of result expected from previous function.
39 *
40 * @return array
41 * API result array
42 */
43 function tag_getlist_expectedresult() {
44
45 $expectedResult = [
46 'is_error' => 0,
47 'version' => 3,
48 'count' => 1,
49 'id' => 0,
50 'values' => [
51 '0' => [
52 'id' => '19',
53 'label' => 'New Tag3',
54 'description' => [
55 '0' => 'This is description for Our New Tag ',
56 ],
57 'extra' => [
58 'used_for' => 'civicrm_contact',
59 ],
60 ],
61 ],
62 'page_num' => 1,
63 'more_results' => '',
64 ];
65
66 return $expectedResult;
67 }
68
69 /*
70 * This example has been generated from the API test suite.
71 * The test that created it is called "testTagGetList"
72 * and can be found at:
73 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TagTest.php
74 *
75 * You can see the outcome of the API tests at
76 * https://test.civicrm.org/job/CiviCRM-master-git/
77 *
78 * To Learn about the API read
79 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
80 *
81 * Browse the api on your own site with the api explorer
82 * http://MYSITE.ORG/path/to/civicrm/api
83 *
84 * Read more about testing here
85 * http://wiki.civicrm.org/confluence/display/CRM/Testing
86 *
87 * API Standards documentation:
88 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
89 */