Merge pull request #5317 from sfe-ev/chainselect-missing-fields
[civicrm-core.git] / api / v3 / MessageTemplate.php
1 <?php
2 // $Id$
3 /*
4 +--------------------------------------------------------------------+
5 | Project60 version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright TTTP (c) 2004-2013 |
8 +--------------------------------------------------------------------+
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 * File for the CiviCRM APIv3 message_template functions
30 *
31 * @package CiviCRM_SEPA
32 *
33 */
34
35 /**
36 * @access public
37 */
38 function civicrm_api3_message_template_create($params) {
39 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
40 }
41
42 /**
43 * Adjust Metadata for Create action
44 *
45 * The metadata is used for setting defaults, documentation & validation
46 * @param array $params array or parameters determined by getfields
47 */
48 function _civicrm_api3_message_template_create_spec(&$params) {
49 $params['msg_title']['api.required'] = 1;
50 $params['is_active']['api.default'] = true;
51 /* $params['entity_id']['api.required'] = 1;
52 $params['entity_table']['api.default'] = "civicrm_contribution_recur";
53 $params['type']['api.default'] = "R";
54 */
55 }
56
57 /**
58 * @param array $params
59 *
60 * @return boolean | error true if successfull, error otherwise
61 * {@getfields message_template_delete}
62 * @access public
63 */
64 function civicrm_api3_message_template_delete($params) {
65 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
66 }
67
68 /**
69 * @param $params
70 */
71 function _civicrm_api3_message_template_get_spec(&$params) {
72 }
73
74 /**
75 * Retrieve one or more message_template
76 *
77 * @param array input parameters
78 *
79 *
80 * @example SepaCreditorGet.php Standard Get Example
81 *
82 * @param array $params an associative array of name/value pairs.
83 *
84 * @return array api result array
85 * {@getfields message_template_get}
86 * @access public
87 */
88 function civicrm_api3_message_template_get($params) {
89 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
90 }
91
92 /**
93 * Sends a template.
94 */
95 function civicrm_api3_message_template_send($params) {
96 // Change external param names to internal ones
97 $fieldSpec = array();
98 _civicrm_api3_message_template_send_spec($fieldSpec);
99
100 foreach ($fieldSpec as $field => $spec) {
101 if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
102 $params[CRM_Utils_Array::first($spec['api.aliases'])] = $params[$field];
103 unset($params[$field]);
104 }
105 }
106 if (empty($params['messageTemplateID'])) {
107 if (empty($params['groupName']) || empty($params['valueName'])) {
108 // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
109 throw new API_Exception(
110 "Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name",
111 "mandatory_missing",
112 array("fields" => array('id', 'option_group_name', 'option_value_name'))
113 );
114 }
115 }
116 CRM_Core_BAO_MessageTemplate::sendTemplate($params);
117 }
118
119 /**
120 * Adjust Metadata for Create action
121 *
122 * The metadata is used for setting defaults, documentation &
123 * validation.
124 *
125 * @param array $params array or parameters determined by getfields
126 */
127 function _civicrm_api3_message_template_send_spec(&$params) {
128 $params['id']['description'] = 'ID of the template';
129 $params['id']['title'] = 'Message Template ID';
130 $params['id']['api.aliases'] = array('messageTemplateID', 'message_template_id');
131
132 $params['option_group_name']['description'] = 'option group name of the template (required if no id supplied)';
133 $params['option_group_name']['title'] = 'Option Group Name';
134 $params['option_group_name']['api.aliases'] = array('groupName');
135
136 $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)';
137 $params['option_value_name']['title'] = 'Option Value Name';
138 $params['option_value_name']['api.aliases'] = array('valueName');
139
140 $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced';
141 $params['contact_id']['title'] = 'Contact ID';
142 $params['contact_id']['api.aliases'] = array('contactId');
143
144 $params['template_params']['description'] = 'additional template params (other than the ones already set in the template singleton)';
145 $params['template_params']['title'] = 'Template Params';
146 $params['template_params']['api.aliases'] = array('tplParams');
147
148 $params['from']['description'] = 'the From: header';
149 $params['from']['title'] = 'From';
150
151 $params['to_name']['description'] = 'the recipient’s name';
152 $params['to_name']['title'] = 'Recipient Name';
153 $params['to_name']['api.aliases'] = array('toName');
154
155 $params['to_email']['description'] = 'the recipient’s email - mail is sent only if set';
156 $params['to_email']['title'] = 'Recipient Email';
157 $params['to_email']['api.aliases'] = array('toEmail');
158
159 $params['cc']['description'] = 'the Cc: header';
160 $params['cc']['title'] = 'CC';
161
162 $params['bcc']['description'] = 'the Bcc: header';
163 $params['bcc']['title'] = 'BCC';
164
165 $params['reply_to']['description'] = 'the Reply-To: header';
166 $params['reply_to']['title'] = 'Reply To';
167 $params['reply_to']['api.aliases'] = array('replyTo');
168
169 $params['attachments']['description'] = 'email attachments';
170 $params['attachments']['title'] = 'Attachments';
171
172 $params['is_test']['description'] = 'whether this is a test email (and hence should include the test banner)';
173 $params['is_test']['title'] = 'Is Test';
174 $params['is_test']['api.aliases'] = array('isTest');
175
176 $params['pdf_filename']['description'] = 'filename of optional PDF version to add as attachment (do not include path)';
177 $params['pdf_filename']['title'] = 'PDF Filename';
178 $params['pdf_filename']['api.aliases'] = array('PDFFilename');
179 }