Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
3 | * Test Generated example of using participant create API | |
4 | * single function to create contact w partipation & contribution. Note that in the | |
5 | case of 'contribution' the 'create' is implied (api.contribution.create) * | |
6a488035 TO |
6 | */ |
7 | function participant_create_example(){ | |
53ca8fd7 | 8 | $params = array( |
6a488035 TO |
9 | 'contact_type' => 'Individual', |
10 | 'display_name' => 'dlobo', | |
53ca8fd7 | 11 | 'api.participant' => array( |
fb32de45 | 12 | 'event_id' => 39, |
6a488035 TO |
13 | 'status_id' => 1, |
14 | 'role_id' => 1, | |
15 | 'format.only_id' => 1, | |
16 | ), | |
53ca8fd7 | 17 | 'api.contribution.create' => array( |
6a488035 TO |
18 | 'financial_type_id' => 1, |
19 | 'total_amount' => 100, | |
20 | 'format.only_id' => 1, | |
21 | ), | |
53ca8fd7 | 22 | 'api.participant_payment.create' => array( |
6a488035 TO |
23 | 'contribution_id' => '$value.api.contribution.create', |
24 | 'participant_id' => '$value.api.participant', | |
25 | ), | |
26 | ); | |
27 | ||
fb32de45 | 28 | try{ |
29 | $result = civicrm_api3('participant', 'create', $params); | |
30 | } | |
31 | catch (CiviCRM_API3_Exception $e) { | |
32 | // handle error here | |
33 | $errorMessage = $e->getMessage(); | |
34 | $errorCode = $e->getErrorCode(); | |
35 | $errorData = $e->getExtraParams(); | |
36 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); | |
37 | } | |
6a488035 | 38 | |
fb32de45 | 39 | return $result; |
6a488035 TO |
40 | } |
41 | ||
fb32de45 | 42 | /** |
6a488035 TO |
43 | * Function returns array of result expected from previous function |
44 | */ | |
45 | function participant_create_expectedresult(){ | |
46 | ||
53ca8fd7 | 47 | $expectedResult = array( |
6a488035 TO |
48 | 'is_error' => 0, |
49 | 'version' => 3, | |
50 | 'count' => 1, | |
51 | 'id' => 5, | |
53ca8fd7 | 52 | 'values' => array( |
53 | '5' => array( | |
6a488035 TO |
54 | 'id' => '5', |
55 | 'contact_type' => 'Individual', | |
56 | 'contact_sub_type' => '', | |
57 | 'do_not_email' => 0, | |
58 | 'do_not_phone' => 0, | |
59 | 'do_not_mail' => 0, | |
60 | 'do_not_sms' => 0, | |
61 | 'do_not_trade' => 0, | |
62 | 'is_opt_out' => 0, | |
63 | 'legal_identifier' => '', | |
64 | 'external_identifier' => '', | |
65 | 'sort_name' => '', | |
66 | 'display_name' => 'dlobo', | |
67 | 'nick_name' => '', | |
68 | 'legal_name' => '', | |
69 | 'image_URL' => '', | |
70 | 'preferred_communication_method' => '', | |
71 | 'preferred_language' => 'en_US', | |
72 | 'preferred_mail_format' => 'Both', | |
73 | 'hash' => '67eac7789eaee00', | |
74 | 'api_key' => '', | |
75 | 'first_name' => '', | |
76 | 'middle_name' => '', | |
77 | 'last_name' => '', | |
6a488035 TO |
78 | 'email_greeting_id' => '1', |
79 | 'email_greeting_custom' => '', | |
80 | 'email_greeting_display' => '', | |
81 | 'postal_greeting_id' => '1', | |
82 | 'postal_greeting_custom' => '', | |
83 | 'postal_greeting_display' => '', | |
84 | 'addressee_id' => '1', | |
85 | 'addressee_custom' => '', | |
86 | 'addressee_display' => '', | |
87 | 'job_title' => '', | |
88 | 'gender_id' => '', | |
89 | 'birth_date' => '', | |
90 | 'is_deceased' => 0, | |
91 | 'deceased_date' => '', | |
92 | 'household_name' => '', | |
93 | 'primary_contact_id' => '', | |
94 | 'organization_name' => '', | |
95 | 'sic_code' => '', | |
96 | 'user_unique_id' => '', | |
fb32de45 | 97 | 'created_date' => '2013-07-28 05:52:14', |
6a488035 TO |
98 | 'modified_date' => '2012-11-14 16:02:35', |
99 | 'api.participant' => 4, | |
100 | 'api.contribution.create' => 1, | |
53ca8fd7 | 101 | 'api.participant_payment.create' => array( |
6a488035 TO |
102 | 'is_error' => 0, |
103 | 'version' => 3, | |
104 | 'count' => 1, | |
105 | 'id' => 1, | |
53ca8fd7 | 106 | 'values' => array( |
107 | '0' => array( | |
6a488035 TO |
108 | 'id' => '1', |
109 | 'participant_id' => '4', | |
110 | 'contribution_id' => '1', | |
111 | ), | |
112 | ), | |
113 | ), | |
114 | ), | |
115 | ), | |
116 | ); | |
117 | ||
fb32de45 | 118 | return $expectedResult; |
6a488035 TO |
119 | } |
120 | ||
121 | ||
122 | /* | |
123 | * This example has been generated from the API test suite. The test that created it is called | |
124 | * | |
125 | * testCreateParticipantWithPayment and can be found in | |
126 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ParticipantTest.php | |
127 | * | |
128 | * You can see the outcome of the API tests at | |
129 | * http://tests.dev.civicrm.org/trunk/results-api_v3 | |
130 | * | |
131 | * To Learn about the API read | |
132 | * http://book.civicrm.org/developer/current/techniques/api/ | |
133 | * | |
134 | * and review the wiki at | |
135 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs | |
136 | * | |
137 | * Read more about testing here | |
138 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
139 | * | |
140 | * API Standards documentation: | |
141 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
142 | */ |