Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Event.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function event_create_example() { | |
cf8f0fff | 9 | $params = [ |
50fb255d | 10 | 'title' => 'Annual CiviCRM meet', |
4edefac7 | 11 | 'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now', |
50fb255d | 12 | 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', |
13 | 'event_type_id' => 1, | |
14 | 'is_public' => 1, | |
15 | 'start_date' => 20081021, | |
16 | 'end_date' => 20081023, | |
17 | 'is_online_registration' => 1, | |
18 | 'registration_start_date' => 20080601, | |
19 | 'registration_end_date' => '2008-10-15', | |
20 | 'max_participants' => 100, | |
21 | 'event_full_text' => 'Sorry! We are already full', | |
22 | 'is_monetary' => 0, | |
23 | 'is_active' => 1, | |
24 | 'is_show_location' => 0, | |
cf8f0fff | 25 | ]; |
6a488035 | 26 | |
50fb255d | 27 | try{ |
a828d7b8 | 28 | $result = civicrm_api3('Event', 'create', $params); |
50fb255d | 29 | } |
30 | catch (CiviCRM_API3_Exception $e) { | |
31 | // Handle error here. | |
32 | $errorMessage = $e->getMessage(); | |
33 | $errorCode = $e->getErrorCode(); | |
34 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 35 | return [ |
5be22f39 | 36 | 'is_error' => 1, |
37 | 'error_message' => $errorMessage, | |
50fb255d | 38 | 'error_code' => $errorCode, |
39 | 'error_data' => $errorData, | |
cf8f0fff | 40 | ]; |
50fb255d | 41 | } |
42 | ||
43 | return $result; | |
6a488035 TO |
44 | } |
45 | ||
fb32de45 | 46 | /** |
50fb255d | 47 | * Function returns array of result expected from previous function. |
48 | * | |
49 | * @return array | |
50 | * API result array | |
6a488035 | 51 | */ |
50fb255d | 52 | function event_create_expectedresult() { |
6a488035 | 53 | |
cf8f0fff | 54 | $expectedResult = [ |
50fb255d | 55 | 'is_error' => 0, |
56 | 'version' => 3, | |
57 | 'count' => 1, | |
58 | 'id' => 3, | |
cf8f0fff CW |
59 | 'values' => [ |
60 | '3' => [ | |
50fb255d | 61 | 'id' => '3', |
62 | 'title' => 'Annual CiviCRM meet', | |
4edefac7 | 63 | 'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now', |
50fb255d | 64 | 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', |
65 | 'event_type_id' => '1', | |
50fb255d | 66 | 'is_public' => '1', |
67 | 'start_date' => '2013-07-29 00:00:00', | |
68 | 'end_date' => '2013-08-04 00:00:00', | |
69 | 'is_online_registration' => '1', | |
70 | 'registration_link_text' => '', | |
71 | 'registration_start_date' => '20080601000000', | |
72 | 'registration_end_date' => '20081015000000', | |
73 | 'max_participants' => '100', | |
74 | 'event_full_text' => 'Sorry! We are already full', | |
75 | 'is_monetary' => 0, | |
76 | 'financial_type_id' => '', | |
77 | 'payment_processor' => '', | |
78 | 'is_map' => '', | |
79 | 'is_active' => '1', | |
80 | 'fee_label' => '', | |
81 | 'is_show_location' => 0, | |
82 | 'loc_block_id' => '', | |
83 | 'default_role_id' => '', | |
84 | 'intro_text' => '', | |
85 | 'footer_text' => '', | |
86 | 'confirm_title' => '', | |
87 | 'confirm_text' => '', | |
88 | 'confirm_footer_text' => '', | |
89 | 'is_email_confirm' => '', | |
90 | 'confirm_email_text' => '', | |
91 | 'confirm_from_name' => '', | |
92 | 'confirm_from_email' => '', | |
93 | 'cc_confirm' => '', | |
94 | 'bcc_confirm' => '', | |
95 | 'default_fee_id' => '', | |
96 | 'default_discount_fee_id' => '', | |
97 | 'thankyou_title' => '', | |
98 | 'thankyou_text' => '', | |
99 | 'thankyou_footer_text' => '', | |
100 | 'is_pay_later' => '', | |
101 | 'pay_later_text' => '', | |
102 | 'pay_later_receipt' => '', | |
103 | 'is_partial_payment' => '', | |
104 | 'initial_amount_label' => '', | |
105 | 'initial_amount_help_text' => '', | |
106 | 'min_initial_amount' => '', | |
107 | 'is_multiple_registrations' => '', | |
5be22f39 | 108 | 'max_additional_participants' => '', |
50fb255d | 109 | 'allow_same_participant_emails' => '', |
110 | 'has_waitlist' => '', | |
111 | 'requires_approval' => '', | |
112 | 'expiration_time' => '', | |
5be22f39 | 113 | 'allow_selfcancelxfer' => '', |
114 | 'selfcancelxfer_time' => '', | |
50fb255d | 115 | 'waitlist_text' => '', |
116 | 'approval_req_text' => '', | |
117 | 'is_template' => 0, | |
118 | 'template_title' => '', | |
119 | 'created_id' => '', | |
120 | 'created_date' => '2013-07-28 08:49:19', | |
121 | 'currency' => '', | |
122 | 'campaign_id' => '', | |
123 | 'is_share' => '', | |
124 | 'is_confirm_enabled' => '', | |
125 | 'parent_event_id' => '', | |
126 | 'slot_label_id' => '', | |
127 | 'dedupe_rule_group_id' => '', | |
128 | 'is_billing_required' => '', | |
cf8f0fff CW |
129 | ], |
130 | ], | |
131 | ]; | |
6a488035 | 132 | |
fb32de45 | 133 | return $expectedResult; |
6a488035 TO |
134 | } |
135 | ||
a828d7b8 | 136 | /* |
50fb255d | 137 | * This example has been generated from the API test suite. |
a828d7b8 CW |
138 | * The test that created it is called "testCreateEventSuccess" |
139 | * and can be found at: | |
69d79249 | 140 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EventTest.php |
6a488035 TO |
141 | * |
142 | * You can see the outcome of the API tests at | |
8390b11b | 143 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
6a488035 TO |
144 | * |
145 | * To Learn about the API read | |
8390b11b | 146 | * https://docs.civicrm.org/dev/en/latest/api/ |
6a488035 | 147 | * |
8390b11b SL |
148 | * Browse the API on your own site with the API Explorer. It is in the main |
149 | * CiviCRM menu, under: Support > Development > API Explorer. | |
6a488035 TO |
150 | * |
151 | * Read more about testing here | |
8390b11b | 152 | * https://docs.civicrm.org/dev/en/latest/testing/ |
6a488035 TO |
153 | * |
154 | * API Standards documentation: | |
8390b11b | 155 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
b259a4ab | 156 | */ |