Search in sources :

Example 76 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class RichTextConfiguration method setInsertDateTimeEnabled.

/**
 * Enable / disable the date and time insert plugin
 *
 * @param insertDateTimeEnabled
 *            true: plugin enabled; false: plugin disabled
 * @param locale
 *            the locale used to format the date and time
 * @param row
 *            The row where to place the plugin buttons
 */
private void setInsertDateTimeEnabled(boolean insertDateTimeEnabled, Locale locale) {
    if (insertDateTimeEnabled) {
        // use date format defined in org.olat.core package
        Formatter formatter = Formatter.getInstance(locale);
        String dateFormat = formatter.getSimpleDatePatternForDate();
        setQuotedConfigValue("insertdatetime_dateformat", dateFormat);
        setNonQuotedConfigValue("insertdatetime_formats", "['" + dateFormat + "','%H:%M:%S']");
    }
}
Also used : Formatter(org.olat.core.util.Formatter)

Example 77 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class CertificatePDFFormWorker method fillRepositoryEntry.

private void fillRepositoryEntry(PDAcroForm acroForm) throws IOException {
    String title = entry.getDisplayname();
    fillField("title", title, acroForm);
    String externalRef = entry.getExternalRef();
    fillField("externalReference", externalRef, acroForm);
    String authors = entry.getAuthors();
    fillField("authors", authors, acroForm);
    String expenditureOfWorks = entry.getExpenditureOfWork();
    fillField("expenditureOfWorks", expenditureOfWorks, acroForm);
    String mainLanguage = entry.getMainLanguage();
    fillField("mainLanguage", mainLanguage, acroForm);
    if (entry.getLifecycle() != null) {
        Formatter format = Formatter.getInstance(locale);
        Date from = entry.getLifecycle().getValidFrom();
        String formattedFrom = format.formatDate(from);
        fillField("from", formattedFrom, acroForm);
        String formattedFromLong = format.formatDateLong(from);
        fillField("fromLong", formattedFromLong, acroForm);
        Date to = entry.getLifecycle().getValidTo();
        String formattedTo = format.formatDate(to);
        fillField("to", formattedTo, acroForm);
        String formattedToLong = format.formatDateLong(to);
        fillField("toLong", formattedToLong, acroForm);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 78 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class PortfolioCourseNodeRunController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    infosContainer = FormLayoutContainer.createDefaultFormLayout("infos", getTranslator());
    formLayout.add(infosContainer);
    String assessmentPage = velocity_root + "/assessment_infos.html";
    assessmentInfosContainer = FormLayoutContainer.createCustomFormLayout("assessmentInfos", getTranslator(), assessmentPage);
    assessmentInfosContainer.setVisible(false);
    formLayout.add(assessmentInfosContainer);
    VelocityContainer mainVC = ((FormLayoutContainer) formLayout).getFormItemComponent();
    if (courseNode.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD, false)) {
        HighScoreRunController highScoreCtr = new HighScoreRunController(ureq, getWindowControl(), userCourseEnv, courseNode, this.mainForm);
        if (highScoreCtr.isViewHighscore()) {
            Component highScoreComponent = highScoreCtr.getInitialComponent();
            mainVC.put("highScore", highScoreComponent);
        }
    }
    Object text = config.get(PortfolioCourseNodeConfiguration.NODE_TEXT);
    String explanation = (text instanceof String) ? (String) text : "";
    if (StringHelper.containsNonWhitespace(explanation)) {
        uifactory.addStaticTextElement("explanation.text", explanation, infosContainer);
    }
    String deadlineconfig = (String) config.get(PortfolioCourseNodeConfiguration.DEADLINE_TYPE);
    if (!DeadlineType.none.name().equals(deadlineconfig) && deadlineconfig != null) {
        // show deadline-config
        String deadLineLabel = "map.deadline." + deadlineconfig + ".label";
        String deadLineInfo = "";
        if (deadlineconfig.equals(DeadlineType.absolut.name())) {
            Formatter f = Formatter.getInstance(getLocale());
            deadLineInfo = f.formatDate((Date) config.get(PortfolioCourseNodeConfiguration.DEADLINE_DATE));
        } else {
            deadLineInfo = getDeadlineRelativeInfo();
        }
        deadlineDateText = uifactory.addStaticTextElement("deadline", deadLineLabel, deadLineInfo, infosContainer);
    }
    if (templateMap != null || templateBinder != null) {
        updateUI(ureq);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HighScoreRunController(org.olat.course.highscore.ui.HighScoreRunController) Component(org.olat.core.gui.components.Component) Date(java.util.Date) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 79 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class DropboxController method getConfirmation.

private String getConfirmation(UserRequest ureq, String filename) {
    // grab confirmation-text from bb-config
    String confirmation = config.getStringValue(TACourseNode.CONF_DROPBOX_CONFIRMATION);
    Context c = new VelocityContext();
    Identity identity = ureq.getIdentity();
    c.put("login", identity.getName());
    c.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
    c.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
    c.put("email", UserManager.getInstance().getUserDisplayEmail(identity, getLocale()));
    c.put("filename", filename);
    Date now = new Date();
    Formatter f = Formatter.getInstance(ureq.getLocale());
    c.put("date", f.formatDate(now));
    c.put("time", f.formatTime(now));
    // update attempts counter for this user: one file - one attempts
    AssessableCourseNode acn = (AssessableCourseNode) node;
    acn.incrementUserAttempts(userCourseEnv, Role.user);
    // log entry for this file
    UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
    am.appendToUserNodeLog(node, identity, identity, "FILE UPLOADED: " + filename);
    return VelocityHelper.getInstance().evaluateVTL(confirmation, c);
}
Also used : Context(org.apache.velocity.context.Context) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VelocityContext(org.apache.velocity.VelocityContext) MailContext(org.olat.core.util.mail.MailContext) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) VelocityContext(org.apache.velocity.VelocityContext) Formatter(org.olat.core.util.Formatter) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 80 with Formatter

use of org.olat.core.util.Formatter in project openolat by klemens.

the class MemberInfoController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        Controller dpc = new DisplayPortraitController(ureq, getWindowControl(), identity, true, false);
        // auto dispose
        listenTo(dpc);
        layoutCont.put("image", dpc.getInitialComponent());
        layoutCont.contextPut("fullname", StringHelper.escapeHtml(userManager.getUserDisplayName(identity)));
    }
    // user properties
    FormLayoutContainer userPropertiesContainer = FormLayoutContainer.createDefaultFormLayout_6_6("userProperties", getTranslator());
    formLayout.add("userProperties", userPropertiesContainer);
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(getClass().getCanonicalName(), false);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        String value = userPropertyHandler.getUserProperty(identity.getUser(), getLocale());
        String key = userPropertyHandler.i18nFormElementLabelKey();
        if (value == null) {
            value = "";
        }
        uifactory.addStaticTextElement("up_" + propName, key, value, userPropertiesContainer);
    }
    // course informations
    FormLayoutContainer courseInfosContainer = FormLayoutContainer.createDefaultFormLayout_9_3("courseInfos", getTranslator());
    formLayout.add("courseInfos", courseInfosContainer);
    membershipCreationEl = uifactory.addStaticTextElement("firstTime", "course.membership.creation", "", courseInfosContainer);
    if (securityModule.isUserLastVisitVisible(ureq.getUserSession().getRoles())) {
        Formatter formatter = Formatter.getInstance(getLocale());
        String lastVisit = "";
        String numOfVisits = "0";
        if (courseInfos != null) {
            if (courseInfos.getRecentLaunch() != null) {
                lastVisit = formatter.formatDate(courseInfos.getRecentLaunch());
            }
            if (courseInfos.getVisit() >= 0) {
                numOfVisits = Integer.toString(courseInfos.getVisit());
            }
        }
        uifactory.addStaticTextElement("lastTime", "course.lastTime", lastVisit, courseInfosContainer);
        uifactory.addStaticTextElement("numOfVisits", "course.numOfVisits", numOfVisits, courseInfosContainer);
    }
    // links
    if (withLinks) {
        homeLink = uifactory.addFormLink("home", formLayout, Link.BUTTON);
        homeLink.setIconLeftCSS("o_icon o_icon_home");
        formLayout.add("home", homeLink);
        contactLink = uifactory.addFormLink("contact", formLayout, Link.BUTTON);
        contactLink.setIconLeftCSS("o_icon o_icon_mail");
        formLayout.add("contact", contactLink);
        if (repoEntryKey != null) {
            assessmentLink = uifactory.addFormLink("assessment", formLayout, Link.BUTTON);
            assessmentLink.setIconLeftCSS("o_icon o_icon_certificate");
            formLayout.add("assessment", assessmentLink);
        }
    }
}
Also used : DisplayPortraitController(org.olat.user.DisplayPortraitController) Formatter(org.olat.core.util.Formatter) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) DisplayPortraitController(org.olat.user.DisplayPortraitController) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) Controller(org.olat.core.gui.control.Controller) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

Formatter (org.olat.core.util.Formatter)80 Date (java.util.Date)30 ArrayList (java.util.ArrayList)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 IOException (java.io.IOException)6 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)6 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)6 Identity (org.olat.core.id.Identity)6 Translator (org.olat.core.gui.translator.Translator)5 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)5 File (java.io.File)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 COSVisitorException (org.apache.pdfbox.exceptions.COSVisitorException)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 OWASPAntiSamyXSSFilter (org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2