4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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',
55 function __construct() {
56 $this->_columns
= array();
58 $this->_columns
['civicrm_contact'] = array(
59 'dao' => 'CRM_Contact_DAO_Contact',
62 'title' => ts('Contact ID'),
67 'title' => ts('Contact Name'),
73 'title' => ts('Contact Name'),
76 'title' => ts('Contact Source'),
77 'type' => CRM_Utils_Type
::T_STRING
,
80 'title' => ts('Contact ID'),
87 array('title' => ts('Contact Name'), 'default' => TRUE, 'default_order' => 'ASC'),
89 'grouping' => 'contact-fields',
92 $this->_columns
['civicrm_mailing'] = array(
93 'dao' => 'CRM_Mailing_DAO_Mailing',
95 'mailing_name' => array(
97 'title' => ts('Mailing'),
100 'mailing_name_alias' => array(
103 'no_display' => TRUE,
107 'mailing_id' => array(
109 'title' => ts('Mailing'),
110 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
111 'type' => CRM_Utils_Type
::T_INT
,
112 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
113 'operator' => 'like',
121 'title' => ts('Mailing'),
124 'grouping' => 'mailing-fields',
127 $this->_columns
['civicrm_mailing_event_bounce'] = array(
128 'dao' => 'CRM_Mailing_DAO_Mailing',
130 'bounce_reason' => array(
131 'title' => ts('Bounce Reason'),
137 array('title' => ts('Bounce Reason')),
139 'grouping' => 'mailing-fields',
142 $this->_columns
['civicrm_mailing_bounce_type'] = array(
143 'dao' => 'CRM_Mailing_DAO_BounceType',
145 'bounce_name' => array(
147 'title' => ts('Bounce Type'),
151 'bounce_type_name' => array(
153 'title' => ts('Bounce Type'),
154 'operatorType' => CRM_Report_Form
::OP_SELECT
,
155 'type' => CRM_Utils_Type
::T_STRING
,
156 'options' => self
::bounce_type(),
157 'operator' => 'like',
165 'title' => ts('Bounce Type'),
168 'grouping' => 'mailing-fields',
171 $this->_columns
['civicrm_email'] = array(
172 'dao' => 'CRM_Core_DAO_Email',
175 'title' => ts('Email'),
183 array('title' => ts('Email'), 'default_order' => 'ASC'),
185 'grouping' => 'contact-fields',
188 $this->_columns
['civicrm_phone'] = array(
189 'dao' => 'CRM_Core_DAO_Phone',
190 'fields' => array('phone' => NULL),
191 'grouping' => 'contact-fields',
194 $this->_columns
['civicrm_group'] = array(
195 'dao' => 'CRM_Contact_DAO_Group',
199 'name' => 'group_id',
200 'title' => ts('Group'),
201 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
203 'options' => CRM_Core_PseudoConstant
::group(),
208 $this->_tagFilter
= TRUE;
209 parent
::__construct();
212 function preProcess() {
213 $this->assign('chartSupported', TRUE);
214 parent
::preProcess();
219 $this->_columnHeaders
= array();
221 foreach ($this->_columns
as $tableName => $table) {
222 if (array_key_exists('fields', $table)) {
223 foreach ($table['fields'] as $fieldName => $field) {
224 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
225 if ($tableName == 'civicrm_email') {
226 $this->_emailField
= TRUE;
228 elseif ($tableName == 'civicrm_phone') {
229 $this->_phoneField
= TRUE;
232 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
233 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
234 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
235 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
242 if (!empty($this->_params
['charts'])) {
243 $select[] = "COUNT({$this->_aliases['civicrm_mailing_event_bounce']}.id) as civicrm_mailing_bounce_count";
244 $this->_columnHeaders
["civicrm_mailing_bounce_count"]['title'] = ts('Bounce Count');
247 $this->_select
= "SELECT " . implode(', ', $select) . " ";
250 static function formRule($fields, $files, $self) {
251 $errors = $grouping = array();
257 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
258 // LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
259 // ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
260 // {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
263 INNER JOIN civicrm_mailing_event_queue
264 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
265 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
266 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
267 INNER JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']}
268 ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = civicrm_mailing_event_queue.id
269 LEFT JOIN civicrm_mailing_bounce_type {$this->_aliases['civicrm_mailing_bounce_type']}
270 ON {$this->_aliases['civicrm_mailing_event_bounce']}.bounce_type_id = {$this->_aliases['civicrm_mailing_bounce_type']}.id
271 INNER JOIN civicrm_mailing_job
272 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
273 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
274 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
277 if ($this->_phoneField
) {
279 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
280 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
281 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
287 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
291 if (!empty($this->_params
['charts'])) {
292 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
295 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing_event_bounce']}.id";
299 function postProcess() {
300 $this->beginPostProcess();
302 // get the acl clauses built before we assemble the query
303 $this->buildACLClause($this->_aliases
['civicrm_contact']);
305 $sql = $this->buildQuery(TRUE);
307 $rows = $graphRows = array();
308 $this->buildRows($sql, $rows);
310 $this->formatDisplay($rows);
311 $this->doTemplateAssignment($rows);
312 $this->endPostProcess($rows);
315 function buildChart(&$rows) {
320 $chartInfo = array('legend' => ts('Mail Bounce Report'),
321 'xname' => ts('Mailing'),
322 'yname' => ts('Bounce'),
324 'tip' => ts('Mail Bounce: %1', array(1 => '#val#')),
326 foreach ($rows as $row) {
327 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_bounce_count'];
331 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
332 $this->assign('chartType', $this->_params
['charts']);
335 function bounce_type() {
337 $data = array('' => '--Please Select--');
339 $bounce_type = new CRM_Mailing_DAO_BounceType();
340 $query = "SELECT name FROM civicrm_mailing_bounce_type";
341 $bounce_type->query($query);
343 while ($bounce_type->fetch()) {
344 $data[$bounce_type->name
] = $bounce_type->name
;
350 function alterDisplay(&$rows) {
351 // custom code to alter rows
353 foreach ($rows as $rowNum => $row) {
354 // make count columns point to detail report
355 // convert display name to links
356 if (array_key_exists('civicrm_contact_sort_name', $row) &&
357 array_key_exists('civicrm_contact_id', $row)
359 $url = CRM_Utils_System
::url('civicrm/contact/view',
360 'reset=1&cid=' . $row['civicrm_contact_id'],
363 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
364 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
368 // skip looking further in rows, if first row itself doesn't
369 // have the column we need