5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Mailing_Bounce
extends CRM_Report_Form
{
39 protected $_summary = NULL;
41 protected $_emailField = FALSE;
43 protected $_phoneField = FALSE;
45 // just a toggle we use to build the from
46 protected $_mailingidField = FALSE;
48 protected $_customGroupExtends = array('Contact', 'Individual', 'Household', 'Organization');
50 protected $_charts = array(
52 'barChart' => 'Bar Chart',
53 'pieChart' => 'Pie Chart',
56 function __construct() {
57 $this->_columns
= array();
59 $this->_columns
['civicrm_contact'] = array(
60 'dao' => 'CRM_Contact_DAO_Contact',
63 'title' => ts('Contact ID'),
68 'title' => ts('Contact Name'),
74 'title' => ts('Contact Name'),
77 'title' => ts('Contact Source'),
78 'type' => CRM_Utils_Type
::T_STRING
,
81 'title' => ts('Contact ID'),
88 array('title' => ts('Contact Name'), 'default' => TRUE, 'default_order' => 'ASC'),
90 'grouping' => 'contact-fields',
93 $this->_columns
['civicrm_mailing'] = array(
94 'dao' => 'CRM_Mailing_DAO_Mailing',
96 'mailing_name' => array(
98 'title' => ts('Mailing'),
101 'mailing_name_alias' => array(
104 'no_display' => TRUE,
108 'mailing_id' => array(
110 'title' => ts('Mailing'),
111 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
112 'type' => CRM_Utils_Type
::T_INT
,
113 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
114 'operator' => 'like',
122 'title' => ts('Mailing'),
125 'grouping' => 'mailing-fields',
128 $this->_columns
['civicrm_mailing_event_bounce'] = array(
129 'dao' => 'CRM_Mailing_DAO_Mailing',
131 'bounce_reason' => array(
132 'title' => ts('Bounce Reason'),
138 array('title' => ts('Bounce Reason')),
140 'grouping' => 'mailing-fields',
143 $this->_columns
['civicrm_mailing_bounce_type'] = array(
144 'dao' => 'CRM_Mailing_DAO_BounceType',
146 'bounce_name' => array(
148 'title' => ts('Bounce Type'),
152 'bounce_type_name' => array(
154 'title' => ts('Bounce Type'),
155 'operatorType' => CRM_Report_Form
::OP_SELECT
,
156 'type' => CRM_Utils_Type
::T_STRING
,
157 'options' => self
::bounce_type(),
158 'operator' => 'like',
166 'title' => ts('Bounce Type'),
169 'grouping' => 'mailing-fields',
172 $this->_columns
['civicrm_email'] = array(
173 'dao' => 'CRM_Core_DAO_Email',
176 'title' => ts('Email'),
184 array('title' => ts('Email'), 'default_order' => 'ASC'),
186 'grouping' => 'contact-fields',
189 $this->_columns
['civicrm_phone'] = array(
190 'dao' => 'CRM_Core_DAO_Phone',
191 'fields' => array('phone' => NULL),
192 'grouping' => 'contact-fields',
195 $this->_columns
['civicrm_group'] = array(
196 'dao' => 'CRM_Contact_DAO_Group',
200 'name' => 'group_id',
201 'title' => ts('Group'),
202 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
204 'options' => CRM_Core_PseudoConstant
::group(),
209 $this->_tagFilter
= TRUE;
210 parent
::__construct();
213 function preProcess() {
214 $this->assign('chartSupported', TRUE);
215 parent
::preProcess();
220 $this->_columnHeaders
= array();
222 foreach ($this->_columns
as $tableName => $table) {
223 if (array_key_exists('fields', $table)) {
224 foreach ($table['fields'] as $fieldName => $field) {
225 if (CRM_Utils_Array
::value('required', $field) ||
226 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
228 if ($tableName == 'civicrm_email') {
229 $this->_emailField
= TRUE;
231 elseif ($tableName == 'civicrm_phone') {
232 $this->_phoneField
= TRUE;
235 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
236 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
237 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
238 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
245 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
246 $select[] = "COUNT({$this->_aliases['civicrm_mailing_event_bounce']}.id) as civicrm_mailing_bounce_count";
247 $this->_columnHeaders
["civicrm_mailing_bounce_count"]['title'] = ts('Bounce Count');
250 $this->_select
= "SELECT " . implode(', ', $select) . " ";
253 static function formRule($fields, $files, $self) {
254 $errors = $grouping = array();
260 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
261 // LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
262 // ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
263 // {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
266 INNER JOIN civicrm_mailing_event_queue
267 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
268 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
269 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
270 INNER JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']}
271 ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = civicrm_mailing_event_queue.id
272 LEFT JOIN civicrm_mailing_bounce_type {$this->_aliases['civicrm_mailing_bounce_type']}
273 ON {$this->_aliases['civicrm_mailing_event_bounce']}.bounce_type_id = {$this->_aliases['civicrm_mailing_bounce_type']}.id
274 INNER JOIN civicrm_mailing_job
275 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
276 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
277 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
280 if ($this->_phoneField
) {
282 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
283 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
284 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
290 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
294 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
295 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
298 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing_event_bounce']}.id";
302 function postProcess() {
303 $this->beginPostProcess();
305 // get the acl clauses built before we assemble the query
306 $this->buildACLClause($this->_aliases
['civicrm_contact']);
308 $sql = $this->buildQuery(TRUE);
310 $rows = $graphRows = array();
311 $this->buildRows($sql, $rows);
313 $this->formatDisplay($rows);
314 $this->doTemplateAssignment($rows);
315 $this->endPostProcess($rows);
318 function buildChart(&$rows) {
323 $chartInfo = array('legend' => ts('Mail Bounce Report'),
324 'xname' => ts('Mailing'),
325 'yname' => ts('Bounce'),
327 'tip' => ts('Mail Bounce: %1', array(1 => '#val#')),
329 foreach ($rows as $row) {
330 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_bounce_count'];
334 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
335 $this->assign('chartType', $this->_params
['charts']);
338 function bounce_type() {
340 $data = array('' => '--Please Select--');
342 $bounce_type = new CRM_Mailing_DAO_BounceType();
343 $query = "SELECT name FROM civicrm_mailing_bounce_type";
344 $bounce_type->query($query);
346 while ($bounce_type->fetch()) {
347 $data[$bounce_type->name
] = $bounce_type->name
;
353 function alterDisplay(&$rows) {
354 // custom code to alter rows
356 foreach ($rows as $rowNum => $row) {
357 // make count columns point to detail report
358 // convert display name to links
359 if (array_key_exists('civicrm_contact_sort_name', $row) &&
360 array_key_exists('civicrm_contact_id', $row)
362 $url = CRM_Utils_System
::url('civicrm/contact/view',
363 'reset=1&cid=' . $row['civicrm_contact_id'],
366 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
367 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
371 // skip looking further in rows, if first row itself doesn't
372 // have the column we need