use of org.olat.user.UserManager in project openolat by klemens.
the class GenderPropertyHandler 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) {
org.olat.core.gui.components.form.flexible.elements.SingleSelection genderElem = null;
// genderElem = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, keys, getTranslatedValues(locale), null);
genderElem = FormUIFactory.getInstance().addRadiosVertical(getName(), i18nFormElementLabelKey(), formItemContainer, keys, getTranslatedValues(locale));
String key = user == null ? "-" : getInternalValue(user);
for (int i = keys.length; i-- > 0; ) {
if (keys[i].equals(key)) {
genderElem.select(keys[i], true);
}
}
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
genderElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
genderElem.setMandatory(true);
}
return genderElem;
}
use of org.olat.user.UserManager in project openolat by klemens.
the class Generic127CharTextPropertyHandler 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, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
tElem.setItemValidatorProvider(new ItemValidatorProvider() {
@Override
public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
return Generic127CharTextPropertyHandler.this.isValidValue(user, value, validationError, llocale);
}
});
tElem.setLabel(i18nFormElementLabelKey(), null);
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
tElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
tElem.setMandatory(true);
}
return tElem;
}
use of org.olat.user.UserManager in project openolat by klemens.
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 klemens.
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 klemens.
the class UserVOFactory method get.
public static UserVO get(Identity identity, Locale locale, boolean allProperties, boolean isAdmin, boolean withPortrait) {
if (locale == null) {
locale = I18nModule.getDefaultLocale();
}
UserVO userVO = new UserVO();
User user = identity.getUser();
userVO.setKey(identity.getKey());
if (identity != null) {
userVO.setLogin(identity.getName());
}
userVO.setExternalId(identity.getExternalId());
userVO.setFirstName(user.getProperty(UserConstants.FIRSTNAME, null));
userVO.setLastName(user.getProperty(UserConstants.LASTNAME, null));
userVO.setEmail(user.getProperty(UserConstants.EMAIL, null));
if (withPortrait) {
File portrait = DisplayPortraitManager.getInstance().getSmallPortrait(identity.getName());
if (portrait != null && portrait.exists()) {
try {
InputStream input = new FileInputStream(portrait);
byte[] datas = IOUtils.toByteArray(input);
FileUtils.closeSafely(input);
byte[] data64 = Base64.encodeBase64(datas);
userVO.setPortrait(new String(data64, "UTF8"));
} catch (IOException e) {
log.error("", e);
}
}
}
if (allProperties) {
UserManager um = UserManager.getInstance();
HomePageConfig hpc = isAdmin ? null : HomePageConfigManagerImpl.getInstance().loadConfigFor(identity.getName());
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
for (UserPropertyHandler propertyHandler : propertyHandlers) {
String propName = propertyHandler.getName();
if (hpc != null && !hpc.isEnabled(propName)) {
continue;
}
if (!UserConstants.FIRSTNAME.equals(propName) && !UserConstants.LASTNAME.equals(propName) && !UserConstants.EMAIL.equals(propName)) {
String value = propertyHandler.getUserProperty(user, locale);
userVO.putProperty(propName, value);
}
}
}
return userVO;
}
Aggregations