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_Opened
extends CRM_Report_Form
{
38 protected $_summary = NULL;
40 protected $_emailField = FALSE;
42 protected $_phoneField = FALSE;
44 protected $_customGroupExtends = array('Contact', 'Individual', 'Household', 'Organization');
46 protected $_charts = array(
48 'barChart' => 'Bar Chart',
49 'pieChart' => 'Pie Chart',
58 function __construct() {
59 $this->_columns
= array();
61 $this->_columns
['civicrm_contact'] = array(
62 'dao' => 'CRM_Contact_DAO_Contact',
65 'title' => ts('Contact ID'),
70 'title' => ts('Contact Name'),
76 'title' => ts('Contact Name'),
79 'title' => ts('Contact Source'),
80 'type' => CRM_Utils_Type
::T_STRING
,
83 'title' => ts('Contact ID'),
90 array('title' => ts('Contact Name'), 'default' => TRUE, 'default_order' => 'ASC'),
92 'grouping' => 'contact-fields',
95 $this->_columns
['civicrm_mailing'] = array(
96 'dao' => 'CRM_Mailing_DAO_Mailing',
99 'mailing_name' => array(
101 'title' => ts('Mailing'),
104 'mailing_name_alias' => array(
107 'no_display' => TRUE,
111 'mailing_id' => array(
113 'title' => ts('Mailing'),
114 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
115 'type' => CRM_Utils_Type
::T_INT
,
116 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
117 'operator' => 'like',
125 'title' => ts('Mailing'),
128 'grouping' => 'mailing-fields',
131 $this->_columns
['civicrm_email'] = array(
132 'dao' => 'CRM_Core_DAO_Email',
135 'title' => ts('Email'),
143 array('title' => ts('Email'), 'default_order' => 'ASC'),
145 'grouping' => 'contact-fields',
148 $this->_columns
['civicrm_phone'] = array(
149 'dao' => 'CRM_Core_DAO_Phone',
150 'fields' => array('phone' => NULL),
151 'grouping' => 'contact-fields',
154 $this->_columns
['civicrm_group'] = array(
155 'dao' => 'CRM_Contact_DAO_Group',
159 'name' => 'group_id',
160 'title' => ts('Group'),
161 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
163 'options' => CRM_Core_PseudoConstant
::group(),
168 $this->_tagFilter
= TRUE;
169 parent
::__construct();
172 function preProcess() {
173 $this->assign('chartSupported', TRUE);
174 parent
::preProcess();
179 $this->_columnHeaders
= array();
180 foreach ($this->_columns
as $tableName => $table) {
181 if (array_key_exists('fields', $table)) {
182 foreach ($table['fields'] as $fieldName => $field) {
183 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
184 if ($tableName == 'civicrm_email') {
185 $this->_emailField
= TRUE;
187 elseif ($tableName == 'civicrm_phone') {
188 $this->_phoneField
= TRUE;
191 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
192 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
193 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
194 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
200 if (!empty($this->_params
['charts'])) {
201 $select[] = "COUNT(civicrm_mailing_event_opened.id) as civicrm_mailing_opened_count";
202 $this->_columnHeaders
["civicrm_mailing_opened_count"]['title'] = ts('Opened Count');
205 $this->_select
= "SELECT " . implode(', ', $select) . " ";
215 static function formRule($fields, $files, $self) {
216 $errors = $grouping = array();
222 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
225 INNER JOIN civicrm_mailing_event_queue
226 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
227 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
228 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
229 INNER JOIN civicrm_mailing_event_opened
230 ON civicrm_mailing_event_opened.event_queue_id = civicrm_mailing_event_queue.id
231 INNER JOIN civicrm_mailing_job
232 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
233 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
234 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
235 AND civicrm_mailing_job.is_test = 0
238 if ($this->_phoneField
) {
240 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
241 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
242 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
248 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
252 if (!empty($this->_params
['charts'])) {
253 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
256 $this->_groupBy
= " GROUP BY civicrm_mailing_event_queue.email_id";
260 function postProcess() {
262 $this->beginPostProcess();
264 // get the acl clauses built before we assemble the query
265 $this->buildACLClause($this->_aliases
['civicrm_contact']);
267 $sql = $this->buildQuery(TRUE);
269 $rows = $graphRows = array();
270 $this->buildRows($sql, $rows);
272 $this->formatDisplay($rows);
273 $this->doTemplateAssignment($rows);
274 $this->endPostProcess($rows);
280 function buildChart(&$rows) {
285 $chartInfo = array('legend' => ts('Mail Opened Report'),
286 'xname' => ts('Mailing'),
287 'yname' => ts('Opened'),
289 'tip' => ts('Mail Opened: %1', array(1 => '#val#')),
291 foreach ($rows as $row) {
292 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_opened_count'];
296 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
297 $this->assign('chartType', $this->_params
['charts']);
303 function alterDisplay(&$rows) {
304 // custom code to alter rows
306 foreach ($rows as $rowNum => $row) {
307 // make count columns point to detail report
308 // convert display name to links
309 if (array_key_exists('civicrm_contact_sort_name', $row) &&
310 array_key_exists('civicrm_contact_id', $row)
312 $url = CRM_Utils_System
::url('civicrm/contact/view',
313 'reset=1&cid=' . $row['civicrm_contact_id'],
316 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
317 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
321 // skip looking further in rows, if first row itself doesn't
322 // have the column we need