communications: Add email preferences.
authorDavid Thompson <davet@gnu.org>
Thu, 23 Oct 2014 15:55:07 +0000 (11:55 -0400)
committerDavid Thompson <davet@gnu.org>
Thu, 23 Oct 2014 15:55:07 +0000 (11:55 -0400)
* 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
templates/CRM/Memberdashboard/Page/Communications.tpl

index 8119172f873770aa40e46003de2fd0fb7deb06d0..9febb951ebd57bbbdc6156a37dc786f7a6d14fa0 100644 (file)
 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');
 
index 9a122508caf991dcbc307159b2226d1e81d3fbe1..b33320e5f6f4048b0022332f2b1eb9918f363f72 100644 (file)
   {include file="CRM/Contact/Page/View/UserDashBoard/GroupContact.tpl"}
 </div>
 
+<div>
+  <div class="header-dark">
+    {ts}Email Preferences{/ts}
+  </div>
+
+  <form method="post" action="{crmURL p='/civicrm/member-dashboard/communications'}">
+    <div class="form-item">
+      <label for="preferred_mail_format">Preferred Email Format</label>
+      <select name="preferred_mail_format">
+        {foreach from=$mailFormats item=format}
+          <option
+            {if $contact.preferred_mail_format eq $format}
+              selected="selected"
+            {/if}
+              value="{$format}">
+            {$format}
+          </option>
+        {/foreach}
+      </select>
+      <input type="submit" value="Save"/>
+    </div>
+  </form>
+</div>
+
 {include file="CRM/Memberdashboard/Page/DashboardElement.tpl"
          element=$dashboardElements.CiviEvent }