commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / api / v3 / examples / Mailing / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Mailing.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function mailing_create_example() {
9 $params = array(
10 'subject' => 'Hello {contact.display_name}',
11 'body_text' => 'This is {contact.display_name}.
12 {domain.address}{action.optOutUrl}',
13 'body_html' => '<p>This is {contact.display_name}.</p><p>{domain.address}{action.optOutUrl}</p>',
14 'name' => 'mailing name',
15 'created_id' => 9,
16 'header_id' => '',
17 'footer_id' => '',
18 'groups' => array(
19 'include' => array(
20 '0' => 7,
21 ),
22 'exclude' => array(
23 '0' => 8,
24 ),
25 ),
26 'mailings' => array(
27 'include' => array(),
28 'exclude' => array(),
29 ),
30 'options' => array(
31 'force_rollback' => 1,
32 ),
33 'api.mailing_job.create' => 1,
34 'api.MailingRecipients.get' => array(
35 'mailing_id' => '$value.id',
36 'api.contact.getvalue' => array(
37 'return' => 'display_name',
38 ),
39 'api.email.getvalue' => array(
40 'return' => 'email',
41 ),
42 ),
43 );
44
45 try{
46 $result = civicrm_api3('Mailing', 'create', $params);
47 }
48 catch (CiviCRM_API3_Exception $e) {
49 // Handle error here.
50 $errorMessage = $e->getMessage();
51 $errorCode = $e->getErrorCode();
52 $errorData = $e->getExtraParams();
53 return array(
54 'error' => $errorMessage,
55 'error_code' => $errorCode,
56 'error_data' => $errorData,
57 );
58 }
59
60 return $result;
61 }
62
63 /**
64 * Function returns array of result expected from previous function.
65 *
66 * @return array
67 * API result array
68 */
69 function mailing_create_expectedresult() {
70
71 $expectedResult = array(
72 'is_error' => 0,
73 'version' => 3,
74 'count' => 1,
75 'id' => 4,
76 'values' => array(
77 '4' => array(
78 'id' => '4',
79 'domain_id' => '1',
80 'header_id' => '',
81 'footer_id' => '',
82 'reply_id' => '8',
83 'unsubscribe_id' => '5',
84 'resubscribe_id' => '6',
85 'optout_id' => '7',
86 'name' => 'mailing name',
87 'from_name' => 'FIXME',
88 'from_email' => 'info@EXAMPLE.ORG',
89 'replyto_email' => 'info@EXAMPLE.ORG',
90 'subject' => 'Hello {contact.display_name}',
91 'body_text' => 'This is {contact.display_name}.
92 {domain.address}{action.optOutUrl}',
93 'body_html' => '<p>This is {contact.display_name}.</p><p>{domain.address}{action.optOutUrl}</p>',
94 'url_tracking' => '1',
95 'forward_replies' => '',
96 'auto_responder' => '',
97 'open_tracking' => '1',
98 'is_completed' => '',
99 'msg_template_id' => '',
100 'override_verp' => '1',
101 'created_id' => '9',
102 'created_date' => '2013-07-28 08:49:19',
103 'scheduled_id' => '',
104 'scheduled_date' => '',
105 'approver_id' => '',
106 'approval_date' => '',
107 'approval_status_id' => '',
108 'approval_note' => '',
109 'is_archived' => '',
110 'visibility' => 'Public Pages',
111 'campaign_id' => '',
112 'dedupe_email' => '1',
113 'sms_provider_id' => '',
114 'hash' => '',
115 'location_type_id' => '',
116 'email_selection_method' => '',
117 'api.mailing_job.create' => array(
118 'is_error' => 0,
119 'version' => 3,
120 'count' => 1,
121 'id' => 5,
122 'values' => array(
123 '0' => array(
124 'id' => '5',
125 'mailing_id' => '4',
126 'scheduled_date' => '20130728085413',
127 'start_date' => '',
128 'end_date' => '',
129 'status' => 'Scheduled',
130 'is_test' => 0,
131 'job_type' => '',
132 'parent_id' => '',
133 'job_offset' => '',
134 'job_limit' => '',
135 ),
136 ),
137 ),
138 'api.MailingRecipients.get' => array(
139 'is_error' => 0,
140 'version' => 3,
141 'count' => 1,
142 'id' => 4,
143 'values' => array(
144 '0' => array(
145 'id' => '4',
146 'mailing_id' => '4',
147 'contact_id' => '10',
148 'email_id' => '10',
149 'api.contact.getvalue' => 'Mr. Includer Person II',
150 'api.email.getvalue' => 'include.me@example.org',
151 ),
152 ),
153 ),
154 ),
155 ),
156 );
157
158 return $expectedResult;
159 }
160
161 /*
162 * This example has been generated from the API test suite.
163 * The test that created it is called "testMailerPreviewRecipients"
164 * and can be found at:
165 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MailingTest.php
166 *
167 * You can see the outcome of the API tests at
168 * https://test.civicrm.org/job/CiviCRM-master-git/
169 *
170 * To Learn about the API read
171 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
172 *
173 * Browse the api on your own site with the api explorer
174 * http://MYSITE.ORG/path/to/civicrm/api
175 *
176 * Read more about testing here
177 * http://wiki.civicrm.org/confluence/display/CRM/Testing
178 *
179 * API Standards documentation:
180 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
181 */