4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
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_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',
52 function __construct() {
53 $this->_columns
= array();
55 $this->_columns
['civicrm_contact'] = array(
56 'dao' => 'CRM_Contact_DAO_Contact',
59 'title' => ts('Contact ID'),
64 'title' => ts('Contact Name'),
70 'title' => ts('Contact Name'),
73 'title' => ts('Contact Source'),
74 'type' => CRM_Utils_Type
::T_STRING
,
77 'title' => ts('Contact ID'),
84 array('title' => ts('Contact Name'), 'default' => TRUE, 'default_order' => 'ASC'),
86 'grouping' => 'contact-fields',
89 $this->_columns
['civicrm_mailing'] = array(
90 'dao' => 'CRM_Mailing_DAO_Mailing',
93 'mailing_name' => array(
95 'title' => ts('Mailing'),
98 'mailing_name_alias' => array(
101 'no_display' => TRUE,
105 'mailing_id' => array(
107 'title' => ts('Mailing'),
108 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
109 'type' => CRM_Utils_Type
::T_INT
,
110 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
111 'operator' => 'like',
119 'title' => ts('Mailing'),
122 'grouping' => 'mailing-fields',
125 $this->_columns
['civicrm_email'] = array(
126 'dao' => 'CRM_Core_DAO_Email',
129 'title' => ts('Email'),
137 array('title' => ts('Email'), 'default_order' => 'ASC'),
139 'grouping' => 'contact-fields',
142 $this->_columns
['civicrm_phone'] = array(
143 'dao' => 'CRM_Core_DAO_Phone',
144 'fields' => array('phone' => NULL),
145 'grouping' => 'contact-fields',
148 $this->_columns
['civicrm_group'] = array(
149 'dao' => 'CRM_Contact_DAO_Group',
153 'name' => 'group_id',
154 'title' => ts('Group'),
155 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
157 'options' => CRM_Core_PseudoConstant
::group(),
162 $this->_tagFilter
= TRUE;
163 parent
::__construct();
166 function preProcess() {
167 $this->assign('chartSupported', TRUE);
168 parent
::preProcess();
173 $this->_columnHeaders
= array();
174 foreach ($this->_columns
as $tableName => $table) {
175 if (array_key_exists('fields', $table)) {
176 foreach ($table['fields'] as $fieldName => $field) {
177 if (CRM_Utils_Array
::value('required', $field) ||
178 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
180 if ($tableName == 'civicrm_email') {
181 $this->_emailField
= TRUE;
183 elseif ($tableName == 'civicrm_phone') {
184 $this->_phoneField
= TRUE;
187 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
188 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
189 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
190 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
196 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
197 $select[] = "COUNT(civicrm_mailing_event_opened.id) as civicrm_mailing_opened_count";
198 $this->_columnHeaders
["civicrm_mailing_opened_count"]['title'] = ts('Opened Count');
201 $this->_select
= "SELECT " . implode(', ', $select) . " ";
204 static function formRule($fields, $files, $self) {
205 $errors = $grouping = array();
211 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
214 INNER JOIN civicrm_mailing_event_queue
215 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
216 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
217 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
218 INNER JOIN civicrm_mailing_event_opened
219 ON civicrm_mailing_event_opened.event_queue_id = civicrm_mailing_event_queue.id
220 INNER JOIN civicrm_mailing_job
221 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
222 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
223 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
224 AND civicrm_mailing_job.is_test = 0
227 if ($this->_phoneField
) {
229 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
230 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
231 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
237 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
241 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
242 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
245 $this->_groupBy
= " GROUP BY civicrm_mailing_event_queue.email_id";
249 function postProcess() {
251 $this->beginPostProcess();
253 // get the acl clauses built before we assemble the query
254 $this->buildACLClause($this->_aliases
['civicrm_contact']);
256 $sql = $this->buildQuery(TRUE);
258 $rows = $graphRows = array();
259 $this->buildRows($sql, $rows);
261 $this->formatDisplay($rows);
262 $this->doTemplateAssignment($rows);
263 $this->endPostProcess($rows);
266 function buildChart(&$rows) {
271 $chartInfo = array('legend' => ts('Mail Opened Report'),
272 'xname' => ts('Mailing'),
273 'yname' => ts('Opened'),
275 'tip' => ts('Mail Opened: %1', array(1 => '#val#')),
277 foreach ($rows as $row) {
278 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_opened_count'];
282 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
283 $this->assign('chartType', $this->_params
['charts']);
286 function alterDisplay(&$rows) {
287 // custom code to alter rows
289 foreach ($rows as $rowNum => $row) {
290 // make count columns point to detail report
291 // convert display name to links
292 if (array_key_exists('civicrm_contact_sort_name', $row) &&
293 array_key_exists('civicrm_contact_id', $row)
295 $url = CRM_Utils_System
::url('civicrm/contact/view',
296 'reset=1&cid=' . $row['civicrm_contact_id'],
299 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
300 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
304 // skip looking further in rows, if first row itself doesn't
305 // have the column we need