3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM message_template.
31 * @package CiviCRM_APIv3
35 * Create message template.
37 * @param array $params
40 * @throws \API_Exception
42 function civicrm_api3_message_template_create($params) {
43 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
47 * Adjust Metadata for Create action.
49 * The metadata is used for setting defaults, documentation & validation.
51 * @param array $params
52 * Array of parameters determined by getfields.
54 function _civicrm_api3_message_template_create_spec(&$params) {
55 $params['msg_title']['api.required'] = 1;
56 $params['is_active']['api.default'] = TRUE;
57 /* $params['entity_id']['api.required'] = 1;
58 $params['entity_table']['api.default'] = "civicrm_contribution_recur";
59 $params['type']['api.default'] = "R";
64 * Delete message template.
66 * @param array $params
71 function civicrm_api3_message_template_delete($params) {
72 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
76 * Adjust metadata for message_template get action.
78 * @param array $params
80 function _civicrm_api3_message_template_get_spec(&$params) {
81 // fetch active records by default
82 $params['is_active']['api.default'] = 1;
86 * Retrieve one or more message_template.
88 * @param array $params
89 * Array of name/value pairs.
94 function civicrm_api3_message_template_get($params) {
95 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
101 * @param array $params
103 function civicrm_api3_message_template_send($params) {
104 // Change external param names to internal ones
105 $fieldSpec = array();
106 _civicrm_api3_message_template_send_spec($fieldSpec);
108 foreach ($fieldSpec as $field => $spec) {
109 if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
110 $params[CRM_Utils_Array
::first($spec['api.aliases'])] = $params[$field];
111 unset($params[$field]);
114 if (empty($params['messageTemplateID'])) {
115 if (empty($params['groupName']) ||
empty($params['valueName'])) {
116 // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
117 throw new API_Exception(
118 "Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name",
120 array("fields" => array('id', 'option_group_name', 'option_value_name'))
124 CRM_Core_BAO_MessageTemplate
::sendTemplate($params);
128 * Adjust Metadata for Create action.
130 * The metadata is used for setting defaults, documentation &
133 * @param array $params
134 * Array of parameters determined by getfields.
136 function _civicrm_api3_message_template_send_spec(&$params) {
137 $params['id']['description'] = 'ID of the template';
138 $params['id']['title'] = 'Message Template ID';
139 $params['id']['api.aliases'] = array('messageTemplateID', 'message_template_id');
140 $params['id']['type'] = CRM_Utils_Type
::T_INT
;
142 $params['option_group_name']['description'] = 'option group name of the template (required if no id supplied)';
143 $params['option_group_name']['title'] = 'Option Group Name';
144 $params['option_group_name']['api.aliases'] = array('groupName');
145 $params['option_group_name']['type'] = CRM_Utils_Type
::T_STRING
;
147 $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)';
148 $params['option_value_name']['title'] = 'Option Value Name';
149 $params['option_value_name']['api.aliases'] = array('valueName');
150 $params['option_value_name']['type'] = CRM_Utils_Type
::T_STRING
;
152 $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced';
153 $params['contact_id']['title'] = 'Contact ID';
154 $params['contact_id']['api.aliases'] = array('contactId');
155 $params['contact_id']['type'] = CRM_Utils_Type
::T_INT
;
157 $params['template_params']['description'] = 'additional template params (other than the ones already set in the template singleton)';
158 $params['template_params']['title'] = 'Template Params';
159 $params['template_params']['api.aliases'] = array('tplParams');
162 $params['from']['description'] = 'the From: header';
163 $params['from']['title'] = 'From';
164 $params['from']['type'] = CRM_Utils_Type
::T_STRING
;
166 $params['to_name']['description'] = 'the recipient’s name';
167 $params['to_name']['title'] = 'Recipient Name';
168 $params['to_name']['api.aliases'] = array('toName');
169 $params['to_name']['type'] = CRM_Utils_Type
::T_STRING
;
171 $params['to_email']['description'] = 'the recipient’s email - mail is sent only if set';
172 $params['to_email']['title'] = 'Recipient Email';
173 $params['to_email']['api.aliases'] = array('toEmail');
174 $params['to_email']['type'] = CRM_Utils_Type
::T_STRING
;
176 $params['cc']['description'] = 'the Cc: header';
177 $params['cc']['title'] = 'CC';
178 $params['cc']['type'] = CRM_Utils_Type
::T_STRING
;
180 $params['bcc']['description'] = 'the Bcc: header';
181 $params['bcc']['title'] = 'BCC';
182 $params['bcc']['type'] = CRM_Utils_Type
::T_STRING
;
184 $params['reply_to']['description'] = 'the Reply-To: header';
185 $params['reply_to']['title'] = 'Reply To';
186 $params['reply_to']['api.aliases'] = array('replyTo');
187 $params['reply_to']['type'] = CRM_Utils_Type
::T_STRING
;
189 $params['attachments']['description'] = 'email attachments';
190 $params['attachments']['title'] = 'Attachments';
193 $params['is_test']['description'] = 'whether this is a test email (and hence should include the test banner)';
194 $params['is_test']['title'] = 'Is Test';
195 $params['is_test']['api.aliases'] = array('isTest');
196 $params['is_test']['type'] = CRM_Utils_Type
::T_BOOLEAN
;
198 $params['pdf_filename']['description'] = 'filename of optional PDF version to add as attachment (do not include path)';
199 $params['pdf_filename']['title'] = 'PDF Filename';
200 $params['pdf_filename']['api.aliases'] = array('PDFFilename');
201 $params['pdf_filename']['type'] = CRM_Utils_Type
::T_STRING
;