Merge pull request #5035 from TeNNoX/master
[civicrm-core.git] / api / v3 / examples / PriceField / Create.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 price_field create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function price_field_create_example() {
16 $params = array(
17 'price_set_id' => 3,
18 'name' => 'grassvariety',
19 'label' => 'Grass Variety',
20 'html_type' => 'Text',
21 'is_enter_qty' => 1,
22 'is_active' => 1,
23 );
24
25 try{
26 $result = civicrm_api3('price_field', 'create', $params);
27 }
28 catch (CiviCRM_API3_Exception $e) {
29 // Handle error here.
30 $errorMessage = $e->getMessage();
31 $errorCode = $e->getErrorCode();
32 $errorData = $e->getExtraParams();
33 return array(
34 'error' => $errorMessage,
35 'error_code' => $errorCode,
36 'error_data' => $errorData,
37 );
38 }
39
40 return $result;
41 }
42
43 /**
44 * Function returns array of result expected from previous function.
45 *
46 * @return array
47 * API result array
48 */
49 function price_field_create_expectedresult() {
50
51 $expectedResult = array(
52 'is_error' => 0,
53 'version' => 3,
54 'count' => 1,
55 'id' => 2,
56 'values' => array(
57 '2' => array(
58 'id' => '2',
59 'price_set_id' => '3',
60 'name' => 'grassvariety',
61 'label' => 'Grass Variety',
62 'html_type' => 'Text',
63 'is_enter_qty' => '1',
64 'help_pre' => '',
65 'help_post' => '',
66 'weight' => '',
67 'is_display_amounts' => '',
68 'options_per_line' => '',
69 'is_active' => '1',
70 'is_required' => '',
71 'active_on' => '',
72 'expire_on' => '',
73 'javascript' => '',
74 'visibility_id' => '',
75 ),
76 ),
77 );
78
79 return $expectedResult;
80 }
81
82 /**
83 * This example has been generated from the API test suite.
84 * The test that created it is called
85 * testCreatePriceField
86 * and can be found in
87 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PriceFieldTest.php
88 *
89 * You can see the outcome of the API tests at
90 * https://test.civicrm.org/job/CiviCRM-master-git/
91 *
92 * To Learn about the API read
93 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
94 *
95 * Browse the api on your own site with the api explorer
96 * http://MYSITE.ORG/path/to/civicrm/api/explorer
97 *
98 * Read more about testing here
99 * http://wiki.civicrm.org/confluence/display/CRM/Testing
100 *
101 * API Standards documentation:
102 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
103 */