Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Campaign.create API. |
50fb255d | 4 | * |
5c49fee0 CW |
5 | * Create a campaign - Note use of relative dates here: |
6 | * @link http://www.php.net/manual/en/datetime.formats.relative.php. | |
50fb255d | 7 | * |
8 | * @return array | |
9 | * API result array | |
10 | */ | |
11 | function campaign_create_example() { | |
12 | $params = array( | |
13 | 'title' => 'campaign title', | |
14 | 'description' => 'Call people, ask for money', | |
15 | 'created_date' => 'first sat of July 2008', | |
16 | ); | |
6a488035 | 17 | |
50fb255d | 18 | try{ |
a828d7b8 | 19 | $result = civicrm_api3('Campaign', 'create', $params); |
50fb255d | 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( | |
27 | 'error' => $errorMessage, | |
28 | 'error_code' => $errorCode, | |
29 | 'error_data' => $errorData, | |
30 | ); | |
31 | } | |
32 | ||
33 | return $result; | |
6a488035 TO |
34 | } |
35 | ||
fb32de45 | 36 | /** |
50fb255d | 37 | * Function returns array of result expected from previous function. |
38 | * | |
39 | * @return array | |
40 | * API result array | |
6a488035 | 41 | */ |
50fb255d | 42 | function campaign_create_expectedresult() { |
6a488035 | 43 | |
edb0d67a | 44 | $expectedResult = array( |
50fb255d | 45 | 'is_error' => 0, |
46 | 'version' => 3, | |
47 | 'count' => 1, | |
48 | 'id' => 1, | |
49 | 'values' => array( | |
edb0d67a | 50 | '1' => array( |
50fb255d | 51 | 'id' => '1', |
52 | 'name' => 'campaign_title', | |
53 | 'title' => 'campaign title', | |
54 | 'description' => 'Call people, ask for money', | |
55 | 'start_date' => '', | |
56 | 'end_date' => '', | |
57 | 'campaign_type_id' => '', | |
58 | 'status_id' => '', | |
59 | 'external_identifier' => '', | |
60 | 'parent_id' => '', | |
61 | 'is_active' => '', | |
62 | 'created_id' => '', | |
63 | 'created_date' => '2013-07-28 08:49:19', | |
64 | 'last_modified_id' => '', | |
65 | 'last_modified_date' => '', | |
66 | 'goal_general' => '', | |
67 | 'goal_revenue' => '', | |
68 | ), | |
6a488035 | 69 | ), |
50fb255d | 70 | ); |
6a488035 | 71 | |
fb32de45 | 72 | return $expectedResult; |
6a488035 TO |
73 | } |
74 | ||
a828d7b8 | 75 | /* |
50fb255d | 76 | * This example has been generated from the API test suite. |
a828d7b8 CW |
77 | * The test that created it is called "testCreateCampaign" |
78 | * and can be found at: | |
69d79249 | 79 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CampaignTest.php |
6a488035 TO |
80 | * |
81 | * You can see the outcome of the API tests at | |
69d79249 | 82 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
83 | * |
84 | * To Learn about the API read | |
69d79249 | 85 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 86 | * |
69d79249 | 87 | * Browse the api on your own site with the api explorer |
41d4d31f | 88 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
89 | * |
90 | * Read more about testing here | |
91 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
92 | * | |
93 | * API Standards documentation: | |
94 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 95 | */ |