Search in sources :

Example 11 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class Wiki method getRecentChanges.

protected String getRecentChanges(Locale locale) {
    if (locale == null)
        throw new AssertException("param was null which is not allowed");
    final int MAX_RESULTS = 5;
    List<WikiPage> pages = new ArrayList<>(wikiPages.values());
    Collections.sort(pages, WikiPageSort.MODTIME_ORDER);
    StringBuilder sb = new StringBuilder(512);
    int counter = 0;
    Formatter f = Formatter.getInstance(locale);
    UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
    for (Iterator<WikiPage> iter = pages.iterator(); iter.hasNext(); ) {
        if (counter > MAX_RESULTS)
            break;
        WikiPage page = iter.next();
        if (!page.getPageName().startsWith("O_") && !page.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) {
            sb.append("* [[");
            sb.append(page.getPageName());
            sb.append("]] ");
            sb.append(f.formatDateAndTime(new Date(page.getModificationTime())));
            sb.append(" Author: ");
            long author = page.getModifyAuthor();
            if (author != 0) {
                String authorFullname = userManager.getUserDisplayName(author);
                if (StringHelper.containsNonWhitespace(authorFullname)) {
                    sb.append(" Author: ").append(authorFullname);
                } else {
                    sb.append("???");
                }
            }
            sb.append("\n");
            counter++;
        }
    }
    return sb.toString();
}
Also used : AssertException(org.olat.core.logging.AssertException) Formatter(org.olat.core.util.Formatter) UserManager(org.olat.user.UserManager) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 12 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class PortfolioResultDetailsController method initBindersForm.

protected void initBindersForm(FormItemContainer formLayout) {
    Formatter formatter = Formatter.getInstance(getLocale());
    int count = 0;
    for (Binder binder : binders) {
        MapElements mapElements = new MapElements();
        if (binders.size() > 1 || !binder.getTemplate().equals(templateBinder)) {
            String templateTitle = binder.getTemplate().getTitle();
            uifactory.addStaticTextElement("map.template." + count, "map.template", templateTitle, formLayout);
        }
        String copyDate = "";
        if (binder.getCopyDate() != null) {
            copyDate = formatter.formatDateAndTime(binder.getCopyDate());
        }
        uifactory.addStaticTextElement("map.copyDate." + count, "map.copyDate", copyDate, formLayout);
        String returnDate = "";
        if (binder.getReturnDate() != null) {
            returnDate = formatter.formatDateAndTime(binder.getReturnDate());
        }
        uifactory.addStaticTextElement("map.returnDate." + count, "map.returnDate", returnDate, formLayout);
        FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons." + count, getTranslator());
        buttonsCont.setRootForm(mainForm);
        formLayout.add(buttonsCont);
        mapElements.openMapLink = uifactory.addFormLink("open.binder." + count, "open.binder", "open.map", null, buttonsCont, Link.BUTTON);
        mapElements.openMapLink.setUserObject(binder);
        count++;
        if (count != binders.size()) {
            uifactory.addSpacerElement("spacer-" + count, formLayout, false);
        }
        binderToElements.put(binder, mapElements);
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) Formatter(org.olat.core.util.Formatter) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 13 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class IQRunController method createChangelogMsg.

/**
 * @param ureq
 * @return
 */
private StringBuilder createChangelogMsg(UserRequest ureq) {
    /*
		 * TODO:pb:is ImsRepositoryResolver the right place for getting the change log?
		 */
    // re could be null, but if we are here it should not be null!
    Roles userRoles = ureq.getUserSession().getRoles();
    boolean showAll = userRoles.isAuthor() || userRoles.isOLATAdmin();
    // get changelog
    Formatter formatter = Formatter.getInstance(ureq.getLocale());
    ImsRepositoryResolver resolver = new ImsRepositoryResolver(referenceTestEntry);
    QTIChangeLogMessage[] qtiChangeLog = resolver.getDocumentChangeLog();
    StringBuilder qtiChangelog = new StringBuilder();
    if (qtiChangeLog.length > 0) {
        // there are resource changes
        Arrays.sort(qtiChangeLog);
        for (int i = qtiChangeLog.length - 1; i >= 0; i--) {
            // show latest change first
            if (!showAll && qtiChangeLog[i].isPublic()) {
                // logged in person is a normal user, hence public messages only
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            } else if (showAll) {
                // logged in person is an author, olat admin, owner, show all messages
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            }
        // else non public messages are not shown to normal user
        }
    }
    return qtiChangelog;
}
Also used : QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) Formatter(org.olat.core.util.Formatter) ImsRepositoryResolver(org.olat.ims.qti.process.ImsRepositoryResolver) Roles(org.olat.core.id.Roles) Date(java.util.Date)

Example 14 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentRunController method blockedBasedOnDate.

private boolean blockedBasedOnDate() {
    mainVC.contextRemove("startTestDate");
    mainVC.contextRemove("endTestDate");
    boolean dependOnDate = config.getBooleanSafe(IQEditController.CONFIG_KEY_DATE_DEPENDENT_TEST, false);
    if (dependOnDate) {
        Date startTestDate = config.getDateValue(IQEditController.CONFIG_KEY_RESULTS_START_TEST_DATE);
        if (startTestDate != null) {
            Formatter formatter = Formatter.getInstance(getLocale());
            mainVC.contextPut("startTestDate", formatter.formatDateAndTime(startTestDate));
            Date endTestDate = config.getDateValue(IQEditController.CONFIG_KEY_RESULTS_END_TEST_DATE);
            if (endTestDate != null) {
                mainVC.contextPut("endTestDate", formatter.formatDateAndTime(endTestDate));
            }
            Date now = new Date();
            if (startTestDate != null && startTestDate.after(now)) {
                return true;
            }
            if (endTestDate != null && endTestDate.before(now)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 15 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentRunController method exposeVisiblityPeriod.

private void exposeVisiblityPeriod() {
    boolean showResultsActive = config.getBooleanSafe(IQEditController.CONFIG_KEY_DATE_DEPENDENT_RESULTS);
    Date startDate = config.getDateValue(IQEditController.CONFIG_KEY_RESULTS_START_DATE);
    Date endDate = config.getDateValue(IQEditController.CONFIG_KEY_RESULTS_END_DATE);
    if (showResultsActive && startDate != null) {
        Formatter formatter = Formatter.getInstance(getLocale());
        String visibilityStartDate = formatter.formatDate(startDate);
        String visibilityEndDate = "-";
        if (endDate != null) {
            visibilityEndDate = formatter.formatDate(endDate);
        }
        String visibilityPeriod = translate("showResults.visibility", new String[] { visibilityStartDate, visibilityEndDate });
        mainVC.contextPut("visibilityPeriod", visibilityPeriod);
    } else {
        mainVC.contextPut("visibilityPeriod", translate("showResults.visibility.future"));
    }
}
Also used : Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

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