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 contact and mailing.
31 * @package CiviCRM_APIv3
35 * Get all the mailings and details that a contact was involved with.
37 * @param array $params
38 * Input parameters - see _spec for details (returned by getfields)
43 function civicrm_api3_mailing_contact_get($params) {
44 return civicrm_api3_create_success(_civicrm_api3_mailing_contact_getresults($params, FALSE));
48 * This is a wrapper for the functions that return the results from the 'quasi-entity' mailing contact.
50 * @param array $params
55 function _civicrm_api3_mailing_contact_getresults($params, $count) {
56 if (empty($params['type'])) {
57 //ie. because the api is an anomaly & passing in id is not valid
58 throw new Exception('This api call does not accept api as a parameter');
60 $options = _civicrm_api3_get_options_from_params($params, TRUE, 'contribution', 'get');
61 $fnName = '_civicrm_api3_mailing_contact_get_' . strtolower($params['type']);
63 $params['contact_id'],
72 * Adjust Metadata for Get action.
74 * @param array $params
75 * Array of parameters determined by getfields.
77 function _civicrm_api3_mailing_contact_get_spec(&$params) {
78 $params['contact_id'] = array(
80 'title' => 'Contact ID',
81 'type' => CRM_Utils_Type
::T_INT
,
84 $params['type'] = array(
85 'api.default' => 'Delivered',
86 'title' => 'Type', // doesn't really explain the field - but not sure I understand it to explain it better
87 'type' => CRM_Utils_Type
::T_STRING
,
89 'Delivered' => 'Delivered',
90 'Bounced' => 'Bounced',
96 * Helper function for mailing contact queries.
98 * @param int $contactID
101 * @param $selectFields
103 * @param $whereClause
109 function _civicrm_api3_mailing_contact_query(
123 FROM civicrm_mailing m
124 INNER JOIN civicrm_contact c ON m.created_id = c.id
125 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
126 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
129 AND meq.contact_id = %1
135 1 => array($contactID, 'Integer'),
137 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
142 $defaultFields = array(
143 'm.id' => 'mailing_id',
144 'm.subject' => 'subject',
145 'c.id' => 'creator_id',
146 'c.sort_name' => 'creator_name',
150 $fields = array_merge($selectFields, $defaultFields);
153 $fields = $defaultFields;
157 foreach ($fields as $n => $l) {
158 $select[] = "$n as $l";
160 $select = implode(', ', $select);
162 $orderBy = 'ORDER BY MIN(j.start_date) DESC';
164 $orderBy = "ORDER BY $sort";
167 $groupBy = CRM_Contact_BAO_Query
::getGroupByFromSelectColumns(array_keys($fields), "m.id");
171 FROM civicrm_mailing m
172 INNER JOIN civicrm_contact c ON m.created_id = c.id
173 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
174 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
177 AND meq.contact_id = %1
190 1 => array($contactID, 'Integer'),
191 2 => array($offset, 'Integer'),
192 3 => array($limit, 'Integer'),
194 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
197 while ($dao->fetch()) {
198 foreach ($fields as $n => $l) {
199 $results[$dao->mailing_id
][$l] = $dao->$l;
208 * Get delivered mailing contacts.
210 * @param int $contactID
218 function _civicrm_api3_mailing_contact_get_delivered(
225 $selectFields = array('med.time_stamp' => 'start_date');
228 INNER JOIN civicrm_mailing_event_delivered med ON med.event_queue_id = meq.id
229 LEFT JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
236 return _civicrm_api3_mailing_contact_query(
249 * Get bounced mailing contact records.
251 * @param int $contactID
259 function _civicrm_api3_mailing_contact_get_bounced(
267 INNER JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
270 return _civicrm_api3_mailing_contact_query(
283 * Get count of all the mailings that a contact was involved with.
285 * @param array $params
286 * Input parameters per getfields
291 function civicrm_api3_mailing_contact_getcount($params) {
292 return _civicrm_api3_mailing_contact_getresults($params, TRUE);