Search in sources :

Example 21 with UserManager

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;
}
Also used : UserManager(org.olat.user.UserManager)

Example 22 with UserManager

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;
}
Also used : Locale(java.util.Locale) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 23 with UserManager

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;
}
Also used : UserManager(org.olat.user.UserManager) SelectionElement(org.olat.core.gui.components.form.flexible.elements.SelectionElement)

Example 24 with UserManager

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;
}
Also used : Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) SelectionElement(org.olat.core.gui.components.form.flexible.elements.SelectionElement)

Example 25 with UserManager

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;
}
Also used : HomePageConfig(org.olat.user.HomePageConfig) User(org.olat.core.id.User) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UserManager(org.olat.user.UserManager) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

UserManager (org.olat.user.UserManager)64 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)22 Locale (java.util.Locale)12 Identity (org.olat.core.id.Identity)12 Date (java.util.Date)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)10 Translator (org.olat.core.gui.translator.Translator)10 User (org.olat.core.id.User)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 RestSecurityHelper.getLocale (org.olat.restapi.security.RestSecurityHelper.getLocale)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 SelectionElement (org.olat.core.gui.components.form.flexible.elements.SelectionElement)4 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)4 AssertException (org.olat.core.logging.AssertException)4 ICourse (org.olat.course.ICourse)4 RestSecurityHelper.isUserManager (org.olat.restapi.security.RestSecurityHelper.isUserManager)4