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