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();
}
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);
}
}
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;
}
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;
}
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"));
}
}
Aggregations