Merge pull request #5216 from atif-shaikh/CRM-15792
[civicrm-core.git] / api / v3 / examples / Batch / Update.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
3 * Test Generated example of using batch update API.
4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function batch_update_example() {
9 $params = array(
10 'name' => 'New_Batch_04',
11 'title' => 'New Batch 04',
12 'description' => 'This is description for New Batch 04',
13 'total' => '400.44',
14 'item_count' => 4,
15 'id' => 3,
16 );
6a488035 17
50fb255d 18 try{
19 $result = civicrm_api3('batch', 'update', $params);
20 }
21 catch (CiviCRM_API3_Exception $e) {
22 // Handle error here.
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
26 return array(
27 'error' => $errorMessage,
28 'error_code' => $errorCode,
29 'error_data' => $errorData,
30 );
31 }
32
33 return $result;
6a488035
TO
34}
35
fb32de45 36/**
50fb255d 37 * Function returns array of result expected from previous function.
38 *
39 * @return array
40 * API result array
6a488035 41 */
50fb255d 42function batch_update_expectedresult() {
6a488035 43
edb0d67a 44 $expectedResult = array(
50fb255d 45 'is_error' => 0,
46 'version' => 3,
47 'count' => 1,
48 'id' => 3,
49 'values' => array(
50 '3' => array(
51 'id' => '3',
52 'name' => 'New_Batch_04',
53 'title' => 'New Batch 04',
54 'description' => 'This is description for New Batch 04',
55 'created_id' => '',
56 'created_date' => '',
57 'modified_id' => '',
58 'modified_date' => '',
59 'saved_search_id' => '',
60 'status_id' => '',
61 'type_id' => '',
62 'mode_id' => '',
63 'total' => '400.44',
64 'item_count' => '4',
65 'payment_instrument_id' => '',
66 'exported_date' => '',
67 'data' => '',
68 ),
6a488035 69 ),
50fb255d 70 );
6a488035 71
fb32de45 72 return $expectedResult;
6a488035
TO
73}
74
50fb255d 75/**
76* This example has been generated from the API test suite.
77* The test that created it is called
78* testUpdate
79* and can be found in
69d79249 80* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/BatchTest.php
6a488035
TO
81*
82* You can see the outcome of the API tests at
69d79249 83* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
84*
85* To Learn about the API read
69d79249 86* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 87*
69d79249 88* Browse the api on your own site with the api explorer
41d4d31f 89* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
90*
91* Read more about testing here
92* http://wiki.civicrm.org/confluence/display/CRM/Testing
93*
94* API Standards documentation:
95* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 96*/