3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
40 * Get all the mailings and details that a contact was involved with
42 * @param array $params
44 * - key: contact_id, value: int - required
45 * - key: type, value: Delivered | Bounced - optional, defaults to Delivered
46 * - Future extensions will include: Opened, Clicked, Forwarded
48 * @return array API result
51 * @example CRM/Mailing/BAO/Mailing.php
54 function civicrm_api3_mailing_contact_get($params) {
55 return civicrm_api3_create_success(_civicrm_api3_mailing_contact_getresults($params, FALSE));
58 * This is a wrapper for the functions that return the results from the 'quasi-entity'
60 * @param array $params
64 function _civicrm_api3_mailing_contact_getresults($params, $count) {
65 if (empty($params['type'])) {
66 //ie. because the api is an anomoly & passing in id is not valid
67 throw new Exception('This api call does not accept api as a parameter');
69 $options = _civicrm_api3_get_options_from_params($params, TRUE,'contribution','get');
70 $fnName = '_civicrm_api3_mailing_contact_get_' . strtolower($params['type']);
72 $params['contact_id'],
80 * Adjust Metadata for Get action
82 * @param array $params
83 * Array or parameters determined by getfields.
85 function _civicrm_api3_mailing_contact_get_spec(&$params) {
86 $params['contact_id']['api.required'] = 1;
87 $params['contact_id']['title'] = 'Contact ID';
88 $params['type'] = array(
89 'api.default' => 'Delivered',
90 'title' => 'Type',// doesn't really explain the field - but not sure I understand it to explain it better
91 'type' => CRM_Utils_Type
::T_STRING
,
93 'Delivered' => 'Delivered',
94 'Bounced' => 'Bounced',
101 * @param int $contactID
104 * @param $selectFields
106 * @param $whereClause
112 function _civicrm_api3_mailing_contact_query(
127 FROM civicrm_mailing m
128 INNER JOIN civicrm_contact c ON m.created_id = c.id
129 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
130 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
133 AND meq.contact_id = %1
139 1 => array($contactID, 'Integer')
141 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
145 'contact_id' => $contactID
151 $defaultFields = array(
152 'm.id' => 'mailing_id',
153 'm.subject' => 'subject',
154 'c.id' => 'creator_id',
155 'c.sort_name' => 'creator_name',
159 $fields = array_merge($selectFields, $defaultFields);
162 $fields = $defaultFields;
166 foreach ($fields as $n => $l) {
167 $select[] = "$n as $l";
169 $select = implode(', ', $select);
171 $orderBy = 'ORDER BY j.start_date DESC';
173 $orderBy = "ORDER BY $sort";
178 FROM civicrm_mailing m
179 INNER JOIN civicrm_contact c ON m.created_id = c.id
180 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
181 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
184 AND meq.contact_id = %1
197 1 => array($contactID, 'Integer'),
198 2 => array($offset, 'Integer'),
199 3 => array($limit, 'Integer')
201 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
204 while ($dao->fetch()) {
205 foreach ($fields as $n => $l) {
206 $results[$dao->mailing_id
][$l] = $dao->$l;
215 * @param int $contactID
223 function _civicrm_api3_mailing_contact_get_delivered(
230 $selectFields = array('med.time_stamp' => 'start_date');
233 INNER JOIN civicrm_mailing_event_delivered med ON med.event_queue_id = meq.id
234 LEFT JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
241 return _civicrm_api3_mailing_contact_query(
255 * @param int $contactID
263 function _civicrm_api3_mailing_contact_get_bounced(
271 INNER JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
274 return _civicrm_api3_mailing_contact_query(
288 * Get count of all the mailings that a contact was involved with
290 * @param array $params
292 * - key: contact_id, value: int - required
293 * - key: type, value: Delivered | Bounced - optional, defaults to Delivered
294 * - Future extensions will include: Opened, Clicked, Forwarded
296 * @return array API result
299 * @example CRM/Mailing/BAO/Mailing.php
302 function civicrm_api3_mailing_contact_getcount($params) {
303 return _civicrm_api3_mailing_contact_getresults($params, TRUE);