Commit | Line | Data |
---|---|---|
4a092902 | 1 | <?php |
4a092902 XD |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
4 | | Project60 version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright TTTP (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License and the CiviCRM Licensing Exception along | | |
20 | | with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
4a092902 XD |
26 | |
27 | /** | |
c28e1768 | 28 | * This api exposes CiviCRM message_template. |
4a092902 | 29 | * |
b081365f | 30 | * @package CiviCRM_APIv3 |
4a092902 XD |
31 | */ |
32 | ||
4a092902 | 33 | /** |
61fe4988 EM |
34 | * Create message template. |
35 | * | |
d0997921 | 36 | * @param array $params |
61fe4988 | 37 | * |
645ee340 EM |
38 | * @return array |
39 | * @throws \API_Exception | |
4a092902 | 40 | */ |
63c9befe | 41 | function civicrm_api3_message_template_create($params) { |
4a092902 XD |
42 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
43 | } | |
44 | ||
45 | /** | |
0aa0303c EM |
46 | * Adjust Metadata for Create action. |
47 | * | |
48 | * The metadata is used for setting defaults, documentation & validation. | |
8ef12e64 | 49 | * |
cf470720 | 50 | * @param array $params |
b081365f | 51 | * Array of parameters determined by getfields. |
4a092902 | 52 | */ |
63c9befe | 53 | function _civicrm_api3_message_template_create_spec(&$params) { |
4a092902 | 54 | $params['msg_title']['api.required'] = 1; |
35671d00 TO |
55 | $params['is_active']['api.default'] = TRUE; |
56 | /* $params['entity_id']['api.required'] = 1; | |
4a092902 XD |
57 | $params['entity_table']['api.default'] = "civicrm_contribution_recur"; |
58 | $params['type']['api.default'] = "R"; | |
e70a7fc0 | 59 | */ |
4a092902 XD |
60 | } |
61 | ||
62 | /** | |
dc64d047 EM |
63 | * Delete message template. |
64 | * | |
cf470720 | 65 | * @param array $params |
4a092902 | 66 | * |
ae5ffbb7 TO |
67 | * @return bool |
68 | * API result array | |
4a092902 | 69 | */ |
63c9befe | 70 | function civicrm_api3_message_template_delete($params) { |
4a092902 XD |
71 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
72 | } | |
73 | ||
aa1b1481 | 74 | /** |
1747ab99 EM |
75 | * Adjust metadata for message_template get action. |
76 | * | |
c490a46a | 77 | * @param array $params |
aa1b1481 | 78 | */ |
63c9befe | 79 | function _civicrm_api3_message_template_get_spec(&$params) { |
bd876613 CW |
80 | // fetch active records by default |
81 | $params['is_active']['api.default'] = 1; | |
4a092902 | 82 | } |
f471d149 | 83 | |
4a092902 | 84 | /** |
1747ab99 | 85 | * Retrieve one or more message_template. |
4a092902 | 86 | * |
cf470720 | 87 | * @param array $params |
1747ab99 | 88 | * Array of name/value pairs. |
4a092902 | 89 | * |
a6c01b45 | 90 | * @return array |
1747ab99 | 91 | * API result array. |
4a092902 | 92 | */ |
63c9befe | 93 | function civicrm_api3_message_template_get($params) { |
4a092902 XD |
94 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
95 | } | |
96 | ||
f471d149 CB |
97 | /** |
98 | * Sends a template. | |
1747ab99 | 99 | * |
d0997921 | 100 | * @param array $params |
f471d149 CB |
101 | */ |
102 | function civicrm_api3_message_template_send($params) { | |
1d05b6d8 CW |
103 | // Change external param names to internal ones |
104 | $fieldSpec = array(); | |
105 | _civicrm_api3_message_template_send_spec($fieldSpec); | |
106 | ||
107 | foreach ($fieldSpec as $field => $spec) { | |
108 | if (isset($spec['api.aliases']) && array_key_exists($field, $params)) { | |
109 | $params[CRM_Utils_Array::first($spec['api.aliases'])] = $params[$field]; | |
110 | unset($params[$field]); | |
111 | } | |
112 | } | |
113 | if (empty($params['messageTemplateID'])) { | |
114 | if (empty($params['groupName']) || empty($params['valueName'])) { | |
115 | // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names | |
116 | throw new API_Exception( | |
117 | "Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name", | |
118 | "mandatory_missing", | |
119 | array("fields" => array('id', 'option_group_name', 'option_value_name')) | |
120 | ); | |
121 | } | |
122 | } | |
123 | CRM_Core_BAO_MessageTemplate::sendTemplate($params); | |
f471d149 CB |
124 | } |
125 | ||
126 | /** | |
0aa0303c | 127 | * Adjust Metadata for Create action. |
f471d149 CB |
128 | * |
129 | * The metadata is used for setting defaults, documentation & | |
130 | * validation. | |
131 | * | |
cf470720 | 132 | * @param array $params |
b081365f | 133 | * Array of parameters determined by getfields. |
f471d149 CB |
134 | */ |
135 | function _civicrm_api3_message_template_send_spec(&$params) { | |
1d05b6d8 CW |
136 | $params['id']['description'] = 'ID of the template'; |
137 | $params['id']['title'] = 'Message Template ID'; | |
138 | $params['id']['api.aliases'] = array('messageTemplateID', 'message_template_id'); | |
d142432b | 139 | $params['id']['type'] = CRM_Utils_Type::T_INT; |
1d05b6d8 CW |
140 | |
141 | $params['option_group_name']['description'] = 'option group name of the template (required if no id supplied)'; | |
142 | $params['option_group_name']['title'] = 'Option Group Name'; | |
143 | $params['option_group_name']['api.aliases'] = array('groupName'); | |
d142432b | 144 | $params['option_group_name']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
145 | |
146 | $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)'; | |
147 | $params['option_value_name']['title'] = 'Option Value Name'; | |
148 | $params['option_value_name']['api.aliases'] = array('valueName'); | |
d142432b | 149 | $params['option_value_name']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
150 | |
151 | $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced'; | |
152 | $params['contact_id']['title'] = 'Contact ID'; | |
153 | $params['contact_id']['api.aliases'] = array('contactId'); | |
d142432b | 154 | $params['contact_id']['type'] = CRM_Utils_Type::T_INT; |
1d05b6d8 CW |
155 | |
156 | $params['template_params']['description'] = 'additional template params (other than the ones already set in the template singleton)'; | |
157 | $params['template_params']['title'] = 'Template Params'; | |
158 | $params['template_params']['api.aliases'] = array('tplParams'); | |
d142432b | 159 | // FIXME: Type?? |
1d05b6d8 CW |
160 | |
161 | $params['from']['description'] = 'the From: header'; | |
162 | $params['from']['title'] = 'From'; | |
d142432b | 163 | $params['from']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
164 | |
165 | $params['to_name']['description'] = 'the recipient’s name'; | |
166 | $params['to_name']['title'] = 'Recipient Name'; | |
167 | $params['to_name']['api.aliases'] = array('toName'); | |
d142432b | 168 | $params['to_name']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
169 | |
170 | $params['to_email']['description'] = 'the recipient’s email - mail is sent only if set'; | |
171 | $params['to_email']['title'] = 'Recipient Email'; | |
172 | $params['to_email']['api.aliases'] = array('toEmail'); | |
d142432b | 173 | $params['to_email']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
174 | |
175 | $params['cc']['description'] = 'the Cc: header'; | |
176 | $params['cc']['title'] = 'CC'; | |
d142432b | 177 | $params['cc']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
178 | |
179 | $params['bcc']['description'] = 'the Bcc: header'; | |
180 | $params['bcc']['title'] = 'BCC'; | |
d142432b | 181 | $params['bcc']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
182 | |
183 | $params['reply_to']['description'] = 'the Reply-To: header'; | |
184 | $params['reply_to']['title'] = 'Reply To'; | |
185 | $params['reply_to']['api.aliases'] = array('replyTo'); | |
d142432b | 186 | $params['reply_to']['type'] = CRM_Utils_Type::T_STRING; |
1d05b6d8 CW |
187 | |
188 | $params['attachments']['description'] = 'email attachments'; | |
189 | $params['attachments']['title'] = 'Attachments'; | |
d142432b | 190 | // FIXME: Type?? |
1d05b6d8 CW |
191 | |
192 | $params['is_test']['description'] = 'whether this is a test email (and hence should include the test banner)'; | |
193 | $params['is_test']['title'] = 'Is Test'; | |
194 | $params['is_test']['api.aliases'] = array('isTest'); | |
d142432b | 195 | $params['is_test']['type'] = CRM_Utils_Type::T_BOOLEAN; |
1d05b6d8 CW |
196 | |
197 | $params['pdf_filename']['description'] = 'filename of optional PDF version to add as attachment (do not include path)'; | |
198 | $params['pdf_filename']['title'] = 'PDF Filename'; | |
199 | $params['pdf_filename']['api.aliases'] = array('PDFFilename'); | |
d142432b | 200 | $params['pdf_filename']['type'] = CRM_Utils_Type::T_STRING; |
f471d149 | 201 | } |