Merge pull request #2383 from kurund/CRM-13981
[civicrm-core.git] / api / v3 / examples / GrantCreate.php
1 <?php
2 /**
3 * Test Generated example of using grant create API
4 * *
5 */
6 function grant_create_example(){
7 $params = array(
8 'contact_id' => 3,
9 'application_received_date' => 'now',
10 'decision_date' => 'next Monday',
11 'amount_total' => '500',
12 'status_id' => 1,
13 'rationale' => 'Just Because',
14 'currency' => 'USD',
15 'grant_type_id' => 1,
16 );
17
18 try{
19 $result = civicrm_api3('grant', 'create', $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('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
27 }
28
29 return $result;
30 }
31
32 /**
33 * Function returns array of result expected from previous function
34 */
35 function grant_create_expectedresult(){
36
37 $expectedResult = array(
38 'is_error' => 0,
39 'version' => 3,
40 'count' => 1,
41 'id' => 1,
42 'values' => array(
43 '1' => array(
44 'id' => '1',
45 'contact_id' => '3',
46 'application_received_date' => '20130728084957',
47 'decision_date' => '20130805000000',
48 'money_transfer_date' => '',
49 'grant_due_date' => '',
50 'grant_report_received' => '',
51 'grant_type_id' => '1',
52 'amount_total' => '500',
53 'amount_requested' => '',
54 'amount_granted' => '',
55 'currency' => 'USD',
56 'rationale' => 'Just Because',
57 'status_id' => '1',
58 'financial_type_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 * testCreateGrant and can be found in
71 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/GrantTest.php
72 *
73 * You can see the outcome of the API tests at
74 * http://tests.dev.civicrm.org/trunk/results-api_v3
75 *
76 * To Learn about the API read
77 * http://book.civicrm.org/developer/current/techniques/api/
78 *
79 * and review the wiki at
80 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
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 */