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