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_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',
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',
92 'mailing_name' => array(
94 'title' => ts('Mailing'),
97 'mailing_name_alias' => array(
100 'no_display' => TRUE,
104 'mailing_id' => array(
106 'title' => ts('Mailing'),
107 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
108 'type' => CRM_Utils_Type
::T_INT
,
109 'options' => CRM_Mailing_BAO_Mailing
::getMailingsList(),
110 'operator' => 'like',
118 'title' => ts('Mailing'),
121 'grouping' => 'mailing-fields',
124 $this->_columns
['civicrm_email'] = array(
125 'dao' => 'CRM_Core_DAO_Email',
128 'title' => ts('Email'),
133 'grouping' => 'contact-fields',
136 $this->_columns
['civicrm_phone'] = array(
137 'dao' => 'CRM_Core_DAO_Phone',
138 'fields' => array('phone' => NULL),
139 'grouping' => 'contact-fields',
142 $this->_columns
['civicrm_mailing_trackable_url'] = array(
143 'dao' => 'CRM_Mailing_DAO_TrackableURL',
146 'title' => ts('Click through URL'),
152 array('title' => ts('Click through URL')),
154 'grouping' => 'mailing-fields',
157 $this->_columns
['civicrm_group'] = array(
158 'dao' => 'CRM_Contact_DAO_Group',
162 'name' => 'group_id',
163 'title' => ts('Group'),
164 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
166 'options' => CRM_Core_PseudoConstant
::group(),
171 $this->_tagFilter
= TRUE;
172 parent
::__construct();
175 function preProcess() {
176 $this->assign('chartSupported', TRUE);
177 parent
::preProcess();
182 $this->_columnHeaders
= array();
183 foreach ($this->_columns
as $tableName => $table) {
184 if (array_key_exists('fields', $table)) {
185 foreach ($table['fields'] as $fieldName => $field) {
186 if (CRM_Utils_Array
::value('required', $field) ||
187 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
189 if ($tableName == 'civicrm_email') {
190 $this->_emailField
= TRUE;
192 elseif ($tableName == 'civicrm_phone') {
193 $this->_phoneField
= TRUE;
196 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
197 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
198 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
199 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
205 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
206 $select[] = "COUNT(civicrm_mailing_event_trackable_url_open.id) as civicrm_mailing_click_count";
207 $this->_columnHeaders
["civicrm_mailing_click_count"]['title'] = ts('Click Count');
210 $this->_select
= "SELECT " . implode(', ', $select) . " ";
213 static function formRule($fields, $files, $self) {
214 $errors = $grouping = array();
220 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
223 INNER JOIN civicrm_mailing_event_queue
224 ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
225 INNER JOIN civicrm_email {$this->_aliases['civicrm_email']}
226 ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
227 INNER JOIN civicrm_mailing_event_trackable_url_open
228 ON civicrm_mailing_event_trackable_url_open.event_queue_id = civicrm_mailing_event_queue.id
229 INNER JOIN civicrm_mailing_trackable_url {$this->_aliases['civicrm_mailing_trackable_url']}
230 ON civicrm_mailing_event_trackable_url_open.trackable_url_id = {$this->_aliases['civicrm_mailing_trackable_url']}.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
237 if ($this->_phoneField
) {
239 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
240 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
241 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
247 $this->_where
.= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
252 $this->_groupBy
= '';
253 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
254 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_mailing']}.id";
257 $this->_groupBy
= " GROUP BY civicrm_mailing_event_trackable_url_open.id";
261 function postProcess() {
263 $this->beginPostProcess();
265 // get the acl clauses built before we assemble the query
266 $this->buildACLClause($this->_aliases
['civicrm_contact']);
268 $sql = $this->buildQuery(TRUE);
270 $rows = $graphRows = array();
271 $this->buildRows($sql, $rows);
273 $this->formatDisplay($rows);
274 $this->doTemplateAssignment($rows);
275 $this->endPostProcess($rows);
278 function buildChart(&$rows) {
283 $chartInfo = array('legend' => ts('Mail Clickthrough Report'),
284 'xname' => ts('Mailing'),
285 'yname' => ts('Clicks'),
287 'tip' => ts('Clicks: %1', array(1 => '#val#')),
289 foreach ($rows as $row) {
290 $chartInfo['values'][$row['civicrm_mailing_mailing_name_alias']] = $row['civicrm_mailing_click_count'];
294 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
295 $this->assign('chartType', $this->_params
['charts']);
298 function alterDisplay(&$rows) {
299 // custom code to alter rows
301 foreach ($rows as $rowNum => $row) {
302 // make count columns point to detail report
303 // convert display name to links
304 if (array_key_exists('civicrm_contact_sort_name', $row) &&
305 array_key_exists('civicrm_contact_id', $row)
307 $url = CRM_Utils_System
::url('civicrm/contact/view',
308 'reset=1&cid=' . $row['civicrm_contact_id'],
311 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
312 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
316 // skip looking further in rows, if first row itself doesn't
317 // have the column we need