Merge branch 4.5 into master
[civicrm-core.git] / api / v3 / examples / Batch / 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 batch create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function batch_create_example() {
16 $params = array(
17 'name' => 'New_Batch_03',
18 'title' => 'New Batch 03',
19 'description' => 'This is description for New Batch 03',
20 'total' => '300.33',
21 'item_count' => 3,
22 'status_id' => 1,
23 );
24
25 try{
26 $result = civicrm_api3('batch', '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 batch_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 'name' => 'New_Batch_03',
60 'title' => 'New Batch 03',
61 'description' => 'This is description for New Batch 03',
62 'created_id' => '',
63 'created_date' => '',
64 'modified_id' => '',
65 'modified_date' => '2012-11-14 16:02:35',
66 'saved_search_id' => '',
67 'status_id' => '1',
68 'type_id' => '',
69 'mode_id' => '',
70 'total' => '300.33',
71 'item_count' => '3',
72 'payment_instrument_id' => '',
73 'exported_date' => '',
74 'data' => '',
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 * testCreate
86 * and can be found in
87 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/BatchTest.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 */