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