commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / api / v3 / MessageTemplate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * This api exposes CiviCRM message_template.
30 *
31 * @package CiviCRM_APIv3
32 */
33
34 /**
35 * Create message template.
36 *
37 * @param array $params
38 *
39 * @return array
40 * @throws \API_Exception
41 */
42 function civicrm_api3_message_template_create($params) {
43 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
44 }
45
46 /**
47 * Adjust Metadata for Create action.
48 *
49 * The metadata is used for setting defaults, documentation & validation.
50 *
51 * @param array $params
52 * Array of parameters determined by getfields.
53 */
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";
60 */
61 }
62
63 /**
64 * Delete message template.
65 *
66 * @param array $params
67 *
68 * @return bool
69 * API result array
70 */
71 function civicrm_api3_message_template_delete($params) {
72 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
73 }
74
75 /**
76 * Adjust metadata for message_template get action.
77 *
78 * @param array $params
79 */
80 function _civicrm_api3_message_template_get_spec(&$params) {
81 // fetch active records by default
82 $params['is_active']['api.default'] = 1;
83 }
84
85 /**
86 * Retrieve one or more message_template.
87 *
88 * @param array $params
89 * Array of name/value pairs.
90 *
91 * @return array
92 * API result array.
93 */
94 function civicrm_api3_message_template_get($params) {
95 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
96 }
97
98 /**
99 * Sends a template.
100 *
101 * @param array $params
102 */
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);
107
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]);
112 }
113 }
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",
119 "mandatory_missing",
120 array("fields" => array('id', 'option_group_name', 'option_value_name'))
121 );
122 }
123 }
124 CRM_Core_BAO_MessageTemplate::sendTemplate($params);
125 }
126
127 /**
128 * Adjust Metadata for Create action.
129 *
130 * The metadata is used for setting defaults, documentation &
131 * validation.
132 *
133 * @param array $params
134 * Array of parameters determined by getfields.
135 */
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;
141
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;
146
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;
151
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;
156
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');
160 // FIXME: Type??
161
162 $params['from']['description'] = 'the From: header';
163 $params['from']['title'] = 'From';
164 $params['from']['type'] = CRM_Utils_Type::T_STRING;
165
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;
170
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;
175
176 $params['cc']['description'] = 'the Cc: header';
177 $params['cc']['title'] = 'CC';
178 $params['cc']['type'] = CRM_Utils_Type::T_STRING;
179
180 $params['bcc']['description'] = 'the Bcc: header';
181 $params['bcc']['title'] = 'BCC';
182 $params['bcc']['type'] = CRM_Utils_Type::T_STRING;
183
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;
188
189 $params['attachments']['description'] = 'email attachments';
190 $params['attachments']['title'] = 'Attachments';
191 // FIXME: Type??
192
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;
197
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;
202 }