Search in sources :

Example 86 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class BaseFullWebappController method initializeBase.

private void initializeBase(UserRequest ureq, WindowManager winman, ComponentCollection mainPanel) {
    // component-id of mainPanel for the window id
    mainVc.contextPut("o_winid", mainPanel.getDispatchID());
    BaseSecurityModule securityModule = CoreSpringFactory.getImpl(BaseSecurityModule.class);
    mainVc.contextPut("enforceTopFrame", securityModule.isForceTopFrame());
    // add optional css classes
    mainVc.contextPut("bodyCssClasses", bodyCssClasses);
    Window w = wbo.getWindow();
    mainVc.put("jsCssRawHtmlHeader", w.getJsCssRawHtmlHeader());
    // control part for ajax-communication. returns an empty panel if ajax
    // is not enabled, so that ajax can be turned on on the fly for
    // development mode
    jsServerC = wbo.createAJAXController(ureq);
    mainVc.put("jsServer", jsServerC.getInitialComponent());
    // init with no bookmark (=empty bc)
    mainVc.contextPut("o_bc", "");
    mainVc.contextPut("o_serverUri", Settings.createServerURI());
    // the current language; used e.g. by screenreaders
    mainVc.contextPut("lang", ureq.getLocale().toString());
    // some user properties
    if (ureq.getUserSession().isAuthenticated()) {
        Identity ident = ureq.getIdentity();
        StringBuilder sb = new StringBuilder();
        sb.append("{ identity : ").append(ident.getKey());
        User user = ident.getUser();
        List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, ureq.getUserSession().getRoles().isOLATAdmin());
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            String escapedValue = StringHelper.escapeJavaScript(userPropertyHandler.getUserProperty(user, getLocale()));
            sb.append(", ").append(userPropertyHandler.getName()).append(" : \"").append(escapedValue).append("\"");
        }
        sb.append("}");
        mainVc.contextPut("userJSON", sb);
    }
    // the current GUI theme and the global settings that contains the
    // font-size. both are pushed as objects so that window.dirty always reads
    // out the correct value
    mainVc.contextPut("theme", w.getGuiTheme());
    mainVc.contextPut("globalSettings", winman.getGlobalSettings());
    // also add the optional theme javascript
    addThemeJS();
    // Add JS analytics code, e.g. for google analytics
    if (analyticsModule.isAnalyticsEnabled()) {
        AnalyticsSPI analyticsSPI = analyticsModule.getAnalyticsProvider();
        mainVc.contextPut("analytics", analyticsSPI.analyticsInitPageJavaScript());
    }
    // content panel
    contentPanel = new Panel("olatContentPanel");
    mainVc.put("olatContentPanel", contentPanel);
    mainVc.contextPut("o_winid", w.getDispatchID());
    mainVc.contextPut("buildversion", Settings.getVersion());
    if (wbo.isDebuging()) {
        debugC = wbo.createDebugDispatcherController(ureq, getWindowControl());
        mainVc.put("guidebug", debugC.getInitialComponent());
    }
    // Inline translation interceptor. when the translation tool is enabled it
    // will start the translation tool in translation mode, if the overlay
    // feature is enabled it will start in customizing mode
    // fxdiff: allow user-managers to use the inline translation also.
    UserSession usess = ureq.getUserSession();
    if (usess.isAuthenticated() && (usess.getRoles().isOLATAdmin() || usess.getRoles().isUserManager()) && (i18nModule.isTransToolEnabled() || i18nModule.isOverlayEnabled())) {
        inlineTranslationC = wbo.createInlineTranslationDispatcherController(ureq, getWindowControl());
        Preferences guiPrefs = usess.getGuiPreferences();
        Boolean isInlineTranslationEnabled = (Boolean) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_INLINE_TRANSLATION_ENABLED, Boolean.FALSE);
        i18nManager.setMarkLocalizedStringsEnabled(usess, isInlineTranslationEnabled);
        mainVc.put("inlineTranslation", inlineTranslationC.getInitialComponent());
    }
    // debug info if debugging
    if (wbo.isDebuging()) {
        developmentC = wbo.createDevelopmentController(ureq, getWindowControl());
        mainVc.put("development", developmentC.getInitialComponent());
    }
    // put the global js translator mapper path into the main window
    mainVc.contextPut("jsTranslationMapperPath", BaseChiefController.jsTranslationMapperPath);
    // master window
    // w.addListener(this); // to be able to report "browser reload" to the user
    w.setContentPane(mainPanel);
}
Also used : Window(org.olat.core.gui.components.Window) I18nModule(org.olat.core.util.i18n.I18nModule) User(org.olat.core.id.User) BaseSecurityModule(org.olat.basesecurity.BaseSecurityModule) AnalyticsSPI(org.olat.core.commons.services.analytics.AnalyticsSPI) OncePanel(org.olat.core.gui.components.panel.OncePanel) Panel(org.olat.core.gui.components.panel.Panel) StackedPanel(org.olat.core.gui.components.panel.StackedPanel) UserSession(org.olat.core.util.UserSession) Identity(org.olat.core.id.Identity) Preferences(org.olat.core.util.prefs.Preferences) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 87 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class MembersPrintController method initFormMemberList.

