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