Update Test generated examples
[civicrm-core.git] / api / v3 / examples / Participant / Create.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Participant.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function participant_create_example() {
9 $params = array(
1d8ee3d6 10 'contact_id' => 2,
11 'event_id' => 2,
50fb255d 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 );
6a488035 18
50fb255d 19 try{
a828d7b8 20 $result = civicrm_api3('Participant', 'create', $params);
50fb255d 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(
5be22f39 28 'is_error' => 1,
29 'error_message' => $errorMessage,
50fb255d 30 'error_code' => $errorCode,
31 'error_data' => $errorData,
32 );
33 }
34
35 return $result;
6a488035
TO
36}
37
fb32de45 38/**
50fb255d 39 * Function returns array of result expected from previous function.
40 *
41 * @return array
42 * API result array
6a488035 43 */
50fb255d 44function participant_create_expectedresult() {
6a488035 45
53ca8fd7 46 $expectedResult = array(
50fb255d 47 'is_error' => 0,
48 'version' => 3,
49 'count' => 1,
50 'id' => 4,
51 'values' => array(
53ca8fd7 52 '4' => array(
50fb255d 53 'id' => '4',
1d8ee3d6 54 'contact_id' => '2',
55 'event_id' => '2',
50fb255d 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' => '',
5be22f39 71 'transferred_to_contact_id' => '',
50fb255d 72 ),
6a488035 73 ),
50fb255d 74 );
6a488035 75
fb32de45 76 return $expectedResult;
6a488035
TO
77}
78
a828d7b8 79/*
50fb255d 80* This example has been generated from the API test suite.
a828d7b8
CW
81* The test that created it is called "testCreateWithCustom"
82* and can be found at:
69d79249 83* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ParticipantTest.php
6a488035
TO
84*
85* You can see the outcome of the API tests at
69d79249 86* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
87*
88* To Learn about the API read
69d79249 89* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 90*
69d79249 91* Browse the api on your own site with the api explorer
41d4d31f 92* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
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
b259a4ab 99*/