Comment block fixes
[civicrm-core.git] / CRM / Utils / System / Base.php
index 304b9bb8bd21d17daa4262f0e60faceac01cfffe..aeb5411a44dd63105815c910433d066b9936b201 100644 (file)
@@ -116,6 +116,8 @@ abstract class CRM_Utils_System_Base {
    * Determine the native ID of the CMS user
    *
    * @param $username
+   *
+   * @throws CRM_Core_Exception
    * @return int|NULL
    */
   function getUfId($username) {
@@ -147,6 +149,9 @@ abstract class CRM_Utils_System_Base {
 
   /**
    * Return default Site Settings
+   *
+   * @param $dir
+   *
    * @return array array
    * - $url, (Joomla - non admin url)
    * - $siteName,
@@ -201,7 +206,7 @@ abstract class CRM_Utils_System_Base {
         return false;
       }
 
-      $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60 );
+      $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, abs(($tz/60)%60));
 
       if($timeZoneOffset > 0){
         $timeZoneOffset = '+' . $timeZoneOffset;
@@ -215,7 +220,71 @@ abstract class CRM_Utils_System_Base {
    * @return string Timezone e.g. 'America/Los_Angeles'
    */
   function getTimeZoneString() {
-    return NULL;
+    return date_default_timezone_get();
+  }
+
+  /**
+   * Get Unique Identifier from UserFramework system (CMS)
+   * @param object $user object as described by the User Framework
+   * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
+   *
+   */
+  function getUniqueIdentifierFromUserObject($user) {}
+
+  /**
+   * Get User ID from UserFramework system (CMS)
+   * @param object $user object as described by the User Framework
+   * @return mixed <NULL, number>
+   *
+   */
+  function getUserIDFromUserObject($user) {}
+
+  /**
+   * Get currently logged in user uf id.
+   *
+   * @return int $userID logged in user uf id.
+   */
+  function getLoggedInUfID() {}
+
+  /**
+   * Get currently logged in user unique identifier - this tends to be the email address or user name.
+   *
+   * @return string $userID logged in user unique identifier
+   */
+  function getLoggedInUniqueIdentifier() {}
+
+  /**
+   * return a UFID (user account ID from the UserFramework / CMS system being based on the user object
+   * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
+   * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
+   * the function
+   *
+   * Note there is already a function getUFId which takes $username as a param - we could add $user
+   * as a second param to it but it seems messy - just overloading it because the name is taken
+   * @param object $user
+   * @return int $ufid - user ID of UF System
+   */
+  function getBestUFID($user = NULL) {
+    if($user) {
+      return $this->getUserIDFromUserObject($user);
+    }
+    return $this->getLoggedInUfID();
+  }
+
+  /**
+   * return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
+   * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
+   * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
+   * the function
+   *
+   * @param object $user
+   * @return string $uniqueIdentifier - unique identifier from the UF System
+   */
+  function getBestUFUniqueIdentifier($user = NULL) {
+    if($user) {
+      return $this->getUniqueIdentifierFromUserObject($user);
+    }
+    return $this->getLoggedInUniqueIdentifier();
   }
 }