Merge pull request #15109 from civicrm/5.17
[civicrm-core.git] / api / v3 / examples / OptionValue / Get.php
1 <?php
2 /**
3 * Test Generated example demonstrating the OptionValue.get API.
4 *
5 * @return array
6 * API result array
7 */
8 function option_value_get_example() {
9 $params = [
10 'option_group_id' => 1,
11 ];
12
13 try{
14 $result = civicrm_api3('OptionValue', 'get', $params);
15 }
16 catch (CiviCRM_API3_Exception $e) {
17 // Handle error here.
18 $errorMessage = $e->getMessage();
19 $errorCode = $e->getErrorCode();
20 $errorData = $e->getExtraParams();
21 return [
22 'is_error' => 1,
23 'error_message' => $errorMessage,
24 'error_code' => $errorCode,
25 'error_data' => $errorData,
26 ];
27 }
28
29 return $result;
30 }
31
32 /**
33 * Function returns array of result expected from previous function.
34 *
35 * @return array
36 * API result array
37 */
38 function option_value_get_expectedresult() {
39
40 $expectedResult = [
41 'is_error' => 0,
42 'version' => 3,
43 'count' => 5,
44 'values' => [
45 '1' => [
46 'id' => '1',
47 'option_group_id' => '1',
48 'label' => 'Phone',
49 'value' => '1',
50 'name' => 'Phone',
51 'filter' => 0,
52 'weight' => '1',
53 'is_optgroup' => 0,
54 'is_reserved' => 0,
55 'is_active' => '1',
56 ],
57 '2' => [
58 'id' => '2',
59 'option_group_id' => '1',
60 'label' => 'Email',
61 'value' => '2',
62 'name' => 'Email',
63 'filter' => 0,
64 'weight' => '2',
65 'is_optgroup' => 0,
66 'is_reserved' => 0,
67 'is_active' => '1',
68 ],
69 '3' => [
70 'id' => '3',
71 'option_group_id' => '1',
72 'label' => 'Postal Mail',
73 'value' => '3',
74 'name' => 'Postal Mail',
75 'filter' => 0,
76 'weight' => '3',
77 'is_optgroup' => 0,
78 'is_reserved' => 0,
79 'is_active' => '1',
80 ],
81 '4' => [
82 'id' => '4',
83 'option_group_id' => '1',
84 'label' => 'SMS',
85 'value' => '4',
86 'name' => 'SMS',
87 'filter' => 0,
88 'weight' => '4',
89 'is_optgroup' => 0,
90 'is_reserved' => 0,
91 'is_active' => '1',
92 ],
93 '5' => [
94 'id' => '5',
95 'option_group_id' => '1',
96 'label' => 'Fax',
97 'value' => '5',
98 'name' => 'Fax',
99 'filter' => 0,
100 'weight' => '5',
101 'is_optgroup' => 0,
102 'is_reserved' => 0,
103 'is_active' => '1',
104 ],
105 ],
106 ];
107
108 return $expectedResult;
109 }
110
111 /*
112 * This example has been generated from the API test suite.
113 * The test that created it is called "testGetOptionGroup"
114 * and can be found at:
115 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/OptionValueTest.php
116 *
117 * You can see the outcome of the API tests at
118 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
119 *
120 * To Learn about the API read
121 * https://docs.civicrm.org/dev/en/latest/api/
122 *
123 * Browse the API on your own site with the API Explorer. It is in the main
124 * CiviCRM menu, under: Support > Development > API Explorer.
125 *
126 * Read more about testing here
127 * https://docs.civicrm.org/dev/en/latest/testing/
128 *
129 * API Standards documentation:
130 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
131 */