9dd6c6ebc83eff00cc36784199a53619c351e90a
[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 = array(
12 'input' => 'New Tag3',
13 'extra' => array(
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 array(
27 'error' => $errorMessage,
28 'error_code' => $errorCode,
29 'error_data' => $errorData,
30 );
31 }
32
33 return $result;
34 }
35
36 /**
37 * Function returns array of result expected from previous function.
38 *
39 * @return array
40 * API result array
41 */
42 function tag_getlist_expectedresult() {
43
44 $expectedResult = array(
45 'is_error' => 0,
46 'version' => 3,
47 'count' => 1,
48 'id' => 0,
49 'values' => array(
50 '0' => array(
51 'id' => '19',
52 'label' => 'New Tag3',
53 'description' => array(
54 '0' => 'This is description for Our New Tag ',
55 ),
56 'extra' => array(
57 'used_for' => 'civicrm_contact',
58 ),
59 ),
60 ),
61 'page_num' => 1,
62 'more_results' => '',
63 );
64
65 return $expectedResult;
66 }
67
68 /*
69 * This example has been generated from the API test suite.
70 * The test that created it is called "testTagGetList"
71 * and can be found at:
72 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TagTest.php
73 *
74 * You can see the outcome of the API tests at
75 * https://test.civicrm.org/job/CiviCRM-master-git/
76 *
77 * To Learn about the API read
78 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
79 *
80 * Browse the api on your own site with the api explorer
81 * http://MYSITE.ORG/path/to/civicrm/api
82 *
83 * Read more about testing here
84 * http://wiki.civicrm.org/confluence/display/CRM/Testing
85 *
86 * API Standards documentation:
87 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
88 */