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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Report_Form_Mailing_Bounce
extends CRM_Report_Form
{
37 protected $_summary = NULL;
39 protected $_emailField = FALSE;
41 protected $_phoneField = FALSE;
43 // just a toggle we use to build the from
44 protected $_mailingidField = FALSE;
46 protected $_customGroupExtends = array(
53 protected $_charts = array(
55 'barChart' => 'Bar Chart',
56 'pieChart' => 'Pie Chart',
63 public function __construct() {
64 $this->_columns
= array();
66 $this->_columns
['civicrm_contact'] = array(
67 'dao' => 'CRM_Contact_DAO_Contact',
70 'title' => ts('Contact ID'),
74 'title' => ts('Contact Name'),
80 'title' => ts('Contact Name'),
83 'title' => ts('Contact Source'),
84 'type' => CRM_Utils_Type
::T_STRING
,
87 'title' => ts('Contact ID'),
93 'title' => ts('Contact Name'),
95 'default_order' => 'ASC',
98 'grouping' => 'contact-fields',
101 $this->_columns
['civicrm_mailing'] = array(
102 'dao' => 'CRM_Mailing_DAO_Mailing',
104 'mailing_name' => array(
106 'title' => ts('Mailing'),
109 'mailing_name_alias' => array(
112 'no_display' => TRUE,
116 'mailing_id' => array(
118 'title' => ts('Mailing'),
119 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
120 'type' => CRM_Utils_Type
::T_INT
,
121 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
122 'operator' => 'like',
125 'order_bys' => array(
126 'mailing_name' => array(
128 'title' => ts('Mailing'),
131 'grouping' => 'mailing-fields',
134 $this->_columns
['civicrm_mailing_event_bounce'] = array(
135 'dao' => 'CRM_Mailing_DAO_Mailing',
137 'bounce_reason' => array(
138 'title' => ts('Bounce Reason'),
141 'order_bys' => array(
142 'bounce_reason' => array('title' => ts('Bounce Reason')),
144 'grouping' => 'mailing-fields',
147 $this->_columns
['civicrm_mailing_bounce_type'] = array(
148 'dao' => 'CRM_Mailing_DAO_BounceType',
150 'bounce_name' => array(
152 'title' => ts('Bounce Type'),
156 'bounce_type_name' => array(
158 'title' => ts('Bounce Type'),
159 'operatorType' => CRM_Report_Form
::OP_SELECT
,
160 'type' => CRM_Utils_Type
::T_STRING
,
161 'options' => self
::bounce_type(),
162 'operator' => 'like',
165 'order_bys' => array(
166 'bounce_name' => array(
168 'title' => ts('Bounce Type'),
171 'grouping' => 'mailing-fields',
174 $this->_columns
['civicrm_email'] = array(
175 'dao' => 'CRM_Core_DAO_Email',
178 'title' => ts('Email'),
183 'order_bys' => array(
184 'email' => 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->_groupFilter
= TRUE;
196 $this->_tagFilter
= TRUE;
197 parent
::__construct();
200 public function preProcess() {
201 $this->assign('chartSupported', TRUE);
202 parent
::preProcess();
205 public function select() {
207 $this->_columnHeaders
= array();
209 foreach ($this->_columns
as $tableName => $table) {
210 if (array_key_exists('fields', $table)) {
211 foreach ($table['fields'] as $fieldName => $field) {
212 if (!empty($field['required']) ||
213 !empty($this->_params
['fields'][$fieldName])
215 if ($tableName == 'civicrm_email') {
216 $this->_emailField
= TRUE;
218 elseif ($tableName == 'civicrm_phone') {
219 $this->_phoneField
= TRUE;
222 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
223 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
224 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
225 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
231 if (!empty($this->_params
['charts'])) {
232 $select[] = "COUNT({$this->_aliases['civicrm_mailing_event_bounce']}.id) as civicrm_mailing_bounce_count";
233 $this->_columnHeaders
["civicrm_mailing_bounce_count"]['title'] = ts('Bounce Count');
236 $this->_select
= "SELECT " . implode(', ', $select) . " ";
246 public static function formRule($fields, $files, $self) {
247 $errors = $grouping = array();
251 public function from() {
253 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
254 // LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
255 // ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
256 // {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
259 INNER JOIN civicrm_mailing_event_queue
260 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
261 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
262 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
263 INNER JOIN civicrm_mailing_event_bounce {$this->_aliases['civicrm_mailing_event_bounce']}
264 ON {$this->_aliases['civicrm_mailing_event_bounce']}.event_queue_id = civicrm_mailing_event_queue.id
265 LEFT JOIN civicrm_mailing_bounce_type {$this->_aliases['civicrm_mailing_bounce_type']}
266 ON {$this->_aliases['civicrm_mailing_event_bounce']}.bounce_type_id = {$this->_aliases['civicrm_mailing_bounce_type']}.id
267 INNER JOIN civicrm_mailing_job
268 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
269 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
270 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
273 if ($this->_phoneField
) {
275 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
276 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
277 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
281 public function where() {
283 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
286 public function groupBy() {
287 if (!empty($this->_params
['charts'])) {
288 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
291 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing_event_bounce']}.id";
295 public function postProcess() {
296 $this->beginPostProcess();
298 // get the acl clauses built before we assemble the query
299 $this->buildACLClause($this->_aliases
['civicrm_contact']);
301 $sql = $this->buildQuery(TRUE);
303 $rows = $graphRows = array();
304 $this->buildRows($sql, $rows);
306 $this->formatDisplay($rows);
307 $this->doTemplateAssignment($rows);
308 $this->endPostProcess($rows);
314 public function buildChart(&$rows) {
320 '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']);
338 public 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
;
356 public function alterDisplay(&$rows) {
357 // custom code to alter rows
359 foreach ($rows as $rowNum => $row) {
360 // make count columns point to detail report
361 // convert display name to links
362 if (array_key_exists('civicrm_contact_sort_name', $row) &&
363 array_key_exists('civicrm_contact_id', $row)
365 $url = CRM_Utils_System
::url('civicrm/contact/view',
366 'reset=1&cid=' . $row['civicrm_contact_id'],
369 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
370 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
374 // skip looking further in rows, if first row itself doesn't
375 // have the column we need