summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Config.php38
-rw-r--r--app/Model/User.php26
-rw-r--r--app/Model/UserSession.php26
3 files changed, 56 insertions, 34 deletions
diff --git a/app/Model/Config.php b/app/Model/Config.php
index 1ee44a0e..e6d66734 100644
--- a/app/Model/Config.php
+++ b/app/Model/Config.php
@@ -25,24 +25,32 @@ class Config extends Base
* Get available timezones
*
* @access public
+ * @param boolean $prepend Prepend a default value
* @return array
*/
- public function getTimezones()
+ public function getTimezones($prepend = false)
{
$timezones = timezone_identifiers_list();
- return array_combine(array_values($timezones), $timezones);
+ $listing = array_combine(array_values($timezones), $timezones);
+
+ if ($prepend) {
+ return array('' => t('Application default')) + $listing;
+ }
+
+ return $listing;
}
/**
* Get available languages
*
* @access public
+ * @param boolean $prepend Prepend a default value
* @return array
*/
- public function getLanguages()
+ public function getLanguages($prepend = false)
{
// Sorted by value
- return array(
+ $languages = array(
'da_DK' => 'Dansk',
'de_DE' => 'Deutsch',
'en_US' => 'English',
@@ -59,6 +67,12 @@ class Config extends Base
'ja_JP' => '日本語',
'th_TH' => 'ไทย',
);
+
+ if ($prepend) {
+ return array('' => t('Application default')) + $languages;
+ }
+
+ return $languages;
}
/**
@@ -138,10 +152,11 @@ class Config extends Base
*/
public function setupTranslations()
{
- $language = $this->get('application_language', 'en_US');
-
- if ($language !== 'en_US') {
- Translator::load($language);
+ if ($this->userSession->isLogged() && ! empty($this->session['user']['language'])) {
+ Translator::load($this->session['user']['language']);
+ }
+ else {
+ Translator::load($this->get('application_language', 'en_US'));
}
}
@@ -152,7 +167,12 @@ class Config extends Base
*/
public function setupTimezone()
{
- date_default_timezone_set($this->get('application_timezone', 'UTC'));
+ if ($this->userSession->isLogged() && ! empty($this->session['user']['timezone'])) {
+ date_default_timezone_set($this->session['user']['timezone']);
+ }
+ else {
+ date_default_timezone_set($this->get('application_timezone', 'UTC'));
+ }
}
/**
diff --git a/app/Model/User.php b/app/Model/User.php
index 29def6d4..1bcc82b5 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -254,7 +254,7 @@ class User extends Base
// If the user is connected refresh his session
if (Session::isOpen() && $this->userSession->getId() == $values['id']) {
- $this->updateSession();
+ $this->userSession->refresh();
}
return $result;
@@ -295,30 +295,6 @@ class User extends Base
}
/**
- * Update user session information
- *
- * @access public
- * @param array $user User data
- */
- public function updateSession(array $user = array())
- {
- if (empty($user)) {
- $user = $this->getById($this->userSession->getId());
- }
-
- if (isset($user['password'])) {
- unset($user['password']);
- }
-
- $user['id'] = (int) $user['id'];
- $user['default_project_id'] = (int) $user['default_project_id'];
- $user['is_admin'] = (bool) $user['is_admin'];
- $user['is_ldap_user'] = (bool) $user['is_ldap_user'];
-
- $this->session['user'] = $user;
- }
-
- /**
* Common validation rules
*
* @access private
diff --git a/app/Model/UserSession.php b/app/Model/UserSession.php
index c27b3743..6d9a2ebc 100644
--- a/app/Model/UserSession.php
+++ b/app/Model/UserSession.php
@@ -2,6 +2,8 @@
namespace Model;
+use Core\Translator;
+
/**
* User Session
*
@@ -11,6 +13,30 @@ namespace Model;
class UserSession extends Base
{
/**
+ * Update user session information
+ *
+ * @access public
+ * @param array $user User data
+ */
+ public function refresh(array $user = array())
+ {
+ if (empty($user)) {
+ $user = $this->user->getById($this->userSession->getId());
+ }
+
+ if (isset($user['password'])) {
+ unset($user['password']);
+ }
+
+ $user['id'] = (int) $user['id'];
+ $user['default_project_id'] = (int) $user['default_project_id'];
+ $user['is_admin'] = (bool) $user['is_admin'];
+ $user['is_ldap_user'] = (bool) $user['is_ldap_user'];
+
+ $this->session['user'] = $user;
+ }
+
+ /**
* Return true if the logged user is admin
*
* @access public