From: Kurund Jalmi Date: Mon, 22 Apr 2013 01:44:48 +0000 (-0700) Subject: worked on CRM-12357, basic mailing tab is now functional to display contact mailings X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=553f116af2e902632ab20d3017d61ac3c57449b3;p=civicrm-core.git worked on CRM-12357, basic mailing tab is now functional to display contact mailings --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index bf15c462ed..23a15b594d 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2367,9 +2367,12 @@ AND civicrm_openid.is_primary = 1"; return CRM_Activity_BAO_Activity::getActivitiesCount($input); case 'mailing': - //FIX ME: calculate count + $params = array( + 'contact_id' => $contactId, + 'admin' => FALSE, + ); + return CRM_Mailing_BAO_Mailing::getContactMailingsCount($params); - return; default: $custom = explode('_', $component); if ($custom['0'] = 'custom') { diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 515bf97417..2231ca62f9 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1600,7 +1600,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $job->scheduled_date = $params['scheduled_date']; $job->save(); // Populate the recipients. - $mailing->getRecipients($job->id, $mailing->id, NULL, NULL, true, false); + $mailing->getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE); } return $mailing; @@ -2149,7 +2149,7 @@ ORDER BY civicrm_email.is_bulkmail DESC // get all the groups that this user can access // if they dont have universal access - $groups = CRM_Core_PseudoConstant::group(null, false); + $groups = CRM_Core_PseudoConstant::group(NULL, FALSE); if (!empty($groups)) { $groupIDs = implode(',', array_keys($groups)); $selectClause = ($count) ? 'COUNT( DISTINCT m.id) as count' : 'DISTINCT( m.id ) as id'; @@ -2729,5 +2729,80 @@ AND m.id = %1 $params = array( 1 => array( $mid, 'Integer' ) ); return CRM_Core_DAO::singleValueQuery($sql, $params); } + + /** + * This function is a wrapper for ajax activity selector + * + * @param array $params associated array for params record id. + * + * @return array $contactActivities associated array of contact activities + * @access public + */ + public static function getContactMailingSelector(&$params) { + // format the params + $params['offset'] = ($params['page'] - 1) * $params['rp']; + $params['rowCount'] = $params['rp']; + $params['sort'] = CRM_Utils_Array::value('sortBy', $params); + $params['caseId'] = NULL; + $context = CRM_Utils_Array::value('context', $params); + + // get contact mailings + $mailings = CRM_Mailing_BAO_Mailing::getContactMailings($params); + + // add total + $params['total'] = CRM_Mailing_BAO_Mailing::getContactMailingsCount($params); + + // 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]['mailing_creator'] = CRM_Utils_System::href( + $values['creator_name'], + 'civicrm/contact/view', + "reset=1&cid={$values['creator_id']}"); + + $contactMailings[$mailingId]['links'] = CRM_Utils_System::href( + ts('View Mailing'), + 'civicrm/mailing/view', + "reset=1&id={$values['mailing_id']}"); + } + + return $contactMailings; + } + + /** + * Function to retrieve contact mailing + * + * @param array $params associated array + * + * @return array of mailings for a contact + * + * @static + * @access public + */ + static public function getContactMailings(&$params) { + $params['version'] = 3; + $result = civicrm_api('MailingContact', 'get', $params); + return $result['values']; + } + + /** + * Function to retrieve contact mailing count + * + * @param array $params associated array + * + * @return int count of mailings for a contact + * + * @static + * @access public + */ + static public function getContactMailingsCount(&$params) { + //FIX ME: need to implement getcount api for MailingContact + $params['version'] = 3; + $result = civicrm_api('MailingContact', 'get', $params); + return count($result['values']); + } } diff --git a/CRM/Mailing/Page/AJAX.php b/CRM/Mailing/Page/AJAX.php index cf023f2837..3032533d66 100644 --- a/CRM/Mailing/Page/AJAX.php +++ b/CRM/Mailing/Page/AJAX.php @@ -59,5 +59,46 @@ class CRM_Mailing_Page_AJAX { echo json_encode($messages); CRM_Utils_System::civiExit(); } + + /** + * Function to retrieve contact mailings + */ + function getContactMailings() { + $contactID = CRM_Utils_Type::escape($_GET['contact_id'], 'Integer'); + //$context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String'); + + $sortMapper = array( + 0 => 'subject', 1 => 'mailing_creator', 2 => 'start_date', 3 => 'links', + ); + + $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'; + + $params = $_POST; + if ($sort && $sortOrder) { + $params['sortBy'] = $sort . ' ' . $sortOrder; + } + + $params['page'] = ($offset / $rowCount) + 1; + $params['rp'] = $rowCount; + + $params['contact_id'] = $contactID; + $params['context'] = $context; + + // get the contact mailings + $mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params); + + $iFilteredTotal = $iTotal = $params['total']; + $selectorElements = array( + 'subject', 'mailing_creator', + 'start_date', 'links', + ); + + echo CRM_Utils_JSON::encodeDataTableSelector($mailings, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); + CRM_Utils_System::civiExit(); + } } diff --git a/CRM/Mailing/xml/Menu/Mailing.xml b/CRM/Mailing/xml/Menu/Mailing.xml index 52f972474e..7b63894b6b 100644 --- a/CRM/Mailing/xml/Menu/Mailing.xml +++ b/CRM/Mailing/xml/Menu/Mailing.xml @@ -2,211 +2,216 @@ - civicrm/mailing - CiviMail - CRM_Mailing_Page_Browse - access CiviMail;create mailings - 1 - 600 - CiviMail - - - civicrm/admin/mail - Mailer Settings - CRM_Admin_Form_Setting_Mail - Configure spool period, throttling and other mailer settings. - access CiviMail - CiviMail - admin/small/07.png - 400 - - - civicrm/admin/component - Headers, Footers, and Automated Messages - CRM_Mailing_Page_Component - Configure the header and footer used for mailings. Customize the content of automated Subscribe, Unsubscribe, Resubscribe and Opt-out messages. - access CiviMail - CiviMail - admin/small/Profile.png - 410 - - - civicrm/admin/options/from_email - From Email Addresses - List of Email Addresses which can be used when sending emails to contacts. - group=from_email_address - CRM_Admin_Page_Options - CiviMail - admin/small/title.png - 415 - - - civicrm/admin/mailSettings - Mail Accounts - CRM_Admin_Page_MailSettings - Configure email account setting. - access CiviMail - CiviMail - admin/small/07.png - 420 - - - civicrm/admin/setting/preferences/mailing - CiviMail Component Settings - CRM_Admin_Form_Preferences_Mailing - Configure global CiviMail behaviors. - access CiviMail,administer CiviCRM - CiviMail - 430 - - - civicrm/mailing/send - New Mailing - CRM_Mailing_Controller_Send - access CiviMail;create mailings;schedule mailings - 1 - 610 - - - civicrm/mailing/browse/scheduled - Scheduled and Sent Mailings - scheduled=true - CRM_Mailing_Page_Browse - access CiviMail;approve mailings;create mailings;schedule mailings - 1 - 620 - - - civicrm/mailing/browse/unscheduled - Draft and Unscheduled Mailings - scheduled=false - CRM_Mailing_Page_Browse - access CiviMail;create mailings;schedule mailings - 1 - 620 - - - civicrm/mailing/browse/archived - Archived Mailings - CRM_Mailing_Page_Browse - access CiviMail;create mailings - 1 - 625 - - - civicrm/mailing/component - Headers, Footers, and Automated Messages - CRM_Mailing_Page_Component - administer CiviCRM - 1 - 630 - - - civicrm/mailing/unsubscribe - Unsubscribe - CRM_Mailing_Page_Unsubscribe - access CiviMail subscribe/unsubscribe pages - true - 640 - + civicrm/mailing + CiviMail + CRM_Mailing_Page_Browse + access CiviMail;create mailings + 1 + 600 + CiviMail + + + civicrm/admin/mail + Mailer Settings + CRM_Admin_Form_Setting_Mail + Configure spool period, throttling and other mailer settings. + access CiviMail + CiviMail + admin/small/07.png + 400 + + + civicrm/admin/component + Headers, Footers, and Automated Messages + CRM_Mailing_Page_Component + Configure the header and footer used for mailings. Customize the content of automated Subscribe, Unsubscribe, Resubscribe and Opt-out messages. + access CiviMail + CiviMail + admin/small/Profile.png + 410 + + + civicrm/admin/options/from_email + From Email Addresses + List of Email Addresses which can be used when sending emails to contacts. + group=from_email_address + CRM_Admin_Page_Options + CiviMail + admin/small/title.png + 415 + + + civicrm/admin/mailSettings + Mail Accounts + CRM_Admin_Page_MailSettings + Configure email account setting. + access CiviMail + CiviMail + admin/small/07.png + 420 + + + civicrm/admin/setting/preferences/mailing + CiviMail Component Settings + CRM_Admin_Form_Preferences_Mailing + Configure global CiviMail behaviors. + access CiviMail,administer CiviCRM + CiviMail + 430 + + + civicrm/mailing/send + New Mailing + CRM_Mailing_Controller_Send + access CiviMail;create mailings;schedule mailings + 1 + 610 + + + civicrm/mailing/browse/scheduled + Scheduled and Sent Mailings + scheduled=true + CRM_Mailing_Page_Browse + access CiviMail;approve mailings;create mailings;schedule mailings + 1 + 620 + + + civicrm/mailing/browse/unscheduled + Draft and Unscheduled Mailings + scheduled=false + CRM_Mailing_Page_Browse + access CiviMail;create mailings;schedule mailings + 1 + 620 + + + civicrm/mailing/browse/archived + Archived Mailings + CRM_Mailing_Page_Browse + access CiviMail;create mailings + 1 + 625 + + + civicrm/mailing/component + Headers, Footers, and Automated Messages + CRM_Mailing_Page_Component + administer CiviCRM + 1 + 630 + + + civicrm/mailing/unsubscribe + Unsubscribe + CRM_Mailing_Page_Unsubscribe + access CiviMail subscribe/unsubscribe pages + true + 640 + + + civicrm/mailing/resubscribe + Resubscribe + CRM_Mailing_Page_Resubscribe + access CiviMail subscribe/unsubscribe pages + true + 645 + - civicrm/mailing/resubscribe - Resubscribe - CRM_Mailing_Page_Resubscribe - access CiviMail subscribe/unsubscribe pages - true - 645 - + civicrm/mailing/optout + Optout + CRM_Mailing_Page_Optout + access CiviMail subscribe/unsubscribe pages + true + 650 + - civicrm/mailing/optout - Optout - CRM_Mailing_Page_Optout - access CiviMail subscribe/unsubscribe pages - true - 650 - + civicrm/mailing/confirm + Confirm + CRM_Mailing_Page_Confirm + access CiviMail subscribe/unsubscribe pages + true + 660 + - civicrm/mailing/confirm - Confirm - CRM_Mailing_Page_Confirm - access CiviMail subscribe/unsubscribe pages - true - 660 - + civicrm/mailing/subscribe + Subscribe + CRM_Mailing_Form_Subscribe + access CiviMail subscribe/unsubscribe pages + true + 660 + - civicrm/mailing/subscribe - Subscribe - CRM_Mailing_Form_Subscribe - access CiviMail subscribe/unsubscribe pages - true - 660 + civicrm/mailing/preview + Preview Mailing + CRM_Mailing_Page_Preview + access CiviMail;approve mailings;create mailings;schedule mailings + 670 - civicrm/mailing/preview - Preview Mailing - CRM_Mailing_Page_Preview - access CiviMail;approve mailings;create mailings;schedule mailings - 670 + civicrm/mailing/report + Mailing Report + CRM_Mailing_Page_Report + access CiviMail;create mailings + mid=%%mid%% + 680 - civicrm/mailing/report - Mailing Report - CRM_Mailing_Page_Report - access CiviMail;create mailings - mid=%%mid%% - 680 + civicrm/mailing/forward + Forward Mailing + CRM_Mailing_Form_ForwardMailing + access CiviMail subscribe/unsubscribe pages + true + 685 - civicrm/mailing/forward - Forward Mailing - CRM_Mailing_Form_ForwardMailing - access CiviMail subscribe/unsubscribe pages - true - 685 + civicrm/mailing/queue + Sending Mail + CRM_Mailing_Page_Browse + access CiviMail + 690 - civicrm/mailing/queue - Sending Mail - CRM_Mailing_Page_Browse - access CiviMail - 690 + civicrm/mailing/report/event + Mailing Event + CRM_Mailing_Page_Event + access CiviMail + 695 - civicrm/mailing/report/event - Mailing Event - CRM_Mailing_Page_Event - access CiviMail - 695 + civicrm/ajax/template + CRM_Mailing_Page_AJAX::template + access CiviCRM - civicrm/ajax/template - CRM_Mailing_Page_AJAX::template - access CiviCRM + civicrm/mailing/schedule + Schedule Mailing + CRM_Mailing_Form_Schedule + schedule mailings + 700 - civicrm/mailing/schedule - Schedule Mailing - CRM_Mailing_Form_Schedule - schedule mailings - 700 + civicrm/mailing/view + View Mailing + CRM_Mailing_Page_View + view public CiviMail content;access CiviMail;approve mailings + true + 800 - civicrm/mailing/view - View Mailing - CRM_Mailing_Page_View - view public CiviMail content;access CiviMail;approve mailings - true - 800 + civicrm/mailing/approve + Approve Mailing + CRM_Mailing_Form_Approve + approve mailings + 850 - civicrm/mailing/approve - Approve Mailing - CRM_Mailing_Form_Approve - approve mailings - 850 + civicrm/contact/view/mailing + CRM_Mailing_Page_Tab - civicrm/contact/view/mailing - CRM_Mailing_Page_Tab + civicrm/ajax/contactmailing + CRM_Mailing_Page_AJAX::getContactMailings + access CiviCRM diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 13d7322425..7ca056c27f 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -208,7 +208,7 @@ class CRM_Utils_System { return $config->userSystem->url($path, $query, $absolute, $fragment, $htmlize, $frontend, $forceBackend); } - function href($text, $path = NULL, $query = NULL, $absolute = TRUE, + static function href($text, $path = NULL, $query = NULL, $absolute = TRUE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE ) { $url = self::url($path, $query, $absolute, $fragment, $htmlize, $frontend, $forceBackend); diff --git a/templates/CRM/Mailing/Page/Tab.tpl b/templates/CRM/Mailing/Page/Tab.tpl index 0d06a3d113..bf60765b41 100644 --- a/templates/CRM/Mailing/Page/Tab.tpl +++ b/templates/CRM/Mailing/Page/Tab.tpl @@ -32,7 +32,6 @@ {ts}Created By{/ts} {ts}Date{/ts}   -   @@ -46,14 +45,13 @@ }); function buildMailingContact() { - oTable.fnDestroy(); var columns = ''; - var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/rest" h=0 q="entity=MailingContact&action=get&sequential=1&json=1&contact_id=$contactId"}'{literal}; + var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/contactmailing" h=0 q="contact_id=$contactId"}'{literal}; var ZeroRecordText = {/literal}'{ts escape="js"}No mailings found{/ts}.'{literal}; - oTable = cj('#mailing-contact-selector').dataTable({ + oTable = cj('#contact-mailing-selector').dataTable({ "bFilter" : false, "bAutoWidth" : false, "aaSorting" : [], @@ -61,8 +59,7 @@ function buildMailingContact() { {sClass:'crm-mailing-contact-subject'}, {sClass:'crm-mailing-contact_created'}, {sClass:'crm-mailing-contact-date'}, - {sClass:'crm-mailing-contact-links', bSortable:false}, - {sClass:'hiddenElement', bSortable:false} + {sClass:'crm-mailing-contact-links', bSortable:false} ], "bProcessing": true, "sPaginationType": "full_numbers", @@ -85,22 +82,6 @@ function buildMailingContact() { "sNext": {/literal}"{ts escape='js'}Next{/ts}"{literal}, "sLast": {/literal}"{ts escape='js'}Last{/ts}"{literal} } - }, - "fnDrawCallback": function() { setSelectorClass(); }, - "fnServerData": function ( sSource, aoData, fnCallback ) { - aoData.push( {name:'contact_id', value: {/literal}{$contactId}{literal}}, - {name:'admin', value: {/literal}'{$admin}'{literal}} - ); - - cj.ajax( { - "dataType": 'json', - "type": "POST", - "url": sSource, - "data": aoData, - "success": fnCallxback, - // CRM-10244 - "dataFilter": function(data, type) { return data.replace(/[\n\v\t]/g, " "); } - }); } }); }