Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-11-09-14-08-33
[civicrm-core.git] / api / v3 / examples / Mailing / GetTokens.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Mailing.gettokens API.
4 *
5 * Demonstrates fetching tokens for one or more entities (in this case "Contact" and "Mailing").
6 * Optionally pass sequential=1 to have output ready-formatted for the select2 widget.
7 *
8 * @return array
9 * API result array
10 */
11 function mailing_gettokens_example() {
12 $params = array(
13 'entity' => array(
14 '0' => 'Contact',
15 '1' => 'Mailing',
16 ),
17 );
18
19 try{
20 $result = civicrm_api3('Mailing', 'gettokens', $params);
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(
28 'error' => $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 mailing_gettokens_expectedresult() {
44
45 $expectedResult = array(
46 'is_error' => 0,
47 'version' => 3,
48 'count' => 82,
49 'values' => array(
50 '{action.unsubscribe}' => 'Unsubscribe via email',
51 '{action.unsubscribeUrl}' => 'Unsubscribe via web page',
52 '{action.resubscribe}' => 'Resubscribe via email',
53 '{action.resubscribeUrl}' => 'Resubscribe via web page',
54 '{action.optOut}' => 'Opt out via email',
55 '{action.optOutUrl}' => 'Opt out via web page',
56 '{action.forward}' => 'Forward this email (link)',
57 '{action.reply}' => 'Reply to this email (link)',
58 '{action.subscribeUrl}' => 'Subscribe via web page',
59 '{domain.name}' => 'Domain name',
60 '{domain.address}' => 'Domain (organization) address',
61 '{domain.phone}' => 'Domain (organization) phone',
62 '{domain.email}' => 'Domain (organization) email',
63 '{mailing.name}' => 'Mailing name',
64 '{mailing.group}' => 'Mailing group',
65 '{mailing.viewUrl}' => 'Mailing permalink',
66 '{contact.contact_type}' => 'Contact Type',
67 '{contact.do_not_email}' => 'Do Not Email',
68 '{contact.do_not_phone}' => 'Do Not Phone',
69 '{contact.do_not_mail}' => 'Do Not Mail',
70 '{contact.do_not_sms}' => 'Do Not Sms',
71 '{contact.do_not_trade}' => 'Do Not Trade',
72 '{contact.is_opt_out}' => 'No Bulk Emails (User Opt Out)',
73 '{contact.external_identifier}' => 'External Identifier',
74 '{contact.sort_name}' => 'Sort Name',
75 '{contact.display_name}' => 'Display Name',
76 '{contact.nick_name}' => 'Nickname',
77 '{contact.image_URL}' => 'Image Url',
78 '{contact.preferred_communication_method}' => 'Preferred Communication Method',
79 '{contact.preferred_language}' => 'Preferred Language',
80 '{contact.preferred_mail_format}' => 'Preferred Mail Format',
81 '{contact.hash}' => 'Contact Hash',
82 '{contact.contact_source}' => 'Contact Source',
83 '{contact.first_name}' => 'First Name',
84 '{contact.middle_name}' => 'Middle Name',
85 '{contact.last_name}' => 'Last Name',
86 '{contact.individual_prefix}' => 'Individual Prefix',
87 '{contact.individual_suffix}' => 'Individual Suffix',
88 '{contact.formal_title}' => 'Formal Title',
89 '{contact.communication_style}' => 'Communication Style',
90 '{contact.job_title}' => 'Job Title',
91 '{contact.gender}' => 'Gender',
92 '{contact.birth_date}' => 'Birth Date',
93 '{contact.current_employer_id}' => 'Current Employer ID',
94 '{contact.contact_is_deleted}' => 'Contact is in Trash',
95 '{contact.created_date}' => 'Created Date',
96 '{contact.modified_date}' => 'Modified Date',
97 '{contact.addressee}' => 'Addressee',
98 '{contact.email_greeting}' => 'Email Greeting',
99 '{contact.postal_greeting}' => 'Postal Greeting',
100 '{contact.current_employer}' => 'Current Employer',
101 '{contact.location_type}' => 'Location Type',
102 '{contact.street_address}' => 'Street Address',
103 '{contact.street_number}' => 'Street Number',
104 '{contact.street_number_suffix}' => 'Street Number Suffix',
105 '{contact.street_name}' => 'Street Name',
106 '{contact.street_unit}' => 'Street Unit',
107 '{contact.supplemental_address_1}' => 'Supplemental Address 1',
108 '{contact.supplemental_address_2}' => 'Supplemental Address 2',
109 '{contact.city}' => 'City',
110 '{contact.postal_code_suffix}' => 'Postal Code Suffix',
111 '{contact.postal_code}' => 'Postal Code',
112 '{contact.geo_code_1}' => 'Latitude',
113 '{contact.geo_code_2}' => 'Longitude',
114 '{contact.address_name}' => 'Address Name',
115 '{contact.master_id}' => 'Master Address Belongs To',
116 '{contact.county}' => 'County',
117 '{contact.state_province}' => 'State',
118 '{contact.country}' => 'Country',
119 '{contact.phone}' => 'Phone',
120 '{contact.phone_ext}' => 'Phone Extension',
121 '{contact.email}' => 'Email',
122 '{contact.on_hold}' => 'On Hold',
123 '{contact.signature_text}' => 'Signature Text',
124 '{contact.signature_html}' => 'Signature Html',
125 '{contact.im_provider}' => 'IM Provider',
126 '{contact.im}' => 'IM Screen Name',
127 '{contact.openid}' => 'OpenID',
128 '{contact.world_region}' => 'World Region',
129 '{contact.url}' => 'Website',
130 '{contact.checksum}' => 'Checksum',
131 '{contact.contact_id}' => 'Internal Contact ID',
132 ),
133 );
134
135 return $expectedResult;
136 }
137
138 /*
139 * This example has been generated from the API test suite.
140 * The test that created it is called "testMailGetTokens"
141 * and can be found at:
142 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MailingTest.php
143 *
144 * You can see the outcome of the API tests at
145 * https://test.civicrm.org/job/CiviCRM-master-git/
146 *
147 * To Learn about the API read
148 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
149 *
150 * Browse the api on your own site with the api explorer
151 * http://MYSITE.ORG/path/to/civicrm/api
152 *
153 * Read more about testing here
154 * http://wiki.civicrm.org/confluence/display/CRM/Testing
155 *
156 * API Standards documentation:
157 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
158 */