Skip to content
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
189 changes: 189 additions & 0 deletions CRM/Report/Form/Mailing/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Abstract base class for Mailing reports.
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
abstract class CRM_Report_Form_Mailing_Base extends CRM_Report_Form {

protected $_customGroupExtends = [
'Contact',
'Individual',
'Household',
'Organization',
];

/**
* This report has not been optimised for group filtering.
*
* The functionality for group filtering has been improved but not
* all reports have been adjusted to take care of it. This report has not
* and will run an inefficient query until fixed.
*
* @var bool
* @see https://issues.civicrm.org/jira/browse/CRM-19170
*/
protected $groupFilterNotOptimised = TRUE;

/**
* Get standard column definition for civicrm_mailing table.
*
* @return array
*/
protected function getMailingColumns(): array {
return [
'dao' => 'CRM_Mailing_DAO_Mailing',
'fields' => [
'mailing_name' => [
'name' => 'name',
'title' => ts('Mailing Name'),
'default' => TRUE,
],
'mailing_name_alias' => [
'name' => 'name',
'title' => ts('Mailing Name'),
'required' => TRUE,
'no_display' => TRUE,
],
'mailing_subject' => [
'name' => 'subject',
'title' => ts('Mailing Subject'),
'default' => TRUE,
],
],
'filters' => [
'mailing_id' => [
'name' => 'id',
'title' => ts('Mailing Name'),
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'type' => CRM_Utils_Type::T_INT,
'options' => CRM_Mailing_BAO_Mailing::getMailingsList(),
'operator' => 'like',
],
'mailing_subject' => [
'name' => 'subject',
'title' => ts('Mailing Subject'),
'type' => CRM_Utils_Type::T_STRING,
'operator' => 'like',
],
],
'order_bys' => [
'mailing_name' => [
'name' => 'name',
'title' => ts('Mailing Name'),
],
'mailing_subject' => [
'name' => 'subject',
'title' => ts('Mailing Subject'),
],
],
'grouping' => 'mailing-fields',
];
}

/**
* Get standard column definition for civicrm_contact table in mailing reports.
*
* @param array $options
*
* @return array
*/
protected function getContactColumns($options = []): array {
return [
'dao' => 'CRM_Contact_DAO_Contact',
'fields' => [
'id' => [
'title' => ts('Contact ID'),
'required' => TRUE,
],
'sort_name' => [
'title' => ts('Contact Name'),
'required' => TRUE,
],
],
'filters' => [
'sort_name' => [
'title' => ts('Contact Name'),
],
'source' => [
'title' => ts('Contact Source'),
'type' => CRM_Utils_Type::T_STRING,
],
'id' => [
'title' => ts('Contact ID'),
'no_display' => TRUE,
],
],
'order_bys' => [
'sort_name' => [
'title' => ts('Contact Name'),
'default' => TRUE,
'default_order' => 'ASC',
],
],
'grouping' => 'contact-fields',
];
}

/**
* Filter out SMS provider mailings in WHERE clause.
*/
public function where() {
parent::where();
if (!empty($this->_aliases['civicrm_mailing'])) {
$this->_where .= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
}
}

/**
* Alter display of rows.
*
* Iterate through the rows retrieved via SQL and make changes for display purposes,
* such as rendering contacts as links.
*
* @param array $rows
* Rows generated by SQL, with an array for each row.
*/
public function alterDisplay(&$rows) {
$entryFound = FALSE;
foreach ($rows as $rowNum => $row) {

// If the email address has been deleted
if (array_key_exists('civicrm_email_email', $row)) {
if (empty($rows[$rowNum]['civicrm_email_email'])) {
$rows[$rowNum]['civicrm_email_email'] = '<del>' . ts('Email address deleted.') . '</del>';
}
$entryFound = TRUE;
}

// Make count columns point to detail report / convert display name to links
if (array_key_exists('civicrm_contact_sort_name', $row) &&
array_key_exists('civicrm_contact_id', $row)
) {
$url = CRM_Utils_System::url('civicrm/contact/view',
'reset=1&cid=' . $row['civicrm_contact_id'],
$this->_absoluteUrl
);
$rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
$rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
$entryFound = TRUE;
}

if (!$entryFound) {
break;
}
}
}

}
135 changes: 7 additions & 128 deletions CRM/Report/Form/Mailing/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,121 +14,23 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form_Mailing_Base {

protected $_summary = NULL;

protected $_emailField = FALSE;

protected $_phoneField = FALSE;

protected $_customGroupExtends = [
'Contact',
'Individual',
'Household',
'Organization',
];

/**
* This report has not been optimised for group filtering.
*
* The functionality for group filtering has been improved but not
* all reports have been adjusted to take care of it. This report has not
* and will run an inefficient query until fixed.
*
* @var bool
* @see https://issues.civicrm.org/jira/browse/CRM-19170
*/
protected $groupFilterNotOptimised = TRUE;

/**
* Class constructor.
*/
public function __construct() {
$this->_columns = [];

$this->_columns['civicrm_contact'] = [
'dao' => 'CRM_Contact_DAO_Contact',
'fields' => [
'id' => [
'title' => ts('Contact ID'),
'required' => TRUE,
],
'sort_name' => [
'title' => ts('Contact Name'),
'required' => TRUE,
],
],
'filters' => [
'sort_name' => [
'title' => ts('Contact Name'),
],
'source' => [
'title' => ts('Contact Source'),
'type' => CRM_Utils_Type::T_STRING,
],
'id' => [
'title' => ts('Contact ID'),
'no_display' => TRUE,
],
],
'order_bys' => [
'sort_name' => [
'title' => ts('Contact Name'),
'default' => TRUE,
'default_order' => 'ASC',
],
],
'grouping' => 'contact-fields',
];
$this->_columns['civicrm_contact'] = $this->getContactColumns();

$this->_columns['civicrm_mailing'] = [
'dao' => 'CRM_Mailing_DAO_Mailing',
'fields' => [
'mailing_name' => [
'name' => 'name',
'title' => ts('Mailing Name'),
'default' => TRUE,
],
'mailing_name_alias' => [
'name' => 'name',
'required' => TRUE,
'no_display' => TRUE,
],
'mailing_subject' => [
'name' => 'subject',
'title' => ts('Mailing Subject'),
'default' => TRUE,
],
],
'filters' => [
'mailing_id' => [
'name' => 'id',
'title' => ts('Mailing Name'),
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'type' => CRM_Utils_Type::T_INT,
'options' => CRM_Mailing_BAO_Mailing::getMailingsList(),
'operator' => 'like',
],
'mailing_subject' => [
'name' => 'subject',
'title' => ts('Mailing Subject'),
'type' => CRM_Utils_Type::T_STRING,
'operator' => 'like',
],
],
'order_bys' => [
'mailing_name' => [
'name' => 'name',
'title' => ts('Mailing Name'),
],
'mailing_subject' => [
'name' => 'subject',
'title' => ts('Mailing Subject'),
],
],
'grouping' => 'mailing-fields',
];
$this->_columns['civicrm_mailing'] = $this->getMailingColumns();

$this->_columns['civicrm_mailing_event_bounce'] = [
'dao' => 'CRM_Mailing_DAO_Mailing',
Expand All @@ -138,6 +40,8 @@ public function __construct() {
],
'time_stamp' => [
'title' => ts('Bounce Date'),
'operatorType' => CRM_Report_Form::OP_DATE,
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
],
],
'filters' => [
Expand Down Expand Up @@ -303,9 +207,6 @@ public static function formRule($fields, $files, $self) {
public function from() {
$this->_from = "
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
// LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
// ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
// {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";

$this->_from .= "
INNER JOIN civicrm_mailing_event_queue
Expand Down Expand Up @@ -445,34 +346,12 @@ public function bounce_type() {
* Rows generated by SQL, with an array for each row.
*/
public function alterDisplay(&$rows) {

$config = CRM_Core_Config::Singleton();

parent::alterDisplay($rows);

$entryFound = FALSE;
foreach ($rows as $rowNum => $row) {

// If the email address has been deleted
if (array_key_exists('civicrm_email_email', $row)) {
if (empty($rows[$rowNum]['civicrm_email_email'])) {
$rows[$rowNum]['civicrm_email_email'] = '<del>' . ts('Email address deleted.') . '</del>';
}
$entryFound = TRUE;
}

// make count columns point to detail report
// convert display name to links
if (array_key_exists('civicrm_contact_sort_name', $row) &&
array_key_exists('civicrm_contact_id', $row)
) {
$url = CRM_Utils_System::url('civicrm/contact/view',
'reset=1&cid=' . $row['civicrm_contact_id'],
$this->_absoluteUrl
);
$rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
$rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
$entryFound = TRUE;
}

// Handle on_hold boolean display
if (array_key_exists('civicrm_email_on_hold', $row)) {
$rows[$rowNum]['civicrm_email_on_hold'] = (!empty($row['civicrm_email_on_hold'])) ? 'Yes' : 'No';
Expand Down
Loading