Skip to content
Snippets Groups Projects
Commit 3e9eb72b authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Add database column to track user language preference. (#1367)

- Based on work by Ere Maijala for Finna.
- Enables automated communication to be sent to users in the appropriate language (forthcoming feature).
parent 149a17d1
No related merge requests found
...@@ -7,3 +7,6 @@ ALTER TABLE "user" ...@@ -7,3 +7,6 @@ ALTER TABLE "user"
ALTER TABLE "user" ALTER TABLE "user"
ADD COLUMN user_provided_email boolean NOT NULL DEFAULT '0'; ADD COLUMN user_provided_email boolean NOT NULL DEFAULT '0';
ALTER TABLE "user"
ADD COLUMN last_language varchar(30) NOT NULL DEFAULT '';
...@@ -218,6 +218,7 @@ CREATE TABLE `user` ( ...@@ -218,6 +218,7 @@ CREATE TABLE `user` (
`verify_hash` varchar(42) NOT NULL DEFAULT '', `verify_hash` varchar(42) NOT NULL DEFAULT '',
`last_login` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `last_login` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`auth_method` varchar(50) DEFAULT NULL, `auth_method` varchar(50) DEFAULT NULL,
`last_language` varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`), UNIQUE KEY `username` (`username`),
UNIQUE KEY `cat_id` (`cat_id`) UNIQUE KEY `cat_id` (`cat_id`)
......
...@@ -144,6 +144,7 @@ created timestamp NOT NULL DEFAULT '1970-01-01 00:00:00', ...@@ -144,6 +144,7 @@ created timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
verify_hash varchar(42) NOT NULL DEFAULT '', verify_hash varchar(42) NOT NULL DEFAULT '',
last_login timestamp NOT NULL DEFAULT '1970-01-01 00:00:00', last_login timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
auth_method varchar(50) DEFAULT NULL, auth_method varchar(50) DEFAULT NULL,
last_language varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE (username), UNIQUE (username),
UNIQUE (cat_id) UNIQUE (cat_id)
......
...@@ -354,6 +354,14 @@ class Bootstrapper ...@@ -354,6 +354,14 @@ class Bootstrapper
); );
} }
} }
// Store last selected language in user account, if applicable:
if (($user = $sm->get(\VuFind\Auth\Manager::class)->isLoggedIn())
&& $user->last_language != $language
) {
$user->updateLastLanguage($language);
}
// Send key values to view: // Send key values to view:
$viewModel = $sm->get('ViewManager')->getViewModel(); $viewModel = $sm->get('ViewManager')->getViewModel();
$viewModel->setVariable('userLang', $language); $viewModel->setVariable('userLang', $language);
......
...@@ -681,6 +681,19 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface, ...@@ -681,6 +681,19 @@ class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface,
} }
/** /**
* Updated saved language
*
* @param string $language New language
*
* @return void
*/
public function updateLastLanguage($language)
{
$this->last_language = $language;
$this->save();
}
/*
* Update the user's email address, if appropriate. Note that this does NOT * Update the user's email address, if appropriate. Note that this does NOT
* automatically save the row; it assumes a subsequent call will be made to * automatically save the row; it assumes a subsequent call will be made to
* the save() method. * the save() method.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment