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
43 * Input parameters - see _spec for details (returned by getfields)
48 function civicrm_api3_mailing_contact_get($params) {
49 return civicrm_api3_create_success(_civicrm_api3_mailing_contact_getresults($params, FALSE));
52 * This is a wrapper for the functions that return the results from the 'quasi-entity'
54 * @param array $params
58 function _civicrm_api3_mailing_contact_getresults($params, $count) {
59 if (empty($params['type'])) {
60 //ie. because the api is an anomaly & passing in id is not valid
61 throw new Exception('This api call does not accept api as a parameter');
63 $options = _civicrm_api3_get_options_from_params($params, TRUE,'contribution','get');
64 $fnName = '_civicrm_api3_mailing_contact_get_' . strtolower($params['type']);
66 $params['contact_id'],
74 * Adjust Metadata for Get action
76 * @param array $params
77 * Array or parameters determined by getfields.
79 function _civicrm_api3_mailing_contact_get_spec(&$params) {
80 $params['contact_id']['api.required'] = 1;
81 $params['contact_id']['title'] = 'Contact ID';
82 $params['type'] = array(
83 'api.default' => 'Delivered',
84 'title' => 'Type',// doesn't really explain the field - but not sure I understand it to explain it better
85 'type' => CRM_Utils_Type
::T_STRING
,
87 'Delivered' => 'Delivered',
88 'Bounced' => 'Bounced',
94 * @param int $contactID
97 * @param $selectFields
105 function _civicrm_api3_mailing_contact_query(
119 FROM civicrm_mailing m
120 INNER JOIN civicrm_contact c ON m.created_id = c.id
121 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
122 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
125 AND meq.contact_id = %1
131 1 => array($contactID, 'Integer'),
133 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
138 $defaultFields = array(
139 'm.id' => 'mailing_id',
140 'm.subject' => 'subject',
141 'c.id' => 'creator_id',
142 'c.sort_name' => 'creator_name',
146 $fields = array_merge($selectFields, $defaultFields);
149 $fields = $defaultFields;
153 foreach ($fields as $n => $l) {
154 $select[] = "$n as $l";
156 $select = implode(', ', $select);
158 $orderBy = 'ORDER BY j.start_date DESC';
160 $orderBy = "ORDER BY $sort";
165 FROM civicrm_mailing m
166 INNER JOIN civicrm_contact c ON m.created_id = c.id
167 INNER JOIN civicrm_mailing_job j ON j.mailing_id = m.id
168 INNER JOIN civicrm_mailing_event_queue meq ON meq.job_id = j.id
171 AND meq.contact_id = %1
184 1 => array($contactID, 'Integer'),
185 2 => array($offset, 'Integer'),
186 3 => array($limit, 'Integer'),
188 $dao = CRM_Core_DAO
::executeQuery($sql, $qParams);
191 while ($dao->fetch()) {
192 foreach ($fields as $n => $l) {
193 $results[$dao->mailing_id
][$l] = $dao->$l;
202 * @param int $contactID
210 function _civicrm_api3_mailing_contact_get_delivered(
217 $selectFields = array('med.time_stamp' => 'start_date');
220 INNER JOIN civicrm_mailing_event_delivered med ON med.event_queue_id = meq.id
221 LEFT JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
228 return _civicrm_api3_mailing_contact_query(
241 * @param int $contactID
249 function _civicrm_api3_mailing_contact_get_bounced(
257 INNER JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
260 return _civicrm_api3_mailing_contact_query(
273 * Get count of all the mailings that a contact was involved with
275 * @param array $params
276 * Input parameters per getfields
281 function civicrm_api3_mailing_contact_getcount($params) {
282 return _civicrm_api3_mailing_contact_getresults($params, TRUE);