Merge pull request #13948 from civicrm/5.12
[civicrm-core.git] / api / v3 / examples / Grant / Create.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Grant.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function grant_create_example() {
cf8f0fff 9 $params = [
50fb255d 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,
cf8f0fff 18 ];
6a488035 19
50fb255d 20 try{
a828d7b8 21 $result = civicrm_api3('Grant', 'create', $params);
50fb255d 22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
cf8f0fff 28 return [
5be22f39 29 'is_error' => 1,
30 'error_message' => $errorMessage,
50fb255d 31 'error_code' => $errorCode,
32 'error_data' => $errorData,
cf8f0fff 33 ];
50fb255d 34 }
35
36 return $result;
6a488035
TO
37}
38
fb32de45 39/**
50fb255d 40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
6a488035 44 */
50fb255d 45function grant_create_expectedresult() {
6a488035 46
cf8f0fff 47 $expectedResult = [
50fb255d 48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
51 'id' => 1,
cf8f0fff
CW
52 'values' => [
53 '1' => [
50fb255d 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' => '',
cf8f0fff
CW
69 ],
70 ],
71 ];
6a488035 72
fb32de45 73 return $expectedResult;
6a488035
TO
74}
75
a828d7b8 76/*
50fb255d 77* This example has been generated from the API test suite.
a828d7b8
CW
78* The test that created it is called "testCreateGrant"
79* and can be found at:
69d79249 80* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GrantTest.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*/