CRM-9683 add functions to set timezone in mysql based on UF, note that this is not...
authorEileen <eileen@fuzion.co.nz>
Thu, 24 Oct 2013 07:04:25 +0000 (20:04 +1300)
committerEileen <eileen@fuzion.co.nz>
Thu, 24 Oct 2013 07:04:25 +0000 (20:04 +1300)
----------------------------------------
* CRM-9683: Implement timezone support for CiviMail
  http://issues.civicrm.org/jira/browse/CRM-9683

CRM/Utils/System/Base.php
CRM/Utils/System/Drupal.php
CRM/Utils/System/Drupal6.php

index 93cd88b0c3f7e49b9549dc0d30cd7c125658bde4..e9acb7df1a1e9e58a8b0969715213585f344cb13 100644 (file)
@@ -163,5 +163,23 @@ abstract class CRM_Utils_System_Base {
    */
   function userLoginFinalize($params = array()){
   }
+
+  /**
+   * Set timezone in mysql so that timestamp fields show the correct time
+   */
+  function setMySQLTimeZone(){
+    $timeZoneOffset = $this->getTimeZoneOffset();
+    if($timeZoneOffset){
+      $sql = "SET time_zone = '$timeZoneOffset'";
+      CRM_Core_DAO::executequery($sql);
+    }
+  }
+
+  /**
+   * Get timezone from CMS
+   * @return boolean|string
+   */
+  function getTimeZoneOffset(){
+  }
 }
 
index 3ff008b6b7ca9c81100b0b53c61baddac56f0ff6..fda57c0385727286cb67e173ed0b285bf2121983 100644 (file)
@@ -1065,6 +1065,32 @@ AND    u.status = 1
     }
   }
 
+  /**
+   * Get timezone from Drupal
+   * @return boolean|string
+   */
+  function getTimeZoneOffset(){
+    global $user;
+    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
+      $timezone = $user->timezone;
+    } else {
+      $timezone = variable_get('date_default_timezone', null);
+    }
+    $tzObj = new DateTimeZone($timezone);
+    $dateTime = new DateTime("now", $tzObj);
+    $tz = $tzObj->getOffset($dateTime);
+
+    if(empty($tz)){
+      return false;
+    }
+
+    $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60 );
+
+    if($timeZoneOffset > 0){
+      $timeZoneOffset = '+' . $timeZoneOffset;
+    }
+    return $timeZoneOffset;
+  }
   /**
    * Reset any system caches that may be required for proper CiviCRM
    * integration.
index 23fca40ec79ebb0cc2fef894d126f9fa28f3a80c..8ceba7259d33b1d01b0eb1ee7ba08ed770b37765 100644 (file)
@@ -180,7 +180,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase {
     if (!$row) {
       return;
     }
+
     $user = NULL;
 
     if (!empty($row)) {
@@ -1016,6 +1016,29 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase {
       og_delete_subscription( $ogID, $drupalID );
   }
 
+  /**
+   * Get timezone from Drupal
+   * @return boolean|string
+   */
+  function getTimeZoneOffset(){
+    global $user;
+    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
+      $timezone = $user->timezone;
+    } else {
+      $timezone = variable_get('date_default_timezone', null);
+    }
+    if(empty($timezone)){
+      return false;
+    }
+    $hour = $user->timezone / 3600;
+    $timeZoneOffset = sprintf("%02d:%02d", $timezone / 3600, ($timezone/60)%60 );
+    if($timeZoneOffset > 0){
+      $timeZoneOffset = '+' . $timeZoneOffset;
+    }
+    return $timeZoneOffset;
+  }
+
+
   /**
    * Reset any system caches that may be required for proper CiviCRM
    * integration.