private void initFormMemberList(String name, String label, List<Identity> members) {
    List<Member> memberWrappers = members.stream().map(m -> createMember(m)).collect(Collectors.toList());
    VelocityContainer listVC = createVelocityContainer("printList");
    listVC.contextPut("label", label);
    listVC.contextPut("avatarBaseURL", avatarBaseURL);
    listVC.contextPut("members", memberWrappers);
    listVC.contextPut("typecss", "o_" + name);
    listVC.contextPut("userPropertyPrintHandlers", userPropertyPrintHandlers);
    // add lookup table so the avatar properties can be read out from the member object that contains the full list of attributes
    Map<String, Integer> handlerLookupMap = new HashMap<String, Integer>();
    for (int i = userPropertyPrintHandlers.size(); i-- > 0; ) {
        UserPropertyHandler handler = userPropertyPrintHandlers.get(i);
        handlerLookupMap.put(handler.getName(), i);
    }
    listVC.contextPut("handlerLookupMap", handlerLookupMap);
    mainVC.put(name, listVC);
}
Also used : Util(org.olat.core.util.Util) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) MediaResource(org.olat.core.gui.media.MediaResource) Event(org.olat.core.gui.control.Event) Member(org.olat.course.nodes.members.Member) HttpServletRequest(javax.servlet.http.HttpServletRequest) MainPanel(org.olat.core.gui.components.panel.MainPanel) UserConstants(org.olat.core.id.UserConstants) Locale(java.util.Locale) Map(java.util.Map) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) BaseSecurityModule(org.olat.basesecurity.BaseSecurityModule) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Translator(org.olat.core.gui.translator.Translator) WindowControl(org.olat.core.gui.control.WindowControl) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) DisplayPortraitManager(org.olat.user.DisplayPortraitManager) Component(org.olat.core.gui.components.Component) Collectors(java.util.stream.Collectors) Mapper(org.olat.core.dispatcher.mapper.Mapper) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) UserManager(org.olat.user.UserManager) BasicController(org.olat.core.gui.control.controller.BasicController) List(java.util.List) Identity(org.olat.core.id.Identity) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) UserRequest(org.olat.core.gui.UserRequest) Roles(org.olat.core.id.Roles) HashMap(java.util.HashMap) Member(org.olat.course.nodes.members.Member) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 88 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class MembersTableController method initColumns.

