Merge pull request #5035 from TeNNoX/master
[civicrm-core.git] / api / v3 / examples / CustomValue / formatFieldName.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 custom_value get API.
10 *
11 * utilises field names
12 *
13 * @return array
14 * API result array
15 */
16 function custom_value_get_example() {
17 $params = array(
18 'id' => 2,
19 'entity_id' => 2,
20 'format.field_names' => 1,
21 );
22
23 try{
24 $result = civicrm_api3('custom_value', 'get', $params);
25 }
26 catch (CiviCRM_API3_Exception $e) {
27 // Handle error here.
28 $errorMessage = $e->getMessage();
29 $errorCode = $e->getErrorCode();
30 $errorData = $e->getExtraParams();
31 return array(
32 'error' => $errorMessage,
33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 );
36 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function custom_value_get_expectedresult() {
48
49 $expectedResult = array(
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 7,
53 'values' => array(
54 'mySingleField' => array(
55 'entity_id' => '2',
56 'latest' => 'value 1',
57 'id' => 'mySingleField',
58 ),
59 'field_12' => array(
60 'entity_id' => '2',
61 'latest' => 'value 3',
62 'id' => 'field_12',
63 '1' => 'value 2',
64 '2' => 'value 3',
65 ),
66 'field_22' => array(
67 'entity_id' => '2',
68 'latest' => '',
69 'id' => 'field_22',
70 '1' => 'warm beer',
71 '2' => '',
72 ),
73 'field_32' => array(
74 'entity_id' => '2',
75 'latest' => '',
76 'id' => 'field_32',
77 '1' => 'fl* w*',
78 '2' => '',
79 ),
80 'field_13' => array(
81 'entity_id' => '2',
82 'latest' => 'coffee',
83 'id' => 'field_13',
84 '1' => 'defaultValue',
85 '2' => 'coffee',
86 ),
87 'field_23' => array(
88 'entity_id' => '2',
89 'latest' => 'value 4',
90 'id' => 'field_23',
91 '1' => '',
92 '2' => 'value 4',
93 ),
94 'field_33' => array(
95 'entity_id' => '2',
96 'latest' => '',
97 'id' => 'field_33',
98 '1' => 'vegemite',
99 '2' => '',
100 ),
101 ),
102 );
103
104 return $expectedResult;
105 }
106
107 /**
108 * This example has been generated from the API test suite.
109 * The test that created it is called
110 * testGetMultipleCustomValues
111 * and can be found in
112 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CustomValueTest.php
113 *
114 * You can see the outcome of the API tests at
115 * https://test.civicrm.org/job/CiviCRM-master-git/
116 *
117 * To Learn about the API read
118 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
119 *
120 * Browse the api on your own site with the api explorer
121 * http://MYSITE.ORG/path/to/civicrm/api/explorer
122 *
123 * Read more about testing here
124 * http://wiki.civicrm.org/confluence/display/CRM/Testing
125 *
126 * API Standards documentation:
127 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
128 */