15aa07367eb16d639b97a40559e9ef68f921b359
[civicrm-core.git] / api / v3 / examples / Participant / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Participant.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function participant_create_example() {
9 $params = array(
10 'contact_id' => 2,
11 'event_id' => 2,
12 'status_id' => 1,
13 'role_id' => 1,
14 'register_date' => '2007-07-21 00:00:00',
15 'source' => 'Online Event Registration: API Testing',
16 'custom_1' => 'custom string',
17 );
18
19 try{
20 $result = civicrm_api3('Participant', 'create', $params);
21 }
22 catch (CiviCRM_API3_Exception $e) {
23 // Handle error here.
24 $errorMessage = $e->getMessage();
25 $errorCode = $e->getErrorCode();
26 $errorData = $e->getExtraParams();
27 return array(
28 'is_error' => 1,
29 'error_message' => $errorMessage,
30 'error_code' => $errorCode,
31 'error_data' => $errorData,
32 );
33 }
34
35 return $result;
36 }
37
38 /**
39 * Function returns array of result expected from previous function.
40 *
41 * @return array
42 * API result array
43 */
44 function participant_create_expectedresult() {
45
46 $expectedResult = array(
47 'is_error' => 0,
48 'version' => 3,
49 'count' => 1,
50 'id' => 4,
51 'values' => array(
52 '4' => array(
53 'id' => '4',
54 'contact_id' => '2',
55 'event_id' => '2',
56 'status_id' => '1',
57 'role_id' => '1',
58 'register_date' => '20070721000000',
59 'source' => 'Online Event Registration: API Testing',
60 'fee_level' => '',
61 'is_test' => '',
62 'is_pay_later' => '',
63 'fee_amount' => '',
64 'registered_by_id' => '',
65 'discount_id' => '',
66 'fee_currency' => '',
67 'campaign_id' => '',
68 'discount_amount' => '',
69 'cart_id' => '',
70 'must_wait' => '',
71 'transferred_to_contact_id' => '',
72 ),
73 ),
74 );
75
76 return $expectedResult;
77 }
78
79 /*
80 * This example has been generated from the API test suite.
81 * The test that created it is called "testCreateWithCustom"
82 * and can be found at:
83 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ParticipantTest.php
84 *
85 * You can see the outcome of the API tests at
86 * https://test.civicrm.org/job/CiviCRM-master-git/
87 *
88 * To Learn about the API read
89 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
90 *
91 * Browse the api on your own site with the api explorer
92 * http://MYSITE.ORG/path/to/civicrm/api
93 *
94 * Read more about testing here
95 * http://wiki.civicrm.org/confluence/display/CRM/Testing
96 *
97 * API Standards documentation:
98 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
99 */