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 (CRM_Utils_Array
::value('required', $field) ||
225 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
227 if ($tableName == 'civicrm_email') {
228 $this->_emailField
= TRUE;
230 elseif ($tableName == 'civicrm_phone') {
231 $this->_phoneField
= TRUE;
234 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
235 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
236 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
237 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
244 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
245 $select[] = "COUNT({$this->_aliases['civicrm_mailing_event_bounce']}.id) as civicrm_mailing_bounce_count";
246 $this->_columnHeaders
["civicrm_mailing_bounce_count"]['title'] = ts('Bounce Count');
249 $this->_select
= "SELECT " . implode(', ', $select) . " ";
252 static function formRule($fields, $files, $self) {
253 $errors = $grouping = array();
259 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
260 // LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
261 // ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
262 // {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
265 INNER JOIN civicrm_mailing_event_queue
266 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
267 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
268 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
269 INNER JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']}
270 ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = civicrm_mailing_event_queue.id
271 LEFT JOIN civicrm_mailing_bounce_type {$this->_aliases['civicrm_mailing_bounce_type']}
272 ON {$this->_aliases['civicrm_mailing_event_bounce']}.bounce_type_id = {$this->_aliases['civicrm_mailing_bounce_type']}.id
273 INNER JOIN civicrm_mailing_job
274 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
275 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
276 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
279 if ($this->_phoneField
) {
281 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
282 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
283 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
289 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
293 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
294 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
297 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing_event_bounce']}.id";
301 function postProcess() {
302 $this->beginPostProcess();
304 // get the acl clauses built before we assemble the query
305 $this->buildACLClause($this->_aliases
['civicrm_contact']);
307 $sql = $this->buildQuery(TRUE);
309 $rows = $graphRows = array();
310 $this->buildRows($sql, $rows);
312 $this->formatDisplay($rows);
313 $this->doTemplateAssignment($rows);
314 $this->endPostProcess($rows);
317 function buildChart(&$rows) {
322 $chartInfo = array('legend' => ts('Mail Bounce Report'),
323 'xname' => ts('Mailing'),
324 'yname' => ts('Bounce'),
326 'tip' => ts('Mail Bounce: %1', array(1 => '#val#')),
328 foreach ($rows as $row) {
329 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_bounce_count'];
333 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
334 $this->assign('chartType', $this->_params
['charts']);
337 function bounce_type() {
339 $data = array('' => '--Please Select--');
341 $bounce_type = new CRM_Mailing_DAO_BounceType();
342 $query = "SELECT name FROM civicrm_mailing_bounce_type";
343 $bounce_type->query($query);
345 while ($bounce_type->fetch()) {
346 $data[$bounce_type->name
] = $bounce_type->name
;
352 function alterDisplay(&$rows) {
353 // custom code to alter rows
355 foreach ($rows as $rowNum => $row) {
356 // make count columns point to detail report
357 // convert display name to links
358 if (array_key_exists('civicrm_contact_sort_name', $row) &&
359 array_key_exists('civicrm_contact_id', $row)
361 $url = CRM_Utils_System
::url('civicrm/contact/view',
362 'reset=1&cid=' . $row['civicrm_contact_id'],
365 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
366 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
370 // skip looking further in rows, if first row itself doesn't
371 // have the column we need