use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class GenericCheckboxPropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
SelectionElement sElem = FormUIFactory.getInstance().addCheckboxesHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, new String[] { getName() }, new String[] { "" });
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
sElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
sElem.setMandatory(true);
}
return sElem;
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class YearPropertyHandler method addFormItem.
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
/* let's load the years */
loadSelectionKeysFromConfig();
// add the no-selection entry to the dropdown
String[] allKeys = new String[selectionKeys.length + 1];
System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, allKeys, null);
String internalValue = getInternalValue(user);
if (isValidValue(user, internalValue, null, null) && internalValue != null)
sse.select(internalValue, true);
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
sse.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
sse.setMandatory(true);
}
return sse;
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class GenericYesNoPropertyHandler method addFormItem.
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
SelectionElement sElem = null;
Translator trans = Util.createPackageTranslator(this.getClass(), locale);
sElem = FormUIFactory.getInstance().addRadiosHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, new String[] { KEY_YES, KEY_NO }, new String[] { trans.translate("yes"), trans.translate("no") });
// pre-select yes/no
String internalValue = getInternalValue(user);
if (isValidValue(user, internalValue, null, null)) {
if (VAL_YES.equals(internalValue))
sElem.select(KEY_YES, true);
if (VAL_NO.equals(internalValue))
sElem.select(KEY_NO, true);
}
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
sElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
sElem.setMandatory(true);
}
return sElem;
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class RegistrationForm2 method initForm.
/**
* Initialize the form
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.register");
// first the configured user properties
UserManager um = UserManager.getInstance();
userPropertyHandlers = um.getUserPropertyHandlersFor(USERPROPERTIES_FORM_IDENTIFIER, false);
Translator tr = Util.createPackageTranslator(UserPropertyHandler.class, getLocale(), getTranslator());
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
fi.setTranslator(tr);
propFormItems.put(userPropertyHandler.getName(), fi);
}
uifactory.addSpacerElement("lang", formLayout, true);
// second the user language
Map<String, String> languages = i18nManager.getEnabledLanguagesTranslated();
lang = uifactory.addDropdownSingleselect("user.language", formLayout, StringHelper.getMapKeysAsStringArray(languages), StringHelper.getMapValuesAsStringArray(languages), null);
lang.select(languageKey, true);
uifactory.addSpacerElement("loginstuff", formLayout, true);
if (usernameReadonly) {
usernameStatic = uifactory.addStaticTextElement("username", "user.login", proposedUsername, formLayout);
} else {
username = uifactory.addTextElement("username", "user.login", 128, "", formLayout);
username.setMandatory(true);
}
if (proposedUsername != null) {
setLogin(proposedUsername);
}
if (userInUse) {
setLoginErrorKey("form.check6");
}
newpass1 = uifactory.addPasswordElement("newpass1", "form.password.new1", 128, "", formLayout);
newpass1.setMandatory(true);
newpass1.setAutocomplete("new-password");
newpass2 = uifactory.addPasswordElement("newpass2", "form.password.new2", 128, "", formLayout);
newpass2.setMandatory(true);
newpass2.setAutocomplete("new-password");
// Button layout
buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("submit.speichernUndweiter", buttonLayout);
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class IdentityDocument method createDocument.
/**
* Factory method to create a new IdentityDocument
* @param searchResourceContext
* @param wikiPage
* @return
*/
public static Document createDocument(SearchResourceContext searchResourceContext, Identity identity) {
UserManager userMgr = UserManager.getInstance();
User user = identity.getUser();
HomePageConfigManager homepageMgr = HomePageConfigManagerImpl.getInstance();
HomePageConfig publishConfig = homepageMgr.loadConfigFor(identity.getName());
IdentityDocument identityDocument = new IdentityDocument();
identityDocument.setTitle(identity.getName());
identityDocument.setCreatedDate(user.getCreationDate());
// loop through all user properties and collect the content string and the last modified
List<UserPropertyHandler> userPropertyHanders = userMgr.getUserPropertyHandlersFor(IdentityDocument.class.getName(), false);
StringBuilder content = new StringBuilder();
for (UserPropertyHandler userPropertyHandler : userPropertyHanders) {
String propertyName = userPropertyHandler.getName();
// only index fields the user has published!
if (publishConfig.isEnabled(propertyName)) {
String value = user.getProperty(propertyName, I18nModule.getDefaultLocale());
if (value != null) {
content.append(value).append(" ");
}
}
}
// user text
String text = publishConfig.getTextAboutMe();
if (StringHelper.containsNonWhitespace(text)) {
text = FilterFactory.getHtmlTagsFilter().filter(text);
content.append(text).append(' ');
}
// finally use the properties as the content for this identity
if (content.length() > 0) {
identityDocument.setContent(content.toString());
}
identityDocument.setResourceUrl(searchResourceContext.getResourceUrl());
identityDocument.setDocumentType(searchResourceContext.getParentContextType());
identityDocument.setCssIcon(CSSHelper.CSS_CLASS_USER);
if (log.isDebug())
log.debug(identityDocument.toString());
return identityDocument.getLuceneDocument();
}
Aggregations