Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20370 click and open reports - add date fields #10089

Merged
merged 2 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions CRM/Report/Form/Mailing/Clicks.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ public function __construct() {
'grouping' => 'mailing-fields',
);

$this->_columns['civicrm_mailing_event_trackable_url_open'] = array(
'dao' => 'CRM_Mailing_Event_DAO_TrackableURLOpen',
'fields' => array(
'time_stamp' => array(
'title' => ts('Click Date'),
'default' => TRUE,
),
),
'filters' => array(
'time_stamp' => array(
'title' => ts('Click Date'),
'operatorType' => CRM_Report_Form::OP_DATE,
'type' => CRM_Utils_Type::T_DATE,
),
),
'order_bys' => array(
'time_stamp' => array(
'title' => ts('Click Date'),
),
),
'grouping' => 'mailing-fields',
);

$this->_groupFilter = TRUE;
$this->_tagFilter = TRUE;
parent::__construct();
Expand Down Expand Up @@ -231,7 +254,7 @@ public function select() {
}

if (!empty($this->_params['charts'])) {
$select[] = "COUNT(civicrm_mailing_event_trackable_url_open.id) as civicrm_mailing_click_count";
$select[] = "COUNT({$this->_aliases['civicrm_event_trackable_url_open']}.id) as civicrm_mailing_click_count";
$this->_columnHeaders["civicrm_mailing_click_count"]['title'] = ts('Click Count');
}

Expand All @@ -253,28 +276,30 @@ public static function formRule($fields, $files, $self) {

public function from() {
$this->_from = "
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";

$this->_from .= "
INNER JOIN civicrm_mailing_event_queue
ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
INNER JOIN civicrm_mailing_event_trackable_url_open
ON civicrm_mailing_event_trackable_url_open.event_queue_id = civicrm_mailing_event_queue.id
INNER JOIN civicrm_mailing_trackable_url {$this->_aliases['civicrm_mailing_trackable_url']}
ON civicrm_mailing_event_trackable_url_open.trackable_url_id = {$this->_aliases['civicrm_mailing_trackable_url']}.id
INNER JOIN civicrm_mailing_job
ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
AND civicrm_mailing_job.is_test = 0
";
INNER JOIN civicrm_mailing_event_queue
ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
INNER JOIN civicrm_mailing_event_trackable_url_open {$this->_aliases['civicrm_mailing_event_trackable_url_open']}
ON {$this->_aliases['civicrm_mailing_event_trackable_url_open']}.event_queue_id = civicrm_mailing_event_queue.id
INNER JOIN civicrm_mailing_trackable_url {$this->_aliases['civicrm_mailing_trackable_url']}
ON {$this->_aliases['civicrm_mailing_event_trackable_url_open']}.trackable_url_id = {$this->_aliases['civicrm_mailing_trackable_url']}.id
INNER JOIN civicrm_mailing_job
ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
AND civicrm_mailing_job.is_test = 0
";

if ($this->_phoneField) {
$this->_from .= "
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1 ";
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
AND {$this->_aliases['civicrm_phone']}.is_primary = 1
";
}
}

Expand All @@ -289,7 +314,7 @@ public function groupBy() {
$groupBy = "{$this->_aliases['civicrm_mailing']}.id";
}
else {
$groupBy = "civicrm_mailing_event_trackable_url_open.id";
$groupBy = "{$this->_aliases['civicrm_mailing_event_trackable_url_open']}.id";
}
$this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBy);
}
Expand Down
62 changes: 45 additions & 17 deletions CRM/Report/Form/Mailing/Opened.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,33 @@ public function __construct() {
'grouping' => 'contact-fields',
);

$this->_columns['civicrm_mailing_event_opened'] = array(
'dao' => 'CRM_Mailing_Event_DAO_Opened',
'fields' => array(
'id' => array(
'required' => TRUE,
'no_display' => TRUE,
),
'time_stamp' => array(
'title' => ts('Open Date'),
'default' => TRUE,
),
),
'filters' => array(
'time_stamp' => array(
'title' => ts('Open Date'),
'operatorType' => CRM_Report_Form::OP_DATE,
'type' => CRM_Utils_Type::T_DATE,
),
),
'order_bys' => array(
'time_stamp' => array(
'title' => ts('Open Date'),
),
),
'grouping' => 'mailing-fields',
);

$this->_groupFilter = TRUE;
$this->_tagFilter = TRUE;
parent::__construct();
Expand Down Expand Up @@ -209,7 +236,7 @@ public function select() {
}

if (!empty($this->_params['charts'])) {
$select[] = "COUNT(civicrm_mailing_event_opened.id) as civicrm_mailing_opened_count";
$select[] = "COUNT({$this->_aliases['civicrm_event_opened']}.id) as civicrm_mailing_opened_count";
$this->_columnHeaders["civicrm_mailing_opened_count"]['title'] = ts('Opened Count');
}

Expand All @@ -231,27 +258,28 @@ public static function formRule($fields, $files, $self) {

public function from() {
$this->_from = "
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";

$this->_from .= "
INNER JOIN civicrm_mailing_event_queue
ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
INNER JOIN civicrm_mailing_event_opened
ON civicrm_mailing_event_opened.event_queue_id = civicrm_mailing_event_queue.id
INNER JOIN civicrm_mailing_job
ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
AND civicrm_mailing_job.is_test = 0
";
INNER JOIN civicrm_mailing_event_queue
ON civicrm_mailing_event_queue.contact_id = {$this->_aliases['civicrm_contact']}.id
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON civicrm_mailing_event_queue.email_id = {$this->_aliases['civicrm_email']}.id
INNER JOIN civicrm_mailing_event_opened {$this->_aliases['civicrm_mailing_event_opened']}
ON {$this->_aliases['civicrm_mailing_event_opened']}.event_queue_id = civicrm_mailing_event_queue.id
INNER JOIN civicrm_mailing_job
ON civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id
INNER JOIN civicrm_mailing {$this->_aliases['civicrm_mailing']}
ON civicrm_mailing_job.mailing_id = {$this->_aliases['civicrm_mailing']}.id
AND civicrm_mailing_job.is_test = 0
";

if ($this->_phoneField) {
$this->_from .= "
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1 ";
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
AND {$this->_aliases['civicrm_phone']}.is_primary = 1
";
}
}

Expand Down