From c310d8f4fbf284674d72c327ac29672abacdcf22 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 23 Oct 2014 11:55:07 -0400 Subject: [PATCH] communications: Add email preferences. * CRM/Memberdashboard/Page/Communications.php (CRM_Memberdashboard_Page_Communications) [contactId, loadContact, isPOST, postProcess): New methods. [run]: Disable group editing for now. Add 'contact' and 'mailFormats' template variables. * templates/CRM/Memberdashboard/Page/Communications.tpl: Add email preferences form. --- CRM/Memberdashboard/Page/Communications.php | 36 ++++++++++++++++++- .../Memberdashboard/Page/Communications.tpl | 24 +++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CRM/Memberdashboard/Page/Communications.php b/CRM/Memberdashboard/Page/Communications.php index 8119172..9febb95 100644 --- a/CRM/Memberdashboard/Page/Communications.php +++ b/CRM/Memberdashboard/Page/Communications.php @@ -23,12 +23,46 @@ require_once 'CRM/Core/Page.php'; class CRM_Memberdashboard_Page_Communications extends CRM_Core_Page { + function contactId() { + return CRM_Core_Session::singleton()->get('userID'); + } + + function loadContact() { + return civicrm_api3('contact', 'getsingle', array( + 'id' => $this->contactId() + )); + } + + function isPOST() { + return $_SERVER['REQUEST_METHOD'] == 'POST'; + } + + function postProcess($params) { + // Update member's preferred mail format (plain text, HTML) + $key = 'preferred_mail_format'; + $value = $params[$key]; + + civicrm_api3('contact', 'create', array( + 'id' => $this->contactId(), + $key => $value + )); + } + function run() { + // Handle POST requests to update email preferences. + if($this->isPOST()) { + $this->postProcess($_POST); + } + $helper = new CRM_Memberdashboard_Page_ComponentHelper(array('CiviEvent')); $helper->run(); $this->assign('dashboardElements', $helper->buildDashboardElements()); + $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact(); - $gContact->run(); + $gContact->browse(); + + $this->assign('contact', $this->loadContact()); + $this->assign('mailFormats', array('Both', 'HTML', 'Text')); CRM_Utils_System::setTitle('Communications'); diff --git a/templates/CRM/Memberdashboard/Page/Communications.tpl b/templates/CRM/Memberdashboard/Page/Communications.tpl index 9a12250..b33320e 100644 --- a/templates/CRM/Memberdashboard/Page/Communications.tpl +++ b/templates/CRM/Memberdashboard/Page/Communications.tpl @@ -26,5 +26,29 @@ {include file="CRM/Contact/Page/View/UserDashBoard/GroupContact.tpl"} +
+
+ {ts}Email Preferences{/ts} +
+ +
+
+ + + +
+
+
+ {include file="CRM/Memberdashboard/Page/DashboardElement.tpl" element=$dashboardElements.CiviEvent } -- 2.25.1