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_Clicks
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',
98 'mailing_name' => array(
100 'title' => ts('Mailing'),
103 'mailing_name_alias' => array(
106 'no_display' => TRUE,
110 'mailing_id' => array(
112 'title' => ts('Mailing'),
113 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
114 'type' => CRM_Utils_Type
::T_INT
,
115 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
116 'operator' => 'like',
124 'title' => ts('Mailing'),
127 'grouping' => 'mailing-fields',
130 $this->_columns
['civicrm_email'] = array(
131 'dao' => 'CRM_Core_DAO_Email',
134 'title' => ts('Email'),
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_mailing_trackable_url'] = array(
149 'dao' => 'CRM_Mailing_DAO_TrackableURL',
152 'title' => ts('Click through URL'),
158 array('title' => ts('Click through URL')),
160 'grouping' => 'mailing-fields',
163 $this->_columns
['civicrm_group'] = array(
164 'dao' => 'CRM_Contact_DAO_Group',
168 'name' => 'group_id',
169 'title' => ts('Group'),
170 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
172 'options' => CRM_Core_PseudoConstant
::group(),
177 $this->_tagFilter
= TRUE;
178 parent
::__construct();
181 function preProcess() {
182 $this->assign('chartSupported', TRUE);
183 parent
::preProcess();
188 $this->_columnHeaders
= array();
189 foreach ($this->_columns
as $tableName => $table) {
190 if (array_key_exists('fields', $table)) {
191 foreach ($table['fields'] as $fieldName => $field) {
192 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
193 if ($tableName == 'civicrm_email') {
194 $this->_emailField
= TRUE;
196 elseif ($tableName == 'civicrm_phone') {
197 $this->_phoneField
= TRUE;
200 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
201 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
202 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
203 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
209 if (!empty($this->_params
['charts'])) {
210 $select[] = "COUNT(civicrm_mailing_event_trackable_url_open.id) as civicrm_mailing_click_count";
211 $this->_columnHeaders
["civicrm_mailing_click_count"]['title'] = ts('Click Count');
214 $this->_select
= "SELECT " . implode(', ', $select) . " ";
224 static function formRule($fields, $files, $self) {
225 $errors = $grouping = array();
231 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
234 INNER JOIN civicrm_mailing_event_queue
235 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
236 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
237 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
238 INNER JOIN civicrm_mailing_event_trackable_url_open
239 ON civicrm_mailing_event_trackable_url_open.event_queue_id = civicrm_mailing_event_queue.id
240 INNER JOIN civicrm_mailing_trackable_url {$this->_aliases['civicrm_mailing_trackable_url']}
241 ON civicrm_mailing_event_trackable_url_open.trackable_url_id = {$this->_aliases['civicrm_mailing_trackable_url']}.id
242 INNER JOIN civicrm_mailing_job
243 ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
244 INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
245 ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
246 AND civicrm_mailing_job.is_test = 0
248 if ($this->_phoneField
) {
250 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
251 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
252 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
258 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
263 $this->_groupBy
= '';
264 if (!empty($this->_params
['charts'])) {
265 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
268 $this->_groupBy
= " GROUP BY civicrm_mailing_event_trackable_url_open.id";
272 function postProcess() {
274 $this->beginPostProcess();
276 // get the acl clauses built before we assemble the query
277 $this->buildACLClause($this->_aliases
['civicrm_contact']);
279 $sql = $this->buildQuery(TRUE);
281 $rows = $graphRows = array();
282 $this->buildRows($sql, $rows);
284 $this->formatDisplay($rows);
285 $this->doTemplateAssignment($rows);
286 $this->endPostProcess($rows);
292 function buildChart(&$rows) {
297 $chartInfo = array('legend' => ts('Mail Clickthrough Report'),
298 'xname' => ts('Mailing'),
299 'yname' => ts('Clicks'),
301 'tip' => ts('Clicks: %1', array(1 => '#val#')),
303 foreach ($rows as $row) {
304 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_click_count'];
308 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
309 $this->assign('chartType', $this->_params
['charts']);
315 function alterDisplay(&$rows) {
316 // custom code to alter rows
318 foreach ($rows as $rowNum => $row) {
319 // make count columns point to detail report
320 // convert display name to links
321 if (array_key_exists('civicrm_contact_sort_name', $row) &&
322 array_key_exists('civicrm_contact_id', $row)
324 $url = CRM_Utils_System
::url('civicrm/contact/view',
325 'reset=1&cid=' . $row['civicrm_contact_id'],
328 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
329 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
333 // skip looking further in rows, if first row itself doesn't
334 // have the column we need