Merge pull request #9570 from colemanw/CRM-19773-report
[civicrm-core.git] / api / v3 / examples / Campaign / Create.php
CommitLineData
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 */
11function 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(
5be22f39 27 'is_error' => 1,
28 'error_message' => $errorMessage,
50fb255d 29 'error_code' => $errorCode,
30 'error_data' => $errorData,
31 );
32 }
33
34 return $result;
6a488035
TO
35}
36
fb32de45 37/**
50fb255d 38 * Function returns array of result expected from previous function.
39 *
40 * @return array
41 * API result array
6a488035 42 */
50fb255d 43function campaign_create_expectedresult() {
6a488035 44
edb0d67a 45 $expectedResult = array(
50fb255d 46 'is_error' => 0,
47 'version' => 3,
48 'count' => 1,
49 'id' => 1,
50 'values' => array(
edb0d67a 51 '1' => array(
50fb255d 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' => '',
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 ),
6a488035 70 ),
50fb255d 71 );
6a488035 72
fb32de45 73 return $expectedResult;
6a488035
TO
74}
75
a828d7b8 76/*
50fb255d 77* This example has been generated from the API test suite.
a828d7b8
CW
78* The test that created it is called "testCreateCampaign"
79* and can be found at:
69d79249 80* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CampaignTest.php
6a488035
TO
81*
82* You can see the outcome of the API tests at
69d79249 83* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
84*
85* To Learn about the API read
69d79249 86* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 87*
69d79249 88* Browse the api on your own site with the api explorer
41d4d31f 89* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
90*
91* Read more about testing here
92* http://wiki.civicrm.org/confluence/display/CRM/Testing
93*
94* API Standards documentation:
95* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 96*/