dev/core#4410: fixed timezone support for standalone
authorJaap Jansma <jaap.jansma@civicoop.org>
Tue, 5 Dec 2023 15:24:41 +0000 (16:24 +0100)
committerJaap Jansma <jaap.jansma@civicoop.org>
Tue, 5 Dec 2023 15:24:41 +0000 (16:24 +0100)
CRM/Utils/System/Standalone.php
ext/standaloneusers/CRM/Standaloneusers/BAO/User.php
ext/standaloneusers/CRM/Standaloneusers/DAO/User.php
ext/standaloneusers/ang/afformEditUserAccount.aff.html
ext/standaloneusers/xml/schema/CRM/Standaloneusers/User.xml

index b58bcbb3de9e8fe4ab7fe4f01612476091b1c86e..18f5b7bfc7e6933dd94d9c50d4802b09ff01f80e 100644 (file)
@@ -540,6 +540,13 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base {
    */
   public function getTimeZoneString() {
     $timezone = date_default_timezone_get();
+    $userId = Security::singleton()->getLoggedInUfID();
+    if ($userId) {
+      $user = Security::singleton()->loadUserByID($userId);
+      if ($user && !empty($user['timezone'])) {
+        $timezone = $user['timezone'];
+      }
+    }
     return $timezone;
   }
 
index 2522b9d91f77803bff906cd39beea75e0eb25288..b66d9c4bc0cde9e7c08ab10c05f87ad03e3ebf98 100644 (file)
@@ -33,4 +33,12 @@ class CRM_Standaloneusers_BAO_User extends CRM_Standaloneusers_DAO_User implemen
     return CRM_Core_I18n::uiLanguages(FALSE);
   }
 
+  public static function getTimeZones(): array {
+    $timeZones = [];
+    foreach (\DateTimeZone::listIdentifiers() as $timezoneId) {
+      $timeZones[$timezoneId] = $timezoneId;
+    }
+    return $timeZones;
+  }
+
 }
index f06e5c4a56ee855465b86906089f6d34a17f0e81..4cc9d4b60846362341df708b081ef053df84507d 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from standaloneusers/xml/schema/CRM/Standaloneusers/User.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:08b152ee7b327be88d44e2fce7c528ea)
+ * (GenCodeChecksum:889ac5b24fb6913d046bd2e52dcb65ea)
  */
 use CRM_Standaloneusers_ExtensionUtil as E;
 
@@ -505,7 +505,10 @@ class CRM_Standaloneusers_DAO_User extends CRM_Core_DAO {
           'bao' => 'CRM_Standaloneusers_DAO_User',
           'localizable' => 0,
           'html' => [
-            'type' => 'Text',
+            'type' => 'Select',
+          ],
+          'pseudoconstant' => [
+            'callback' => 'CRM_Standaloneusers_BAO_User::getTimeZones',
           ],
           'add' => NULL,
         ],
index 209509dde5da1945e21ffc01caea2ac63d94155b..ef1eb4be1935fffb7a4d26dbb9027e4231214610 100644 (file)
@@ -5,7 +5,7 @@
     <af-field name="username" />
     <af-field name="uf_name" />
     <af-field name="is_active" />
-    <af-field name="timezone" />
+    <af-field name="timezone" defn="{help_pre: ts('Set the timezone of the user. Date and times will be shown in this timezone. You can also leave it empty to use the default system timezone (which is a server setting).'), input_attrs: {placeholder: ts('Server default timezone')}}" />
     <af-field name="language" defn="{help_pre: ts('Set the user interface language of this user. You can also leave it empty to use the default system language.'), input_attrs: {placeholder: ts('System default language')}}" />
   </fieldset>
   <button class="af-button btn btn-primary" crm-icon="fa-check" ng-click="afform.submit()">Submit</button>
index 40132236800a3c816f3e22c7d5d0c2b0c9328302..1fc8cbcb35be823c5101d46d5c4460488f3453f8 100644 (file)
     <length>32</length>
     <required>false</required>
     <comment>User's timezone</comment>
+    <pseudoconstant>
+      <callback>CRM_Standaloneusers_BAO_User::getTimeZones</callback>
+    </pseudoconstant>
     <html>
-      <type>Text</type>
+      <type>Select</type>
     </html>
   </field>