where('subjid', $userId); } if ($pref->count() > 0) { $pref->valstr = $value; } else { if ($isUserValue) { throw new Exception("Preference {$key} not found for user {$userId}."); } throw new Exception("Preference {$key} not found."); } } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); Log::info('Database error: ' . $e->getMessage()); } } private function getValue($key, $isUserValue = false, $forceDefault = false) { try { $userId = Auth::id(); if ($isUserValue && is_null($userId)) { throw new Exception("User id can't be null for a user preference {$key}."); } $pref = Preference::where('key', $key); if ($isUserValue) { $pref = $pref->where('subjid', $userId); } if ($pref->count() > 0) { return $pref->first()->valstr; } else { if ($isUserValue) { throw new Exception("Preference {$key} not found for user {$userId}."); } throw new Exception("Preference {$key} not found."); } } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); Log::info('Database error: ' . $e->getMessage()); die(); } } public function getDefaultTimeZone() { return config('app.timezone'); } public static function setUserTimezone($timezone = null) { self::setValue('user_timezone', $timezone, true); } public static function getUserTimezone() { $timezone = self::getValue('user_timezone', true); if (!$timezone) { return self::getDefaultTimezone(); } return $timezone; } // Always attempts to returns the current user's personal timezone setting public static function getTimezone() { $userId = Auth::id(); if (!is_null($userId)) { return self::getUserTimezone(); } return self::getDefaultTimezone(); } }