4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
36 class CRM_Report_Form_Mailing_Bounce
extends CRM_Report_Form
{
38 protected $_summary = NULL;
40 protected $_emailField = FALSE;
42 protected $_phoneField = FALSE;
44 // just a toggle we use to build the from
45 protected $_mailingidField = FALSE;
47 protected $_customGroupExtends = array('Contact', 'Individual', 'Household', 'Organization');
49 protected $_charts = array(
51 'barChart' => 'Bar Chart',
52 'pieChart' => 'Pie Chart',
61 function __construct() {
62 $this->_columns
= array();
64 $this->_columns
['civicrm_contact'] = array(
65 'dao' => 'CRM_Contact_DAO_Contact',
68 'title' => ts('Contact ID'),
73 'title' => ts('Contact Name'),
79 'title' => ts('Contact Name'),
82 'title' => ts('Contact Source'),
83 'type' => CRM_Utils_Type
::T_STRING
,
86 'title' => ts('Contact ID'),
93 array('title' => ts('Contact Name'), 'default' => TRUE, 'default_order' => 'ASC'),
95 'grouping' => 'contact-fields',
98 $this->_columns
['civicrm_mailing'] = array(
99 'dao' => 'CRM_Mailing_DAO_Mailing',
101 'mailing_name' => array(
103 'title' => ts('Mailing'),
106 'mailing_name_alias' => array(
109 'no_display' => TRUE,
113 'mailing_id' => array(
115 'title' => ts('Mailing'),
116 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
117 'type' => CRM_Utils_Type
::T_INT
,
118 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
119 'operator' => 'like',
127 'title' => ts('Mailing'),
130 'grouping' => 'mailing-fields',
133 $this->_columns
['civicrm_mailing_event_bounce'] = array(
134 'dao' => 'CRM_Mailing_DAO_Mailing',
136 'bounce_reason' => array(
137 'title' => ts('Bounce Reason'),
143 array('title' => ts('Bounce Reason')),
145 'grouping' => 'mailing-fields',
148 $this->_columns
['civicrm_mailing_bounce_type'] = array(
149 'dao' => 'CRM_Mailing_DAO_BounceType',
151 'bounce_name' => array(
153 'title' => ts('Bounce Type'),
157 'bounce_type_name' => array(
159 'title' => ts('Bounce Type'),
160 'operatorType' => CRM_Report_Form
::OP_SELECT
,
161 'type' => CRM_Utils_Type
::T_STRING
,
162 'options' => self
::bounce_type(),
163 'operator' => 'like',
171 'title' => ts('Bounce Type'),
174 'grouping' => 'mailing-fields',
177 $this->_columns
['civicrm_email'] = array(
178 'dao' => 'CRM_Core_DAO_Email',
181 'title' => ts('Email'),
189 array('title' => ts('Email'), 'default_order' => 'ASC'),
191 'grouping' => 'contact-fields',
194 $this->_columns
['civicrm_phone'] = array(
195 'dao' => 'CRM_Core_DAO_Phone',
196 'fields' => array('phone' => NULL),
197 'grouping' => 'contact-fields',
200 $this->_columns
['civicrm_group'] = array(
201 'dao' => 'CRM_Contact_DAO_Group',
205 'name' => 'group_id',
206 'title' => ts('Group'),
207 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
209 'options' => CRM_Core_PseudoConstant
::group(),
214 $this->_tagFilter
= TRUE;
215 parent
::__construct();
218 function preProcess() {
219 $this->assign('chartSupported', TRUE);
220 parent
::preProcess();
225 $this->_columnHeaders
= array();
227 foreach ($this->_columns
as $tableName => $table) {
228 if (array_key_exists('fields', $table)) {
229 foreach ($table['fields'] as $fieldName => $field) {
230 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
231 if ($tableName == 'civicrm_email') {
232 $this->_emailField
= TRUE;
234 elseif ($tableName == 'civicrm_phone') {
235 $this->_phoneField
= TRUE;
238 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
239 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
240 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
241 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
248 if (!empty($this->_params
['charts'])) {
249 $select[] = "COUNT({$this->_aliases['civicrm_mailing_event_bounce']}.id) as civicrm_mailing_bounce_count";
250 $this->_columnHeaders
["civicrm_mailing_bounce_count"]['title'] = ts('Bounce Count');
253 $this->_select
= "SELECT " . implode(', ', $select) . " ";
263 static function formRule($fields, $files, $self) {
264 $errors = $grouping = array();
270 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
271 // LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
272 // ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
273 // {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
276 INNER JOIN civicrm_mailing_event_queue
277 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
278 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
279 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
280 INNER JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']}
281 ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = civicrm_mailing_event_queue.id
282 LEFT JOIN civicrm_mailing_bounce_type {$this->_aliases['civicrm_mailing_bounce_type']}
283 ON {$this->_aliases['civicrm_mailing_event_bounce']}.bounce_type_id = {$this->_aliases['civicrm_mailing_bounce_type']}.id
284 INNER JOIN civicrm_mailing_job
285 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
286 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
287 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
290 if ($this->_phoneField
) {
292 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
293 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
294 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
300 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
304 if (!empty($this->_params
['charts'])) {
305 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
308 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing_event_bounce']}.id";
312 function postProcess() {
313 $this->beginPostProcess();
315 // get the acl clauses built before we assemble the query
316 $this->buildACLClause($this->_aliases
['civicrm_contact']);
318 $sql = $this->buildQuery(TRUE);
320 $rows = $graphRows = array();
321 $this->buildRows($sql, $rows);
323 $this->formatDisplay($rows);
324 $this->doTemplateAssignment($rows);
325 $this->endPostProcess($rows);
331 function buildChart(&$rows) {
336 $chartInfo = array('legend' => ts('Mail Bounce Report'),
337 'xname' => ts('Mailing'),
338 'yname' => ts('Bounce'),
340 'tip' => ts('Mail Bounce: %1', array(1 => '#val#')),
342 foreach ($rows as $row) {
343 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_bounce_count'];
347 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
348 $this->assign('chartType', $this->_params
['charts']);
354 function bounce_type() {
356 $data = array('' => '--Please Select--');
358 $bounce_type = new CRM_Mailing_DAO_BounceType();
359 $query = "SELECT name FROM civicrm_mailing_bounce_type";
360 $bounce_type->query($query);
362 while ($bounce_type->fetch()) {
363 $data[$bounce_type->name
] = $bounce_type->name
;
372 function alterDisplay(&$rows) {
373 // custom code to alter rows
375 foreach ($rows as $rowNum => $row) {
376 // make count columns point to detail report
377 // convert display name to links
378 if (array_key_exists('civicrm_contact_sort_name', $row) &&
379 array_key_exists('civicrm_contact_id', $row)
381 $url = CRM_Utils_System
::url('civicrm/contact/view',
382 'reset=1&cid=' . $row['civicrm_contact_id'],
385 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
386 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
390 // skip looking further in rows, if first row itself doesn't
391 // have the column we need