3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 * File for the CiviCRM APIv3 contact and mailing functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_MailingContact
34 * @copyright CiviCRM LLC (c) 2004-2013
40 * Get all the mailings and details that a contact was involved with
42 * @param array $params input parameters
43 * - key: contact_id, value: int - required
44 * - key: type, value: Delivered | Bounced - optional, defaults to Delivered
45 * - Future extensions will include: Opened, Clicked, Forwarded
47 * @return array API result
50 * @example CRM/Mailing/Page/Tab.php
53 function civicrm_api3_mailing_contact_get($params) {
54 if (empty($params['contact_id'])) {
55 return civicrm_api3_create_error('contact_id is a required field');
58 if (empty($params['type'])) {
59 $params['type'] = 'Delivered';
62 $validTypeValues = array('Delivered', 'Bounced');
63 if (!in_array($params['type'], $validTypeValues)) {
64 return civicrm_api3_create_error(
65 'type should be one of the following: ' .
66 implode(', ', $validTypeValues)
70 if (!isset($params['offset'])) {
71 $params['offset'] = 0;
75 if (!isset($params['limit'])) {
76 $params['limit'] = 50;
79 $fnName = '_civicrm_api3_mailing_contact_get_' . strtolower($params['type']);
81 $params['contact_id'],
87 function _civicrm_api3_mailing_contact_query(
96 $defaultFields = array(
97 'm.id' => 'mailing_id',
98 'm.subject' => 'subject',
99 'c.id' => 'creator_id',
100 'c.sort_name' => 'creator_name',
104 $fields = array_merge($selectFields, $defaultFields);
107 $fields = $defaultFields;
111 foreach ($fields as $n => $l) {
112 $select[] = "$n as $l";
114 $select = implode(', ', $select);
118 FROM civicrm_mailing m
119 INNER JOIN civicrm_contact c ON m.created_id = c.id
120 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
121 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
124 AND meq.contact_id = %1
127 ORDER BY j.start_date
137 1 => array($contactID, 'Integer'),
138 2 => array($offset, 'Integer'),
139 3 => array($limit, 'Integer')
141 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
144 while ($dao->fetch()) {
145 foreach ($fields as $n => $l) {
146 $results[$dao->mailing_id
][$l] = $dao->$l;
152 'contact_id' => $contactID,
156 return civicrm_api3_create_success($results, $params);
159 function _civicrm_api3_mailing_contact_get_delivered(
164 $selectFields = array('med.time_stamp' => 'start_date');
167 INNER JOIN civicrm_mailing_event_delivered med ON med.event_queue_id = meq.id
168 LEFT JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
175 return _civicrm_api3_mailing_contact_query(
186 function _civicrm_api3_mailing_contact_get_bounced(
192 INNER JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
195 return _civicrm_api3_mailing_contact_query(