Extract base page class.
authorDavid Thompson <davet@gnu.org>
Thu, 23 Oct 2014 16:10:51 +0000 (12:10 -0400)
committerDavid Thompson <davet@gnu.org>
Thu, 23 Oct 2014 16:10:51 +0000 (12:10 -0400)
* CRM/Memberdashboard/Page.php: New file.
* CRM/Memberdashboard/Page/Communications.php
  (CRM_Memberdashboard_Page_Communications): Inherit from base page.
  [contactId, loadContact, isPOST]: Remove methods.
  [run]: Use pre-loaded contact object.
* CRM/Memberdashboard/Page/MemberDashboard.php
  (CRM_Memberdashboard_Page_MemberDashboard): Inherit from base page.
  [$contact]: Remove variable.
  [__construct, loadContact]: Remove methods.

CRM/Memberdashboard/Page.php [new file with mode: 0644]
CRM/Memberdashboard/Page/Communications.php
CRM/Memberdashboard/Page/MemberDashboard.php

diff --git a/CRM/Memberdashboard/Page.php b/CRM/Memberdashboard/Page.php
new file mode 100644 (file)
index 0000000..b8ba059
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * FSF Member Dashboard
+ * Copyright © 2014 Free Software Foundation, Inc.
+ *
+ * This file is a part of FSF Member Dashboard.
+ *
+ * FSF Member Dashboard is free software; you can copy, modify, and
+ * distribute it under the terms of the GNU Affero General Public
+ * License Version 3, 19 November 2007 and the CiviCRM Licensing
+ * Exception.
+ *
+ * FSF Member Dashboard is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FSF Member Dashboard.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+require_once 'CRM/Core/Page.php';
+
+class CRM_Memberdashboard_Page extends CRM_Core_Page {
+  public $contact = NULL;
+
+  function __construct() {
+    parent::__construct();
+
+    $this->contact = $this->loadContact();
+  }
+
+  function contactId() {
+    return CRM_Core_Session::singleton()->get('userID');
+  }
+
+  /**
+   * Return a contact object for the current user.
+   *
+   * @return CRM_Contact
+   */
+  function loadContact() {
+    return civicrm_api3('contact', 'getsingle', array(
+      'id' => $this->contactId()
+    ));
+  }
+
+  function isPOST() {
+    return $_SERVER['REQUEST_METHOD'] == 'POST';
+  }
+}
index 9febb951ebd57bbbdc6156a37dc786f7a6d14fa0..36a5439801d04d120d9431a057ddb4096d2b8253 100644 (file)
 
 require_once 'CRM/Core/Page.php';
 
 
 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';
-  }
-
+class CRM_Memberdashboard_Page_Communications extends CRM_Memberdashboard_Page {
   function postProcess($params) {
     // Update member's preferred mail format (plain text, HTML)
     $key = 'preferred_mail_format';
     $value = $params[$key];
 
     civicrm_api3('contact', 'create', array(
   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(),
+      'id' => $this->contact['id'],
       $key => $value
     ));
   }
       $key => $value
     ));
   }
@@ -61,7 +47,7 @@ class CRM_Memberdashboard_Page_Communications extends CRM_Core_Page {
     $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
     $gContact->browse();
 
     $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
     $gContact->browse();
 
-    $this->assign('contact', $this->loadContact());
+    $this->assign('contact', $this->contact);
     $this->assign('mailFormats', array('Both', 'HTML', 'Text'));
 
     CRM_Utils_System::setTitle('Communications');
     $this->assign('mailFormats', array('Both', 'HTML', 'Text'));
 
     CRM_Utils_System::setTitle('Communications');
index 5029510df83649238166e06f0279dd6722ba5b03..2d2185ea94a542184591005e56eea0b2e75f3cda 100644 (file)
 
 require_once 'CRM/Core/Page.php';
 
 
 require_once 'CRM/Core/Page.php';
 
-class CRM_Memberdashboard_Page_MemberDashboard extends CRM_Core_Page {
-  public $contact = NULL;
-
-  function __construct() {
-    parent::__construct();
-
-    $this->contact = $this->loadContact();
-  }
-
-  /**
-   * Return a contact object for the current user.
-   *
-   * @return CRM_Contact
-   */
-  function loadContact() {
-    return civicrm_api3('contact', 'getsingle', array(
-      'id' => CRM_Core_Session::singleton()->get('userID')
-    ));
-  }
-
+class CRM_Memberdashboard_Page_MemberDashboard extends CRM_Memberdashboard_Page {
   /**
    * Return the personalized title for the page.
    *
   /**
    * Return the personalized title for the page.
    *