From 41348d61726dd7abf83dc97f7bf1dbaac92f5b19 Mon Sep 17 00:00:00 2001 From: Joseph Lacey Date: Wed, 29 Apr 2015 20:43:10 -0600 Subject: [PATCH] CRM-16353 - Mailing DataTables refactoring ---------------------------------------- * CRM-16353: Upgrade datatables integration to use v2 api https://issues.civicrm.org/jira/browse/CRM-16353 --- CRM/Mailing/BAO/Mailing.php | 26 ++++++---- CRM/Mailing/Page/AJAX.php | 37 ++++---------- templates/CRM/Mailing/Page/Tab.tpl | 80 ++++++++---------------------- 3 files changed, 46 insertions(+), 97 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index a0c7b9176e..d7e259d66c 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -3046,18 +3046,17 @@ AND m.id = %1 // format params and add links $contactMailings = array(); foreach ($mailings as $mailingId => $values) { - $contactMailings[$mailingId]['subject'] = $values['subject']; - $contactMailings[$mailingId]['start_date'] = CRM_Utils_Date::customFormat($values['start_date']); - $contactMailings[$mailingId]['recipients'] = CRM_Utils_System::href(ts('(recipients)'), 'civicrm/mailing/report/event', - "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&event=queue&context=mailing"); - - $contactMailings[$mailingId]['mailing_creator'] = CRM_Utils_System::href( + $mailing = array(); + $mailing['subject'] = $values['subject']; + $mailing['creator_name'] = CRM_Utils_System::href( $values['creator_name'], 'civicrm/contact/view', "reset=1&cid={$values['creator_id']}"); - + $mailing['recipients'] = CRM_Utils_System::href(ts('(recipients)'), 'civicrm/mailing/report/event', + "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&event=queue&context=mailing"); + $mailing['start_date'] = CRM_Utils_Date::customFormat($values['start_date']); //CRM-12814 - $contactMailings[$mailingId]['openstats'] = "Opens: " . + $mailing['openstats'] = "Opens: " . CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0) . "
Clicks: " . CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0); @@ -3083,7 +3082,7 @@ AND m.id = %1 $mailingKey = $hash; } - $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink( + $mailing['links'] = CRM_Core_Action::formLink( $actionLinks, NULL, array( @@ -3097,9 +3096,16 @@ AND m.id = %1 'Mailing', $values['mailing_id'] ); + + array_push($contactMailings, $mailing); } - return $contactMailings; + $contactMailingsDT = array(); + $contactMailingsDT['data'] = $contactMailings; + $contactMailingsDT['recordsTotal'] = $params['total']; + $contactMailingsDT['recordsFiltered'] = $params['total']; + + return $contactMailingsDT; } /** diff --git a/CRM/Mailing/Page/AJAX.php b/CRM/Mailing/Page/AJAX.php index e49519e2e1..af2c5d274a 100644 --- a/CRM/Mailing/Page/AJAX.php +++ b/CRM/Mailing/Page/AJAX.php @@ -65,22 +65,17 @@ class CRM_Mailing_Page_AJAX { public static function getContactMailings() { $contactID = CRM_Utils_Type::escape($_GET['contact_id'], 'Integer'); - $sortMapper = array( - 0 => 'subject', - 1 => 'creator_name', - 2 => '', - 3 => 'start_date', - 4 => '', - 5 => 'links', - ); + $sortMapper = array(); + foreach ($_GET['columns'] as $key => $value) { + $sortMapper[$key] = $value['data']; + }; - $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); - $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; - $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; - $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; - $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; + $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; + $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; - $params = $_POST; + $params = $_GET; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } @@ -94,19 +89,7 @@ class CRM_Mailing_Page_AJAX { // get the contact mailings $mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params); - $iFilteredTotal = $iTotal = $params['total']; - $selectorElements = array( - 'subject', - 'mailing_creator', - 'recipients', - 'start_date', - 'openstats', - 'links', - ); - - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encodeDataTableSelector($mailings, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - CRM_Utils_System::civiExit(); + CRM_Utils_JSON::output($mailings); } } diff --git a/templates/CRM/Mailing/Page/Tab.tpl b/templates/CRM/Mailing/Page/Tab.tpl index b6e987fa43..3c817fdbf0 100644 --- a/templates/CRM/Mailing/Page/Tab.tpl +++ b/templates/CRM/Mailing/Page/Tab.tpl @@ -25,67 +25,27 @@ *}
- +
- - - - - - - - + + + + + + + +
{ts}Subject{/ts}{ts}Added By{/ts}{ts}Recipients{/ts}{ts}Date{/ts}{ts}Opens/ Clicks{/ts} 
{ts}Subject{/ts}{ts}Added By{/ts}{ts}Recipients{/ts}{ts}Date{/ts}{ts}Opens/ Clicks{/ts} 
-
-{literal} - -{/literal} + }); + })(CRM.$); + + {/literal} + -- 2.25.1