private SortKey initColumns(FlexiTableColumnModel columnsModel) {
    int colPos = AbstractMemberListController.USER_PROPS_OFFSET;
    SortKey defaultSortKey = null;
    String rowAction = "vcard";
    if (chatEnabled && editable) {
        DefaultFlexiColumnModel chatCol = new DefaultFlexiColumnModel(Cols.online.i18n(), Cols.online.ordinal());
        chatCol.setExportable(false);
        columnsModel.addFlexiColumnModel(chatCol);
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        boolean visible = userManager.isMandatoryUserProperty(MembersDisplayRunController.USER_PROPS_LIST_ID, userPropertyHandler);
        String emailRowAction = rowAction;
        FlexiColumnModel col;
        if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName) || UserConstants.EMAIL.equals(propName)) {
            // when email is enabled, the action will trigger email workflow
            if (UserConstants.EMAIL.equals(propName) && canEmail) {
                emailRowAction = "email";
            }
            col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, emailRowAction, true, propName, new StaticFlexiCellRenderer(emailRowAction, new TextFlexiCellRenderer()));
        } else {
            col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName);
        }
        columnsModel.addFlexiColumnModel(col);
        colPos++;
        if (defaultSortKey == null) {
            defaultSortKey = new SortKey(propName, true);
        }
    }
    if (userLastTimeVisible) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.firstTime.i18n(), Cols.firstTime.ordinal(), true, Cols.firstTime.name()));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.lastTime.i18n(), Cols.lastTime.ordinal(), true, Cols.lastTime.name()));
    }
    return defaultSortKey;
}
Also used : StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) SortKey(org.olat.core.commons.persistence.SortKey) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 89 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class XlsMembersExport method createHeader.

private void createHeader(List<UserPropertyHandler> userPropertyHandlers, Translator translator, OpenXMLWorksheet sheet, OpenXMLWorkbook workbook) {
    Row headerRow = sheet.newRow();
    for (int c = 0; c < userPropertyHandlers.size(); c++) {
        UserPropertyHandler handler = userPropertyHandlers.get(c);
        String header = translator.translate("form.name." + handler.getName());
        headerRow.addCell(c, header, workbook.getStyles().getHeaderStyle());
    }
    Translator roleTranslator = Util.createPackageTranslator(RulesDataModel.class, translator.getLocale());
    headerRow.addCell(userPropertyHandlers.size(), roleTranslator.translate("rules.role"));
}
Also used : Translator(org.olat.core.gui.translator.Translator) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 90 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project openolat by klemens.

the class NotificationHelper method getFormatedName.

/**
 * returns "firstname lastname" or a translated "user unknown" for a given
 * identity
 *
 * @param ident
 * @return
 */
public static String getFormatedName(Identity ident) {
    String formattedName;
    if (ident == null) {
        Translator trans = Util.createPackageTranslator(NotificationNewsController.class, I18nManager.getInstance().getLocaleOrDefault(null));
        return trans.translate("user.unknown");
    } else {
        // Optimize: use from cache to not re-calculate user properties over and over again
        formattedName = userPropertiesCache.get(ident.getKey());
        if (formattedName != null) {
            return formattedName;
        }
    }
    Translator trans = Util.createPackageTranslator(NotificationNewsController.class, I18nManager.getInstance().getLocaleOrDefault(ident.getUser().getPreferences().getLanguage()));
    User user = ident.getUser();
    if (user == null) {
        formattedName = trans.translate("user.unknown");
    } else {
        // grap user properties from context
        List<UserPropertyHandler> propertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(NotificationHelper.class.getName(), false);
        String[] properties = new String[propertyHandlers.size()];
        for (int i = 0; i < propertyHandlers.size(); i++) {
            UserPropertyHandler propHandler = propertyHandlers.get(i);
            String prop = propHandler.getUserProperty(user, trans.getLocale());
            if (StringHelper.containsNonWhitespace(prop)) {
                properties[i] = prop;
            } else {
                properties[i] = "-";
            }
        }
        formattedName = trans.translate("user.formatted", properties);
    }
    // put formatted name in cache, times out after 5 mins
    userPropertiesCache.put(ident.getKey(), formattedName);
    return formattedName;
}
Also used : User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)319 Identity (org.olat.core.id.Identity)84 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)74 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)70 ArrayList (java.util.ArrayList)62 FormItem (org.olat.core.gui.components.form.flexible.FormItem)62 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)56 User (org.olat.core.id.User)52 HashMap (java.util.HashMap)40 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)36 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)34 Translator (org.olat.core.gui.translator.Translator)32 Date (java.util.Date)30 UserManager (org.olat.user.UserManager)28 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)24 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)24 File (java.io.File)22 BusinessGroup (org.olat.group.BusinessGroup)22 SortKey (org.olat.core.commons.persistence.SortKey)18 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)18