Merge pull request #9570 from colemanw/CRM-19773-report
[civicrm-core.git] / api / v3 / examples / Grant / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Grant.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function grant_create_example() {
9 $params = array(
10 'contact_id' => 3,
11 'application_received_date' => 'now',
12 'decision_date' => 'next Monday',
13 'amount_total' => '500',
14 'status_id' => 1,
15 'rationale' => 'Just Because',
16 'currency' => 'USD',
17 'grant_type_id' => 1,
18 );
19
20 try{
21 $result = civicrm_api3('Grant', 'create', $params);
22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array(
29 'is_error' => 1,
30 'error_message' => $errorMessage,
31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 );
34 }
35
36 return $result;
37 }
38
39 /**
40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
44 */
45 function grant_create_expectedresult() {
46
47 $expectedResult = array(
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
51 'id' => 1,
52 'values' => array(
53 '1' => array(
54 'id' => '1',
55 'contact_id' => '3',
56 'application_received_date' => '20130728084957',
57 'decision_date' => '20130805000000',
58 'money_transfer_date' => '',
59 'grant_due_date' => '',
60 'grant_report_received' => '',
61 'grant_type_id' => '1',
62 'amount_total' => '500',
63 'amount_requested' => '',
64 'amount_granted' => '',
65 'currency' => 'USD',
66 'rationale' => 'Just Because',
67 'status_id' => '1',
68 'financial_type_id' => '',
69 ),
70 ),
71 );
72
73 return $expectedResult;
74 }
75
76 /*
77 * This example has been generated from the API test suite.
78 * The test that created it is called "testCreateGrant"
79 * and can be found at:
80 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GrantTest.php
81 *
82 * You can see the outcome of the API tests at
83 * https://test.civicrm.org/job/CiviCRM-master-git/
84 *
85 * To Learn about the API read
86 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
87 *
88 * Browse the api on your own site with the api explorer
89 * http://MYSITE.ORG/path/to/civicrm/api
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
96 */