The extension point org.ametys.runtime.plugins.core.userpref.UserPreferencesExtensionPoint allows you to define user preferences for contributors (back-office side).
The extension point org.ametys.runtime.plugins.core.userpref.UserPreferencesExtensionPoint.FO allows you to define user preferences for viewers (front-office side).
These are multiple extension points: in other words, several implementations of these extension points can be active at the same time.
A user preference is defined in the same way as a classic parameter, as described on the Parameter overview page. It has some additional information enabling it to be categorized and scheduled. It is made up of :
a unique identifier
a wording
a description
a type: string, long, date, ...
a widget (optional)
one or more validation rules (optional)
a list of enumerated values (optional)
a group, to group several preferences under a single group
a number to order them
User preferences are defined in a file plugin.xml. If you need to create a new plugin file, follow the instructions on the plugin Ametys page.
Sample declaration
Oops!
Copy to clipboard failed. Open the code and copy it manually.
The user preference storage mode is defined by a single extension point (i.e. only one implementation can be active at a time):
org.ametys.runtime.plugins.core.userpref.DefaultUserPreferencesStorage for contributors' user preferences
org.ametys.runtime.plugins.core.userpref.DefaultUserPreferencesStorage.FO for visitors' user preferences
There are only 2 native storage implementations:
org.ametys.runtime.plugins.core.userpref.JdbcUserPreferencesStorage or org.ametys.runtime.plugins.core.userpref.JdbcUserPreferencesStorage.FO to store user preferences in a database. This is the default implementation.
org.ametys.runtime.plugins.core.userpref.EmptyUserPreferencesStorage to avoid using user preferences.
The site application generally has no user preferences (not to be confused with visitors' user preferences). This is why the "empty" implementation is generally used:
Extract from runtime file.xml site application
Oops!
Copy to clipboard failed. Open the code and copy it manually.
Use of contributors' user preferences (back-office)
In JavaScript, the org.ametys.dao.userpref.UserPrefDAO to access the logged-in user's preference values.
Synchronous mode access
Simple user preference
Oops!
Copy to clipboard failed. Open the code and copy it manually.
var value = org.ametys.dao.userpref.UserPrefDAO.getInstance().getValue("my-user-pref");
var value = org.ametys.dao.userpref.UserPrefDAO.getInstance().getValue("my-user-pref");
var value = org.ametys.dao.userpref.UserPrefDAO.getInstance().getValue("my-user-pref");
Multivalued user preference
Oops!
Copy to clipboard failed. Open the code and copy it manually.
var values = org.ametys.dao.userpref.UserPrefDAO.getInstance().getValues("my-user-pref");
var values = org.ametys.dao.userpref.UserPrefDAO.getInstance().getValues("my-user-pref");
var values = org.ametys.dao.userpref.UserPrefDAO.getInstance().getValues("my-user-pref");
Asynchronous mode access
Oops!
Copy to clipboard failed. Open the code and copy it manually.
function cbFn1(value)
{
alert("The user preference is " + (value || ""));
}
function cbFn2(values)
{
var str = "";
if (values != null)
{
if (i != 0) str += ", ";
for (var i = 0; i < values.length; i++)
{
str += values[i];
}
}
alert("User preferences are " + str);
}
org.ametys.dao.userpref.UserPrefDAO.getInstance().getValue("my-user-pref", cbFn1);
org.ametys.dao.userpref.UserPrefDAO.getInstance().getValues("my-user-pref", callbackFn);
function cbFn1(value)
{
alert("The user preference is " + (value || ""));
}
function cbFn2(values)
{
var str = "";
if (values != null)
{
if (i != 0) str += ", ";
for (var i = 0; i < values.length; i++)
{
str += values[i];
}
}
alert("User preferences are " + str);
}
org.ametys.dao.userpref.UserPrefDAO.getInstance().getValue("my-user-pref", cbFn1);
org.ametys.dao.userpref.UserPrefDAO.getInstance().getValues("my-user-pref", callbackFn);
function cbFn1(value)
{
alert("The user preference is " + (value || ""));
}
function cbFn2(values)
{
var str = "";
if (values != null)
{
if (i != 0) str += ", ";
for (var i = 0; i < values.length; i++)
{
str += values[i];
}
}
alert("User preferences are " + str);
}
org.ametys.dao.userpref.UserPrefDAO.getInstance().getValue("my-user-pref", cbFn1);
org.ametys.dao.userpref.UserPrefDAO.getInstance().getValues("my-user-pref", callbackFn);
Use of visitors' user preferences (front-office)
Visitors' user preferences are available through the "User preferences" service.