separation of concerns - move uf specific code to uf classes
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 21 May 2014 08:06:28 +0000 (20:06 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 21 May 2014 09:37:27 +0000 (21:37 +1200)
CRM/Contact/Page/View.php
CRM/Contact/Page/View/Summary.php
CRM/Utils/System/Base.php
CRM/Utils/System/DrupalBase.php
CRM/Utils/System/Joomla.php
CRM/Utils/System/WordPress.php

index 0a8dcaff0943a3c73af063de460a88f85ef174ec..82bc7cbdb71080ff30fafbce09cdeba97b2aa8a9 100644 (file)
@@ -311,6 +311,12 @@ class CRM_Contact_Page_View extends CRM_Core_Page {
     }
   }
 
+  /**
+   * @param $contactId
+   * @param bool $isDeleted
+   *
+   * @return string
+   */
   static function setTitle($contactId, $isDeleted = FALSE) {
     static $contactDetails;
     $displayName = $contactImage = NULL;
@@ -340,47 +346,19 @@ class CRM_Contact_Page_View extends CRM_Core_Page {
 
   /**
    * Add urls for display in the actions menu
+   * @param CRM_Core_Page $obj
+   * @param integer $cid
    */
   static function addUrls(&$obj, $cid) {
-    // TODO rewrite without so many hard-coded CMS bits; use abstractions like CRM_Core_Permission::check('cms:...') and CRM_Utils_System
+     $uid = CRM_Core_BAO_UFMatch::getUFId($cid);
 
-    $config = CRM_Core_Config::singleton();
-    $session = CRM_Core_Session::singleton();
-    $uid = CRM_Core_BAO_UFMatch::getUFId($cid);
-    $userRecordUrl = NULL;
     if ($uid) {
-      if ($config->userSystem->is_drupal == '1' &&
-        ($session->get('userID') == $cid || CRM_Core_Permission::checkAnyPerm(array('cms:administer users', 'cms:view user account')))
-      ) {
-        $userRecordUrl = CRM_Utils_System::url('user/' . $uid);
-      }
-      elseif ($config->userFramework == 'Joomla') {
-        $userRecordUrl = NULL;
-        // if logged in user is super user, then he can view other users joomla profile
-        if (JFactory::getUser()->authorise('core.admin')) {
-          $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
-        }
-        elseif ($session->get('userID') == $cid) {
-          $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
-        }
-      }
-      // For WordPress, provide link to user profile is contact belongs to logged in user OR user has administrator role
-      elseif ($config->userFramework == 'WordPress' &&
-        ($session->get('userID') == $cid || CRM_Core_Permission::checkAnyPerm(array('cms:administer users')))
-        ) {
-          $userRecordUrl = $config->userFrameworkBaseURL . "wp-admin/user-edit.php?user_id=" . $uid;
-      }
+      $userRecordUrl = CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($cid);
       $obj->assign('userRecordUrl', $userRecordUrl);
       $obj->assign('userRecordId', $uid);
     }
-    elseif (($config->userSystem->is_drupal == '1' && CRM_Core_Permission::check('administer users')) ||
-      ($config->userFramework == 'Joomla' &&
-        JFactory::getUser()->authorise('core.create', 'com_users')
-      )
-    ) {
-      $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd',
-        'reset=1&action=add&cid=' . $cid
-      );
+    elseif (CRM_Core_Config::singleton()->userSystem->checkPermissionAddUser()) {
+      $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $cid);
       $obj->assign('userAddUrl', $userAddUrl);
     }
 
index a8df6e947dec3c77b38db6578e7a61e751d9a000..ee94b0173a5c314abcca1b6582d9b8d4128ecdc0 100644 (file)
@@ -275,7 +275,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
       //for birthdate format with respect to birth format set
       $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
-    
+
     $defaults['external_identifier'] = $contact->external_identifier;
     $this->assign($defaults);
 
index aae668cd8c6705e7e7e984a7019cc9392bed9392..1aa78eb0bbc6f3b83bb81f27480f9d6ec31402ee 100644 (file)
@@ -295,5 +295,22 @@ abstract class CRM_Utils_System_Base {
     }
     return $this->getLoggedInUniqueIdentifier();
   }
+
+  /**
+   * Get Url to view user record
+   * @param integer $contactID Contact ID
+   *
+   * @return string
+   */
+  function getUserRecordUrl($contactID) {
+    return NULL;
+  }
+  /**
+   * Is the current user permitted to add a user
+   * @return bool
+   */
+  function checkPermissionAddUser() {
+    return FALSE;
+  }
 }
 
index b0cff3e7c64c46b89dbdc0ba75cc327ef3073c00..fd3523ccbf9a8be9a242da2fa36911d7e25e150d 100644 (file)
@@ -237,4 +237,27 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
   function permissionDenied() {
     drupal_access_denied();
   }
+
+  /**
+   * Get Url to view user record
+   * @param integer $contactID Contact ID
+   *
+   * @return string
+   */
+  function getUserRecordUrl($contactID) {
+    $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
+    if (CRM_Core_Session::singleton()->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm(array('cms:administer users', 'cms:view user account'))) {
+      return CRM_Utils_System::url('user/' . $uid);
+    };
+  }
+
+  /**
+   * Is the current user permitted to add a user
+   * @return bool
+   */
+  function checkPermissionAddUser() {
+    if (CRM_Core_Permission::check('administer users')) {
+      return TRUE;
+    }
+  }
 }
index c92dbe409302d61be3b4c440021c3656034584cf..e7d8a4765bdc4a431ad6704c4e4ce4b39b1a7ad6 100644 (file)
@@ -798,5 +798,33 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
     );
     return array($url, NULL, $siteRoot);
   }
+
+  /**
+   * Get Url to view user record
+   * @param integer $contactID Contact ID
+   *
+   * @return string
+   */
+  function getUserRecordUrl($contactID) {
+    $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
+    $userRecordUrl = NULL;
+    // if logged in user is super user, then he can view other users joomla profile
+    if (JFactory::getUser()->authorise('core.admin')) {
+      return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
+    }
+    elseif (CRM_Core_Session::singleton()->get('userID') == $contactID) {
+      return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
+    }
+  }
+
+  /**
+   * Is the current user permitted to add a user
+   * @return bool
+   */
+  function checkPermissionAddUser() {
+    if (JFactory::getUser()->authorise('core.create', 'com_users')) {
+      return TRUE;
+    }
+  }
 }
 
index d02ce668b1d02065c3e0e6e57247d5d59c60d9a9..78ad9f0d9239d79e087277c876b185043f752c19 100644 (file)
@@ -733,5 +733,18 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
   function getTimeZoneString() {
     return get_option('timezone_string');
   }
+
+  /**
+   * Get Url to view user record
+   * @param integer $contactID Contact ID
+   *
+   * @return string
+   */
+  function getUserRecordUrl($contactID) {
+    $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
+    if (CRM_Core_Session::singleton()->get('userID') == $contactID || CRM_Core_Permission::checkAnyPerm(array('cms:administer users'))) {
+      return CRM_Core_Config::singleton()->userFrameworkBaseURL . "wp-admin/user-edit.php?user_id=" . $uid;
+    }
+  }
 }