Search in sources :

Example 36 with Formatter

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

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)

Example 37 with Formatter

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

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 38 with Formatter

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

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 39 with Formatter

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

the class ConfirmExtraTimeController method currentAssessmentModeMessage.

private void currentAssessmentModeMessage(FormLayoutContainer layoutCont) {
    Formatter formatter = Formatter.getInstance(getLocale());
    List<String> modes = new ArrayList<>();
    for (AssessmentMode assessmentMode : assessmentModes) {
        String title = assessmentMode.getName();
        String begin = formatter.formatDateAndTime(assessmentMode.getBegin());
        String end = formatter.formatDateAndTime(assessmentMode.getEnd());
        modes.add(translate("warning.assessment.mode.date", new String[] { title, begin, end }));
    }
    layoutCont.contextPut("assessmemtModeMessages", modes);
}
Also used : AssessmentMode(org.olat.course.assessment.AssessmentMode) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList)

Example 40 with Formatter

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

the class MailListController method reloadModel.

private void reloadModel() {
    List<DBMailLight> mails;
    if (outbox) {
        if (StringHelper.containsNonWhitespace(metaId)) {
            mails = mailManager.getEmailsByMetaId(metaId);
        } else {
            mails = mailManager.getOutbox(getIdentity(), 0, -1, true);
        }
        // strip meta emails
        Set<String> metaIds = new HashSet<>();
        for (Iterator<DBMailLight> it = mails.iterator(); it.hasNext(); ) {
            DBMailLight mail = it.next();
            if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                if (metaIds.contains(mail.getMetaId())) {
                    it.remove();
                } else {
                    metaIds.add(mail.getMetaId());
                }
            }
        }
    } else {
        mails = mailManager.getInbox(getIdentity(), null, Boolean.TRUE, null, 0, -1);
    }
    // extract contexts
    Map<String, String> bpToContexts = new HashMap<>();
    for (DBMailLight mail : mails) {
        String businessPath = mail.getContext().getBusinessPath();
        if (StringHelper.containsNonWhitespace(businessPath) && !bpToContexts.containsKey(businessPath)) {
            String contextName = contextResolver.getName(businessPath, getLocale());
            if (StringHelper.containsNonWhitespace(contextName)) {
                bpToContexts.put(businessPath, contextName);
            }
        }
    }
    if (!bpToContexts.isEmpty()) {
        List<ShortName> filters = new ArrayList<>();
        Map<String, MailContextShortName> uniqueNames = new HashMap<>();
        ShortName allContextFilter = new MailContextShortName("-");
        filters.add(allContextFilter);
        for (Map.Entry<String, String> entry : bpToContexts.entrySet()) {
            String businessPath = entry.getKey();
            String contextName = entry.getValue();
            if (!uniqueNames.containsKey(contextName)) {
                MailContextShortName cxt = new MailContextShortName(contextName, new HashSet<String>());
                filters.add(cxt);
                uniqueNames.put(contextName, cxt);
            }
            uniqueNames.get(contextName).getBusinessPaths().add(businessPath);
        }
        tableCtr.setFilters(filters, allContextFilter);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    MailDataModel dataModel = new MailDataModel(mails, bpToContexts, getIdentity(), getTranslator(), formatter, outbox);
    tableCtr.setTableDataModel(dataModel);
}
Also used : HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) ShortName(org.olat.core.gui.ShortName) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

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