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