use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.
the class LectureBlockExport method addHeaders_1.
private void addHeaders_1(OpenXMLWorksheet exportSheet) {
Row headerRow = exportSheet.newRow();
int pos = 0;
Formatter formatter = Formatter.getInstance(translator.getLocale());
String[] args = new String[] { lectureBlock.getTitle(), formatter.formatDate(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getEndDate()) };
headerRow.addCell(pos, translator.translate("export.header.lectureblocks", args));
if (isAdministrativeUser) {
pos++;
}
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
pos++;
}
if (teachers != null && teachers.size() > 0) {
StringBuilder sb = new StringBuilder();
for (Identity teacher : teachers) {
if (sb.length() > 0)
sb.append(", ");
sb.append(userManager.getUserDisplayName(teacher));
}
headerRow.addCell(pos, translator.translate("export.header.teachers", new String[] { sb.toString() }));
}
if (StringHelper.containsNonWhitespace(lectureBlock.getLocation())) {
pos += lectureBlock.getPlannedLecturesNumber();
headerRow.addCell(pos, translator.translate("export.header.location", new String[] { lectureBlock.getLocation() }));
}
}
use of org.olat.core.util.Formatter in project openolat by klemens.
the class RollCallInterceptorController method isUserInteractionRequired.
@Override
public boolean isUserInteractionRequired(UserRequest ureq) {
if (lectureModule.isEnabled()) {
List<LectureBlock> lectureBlocks = lectureService.getRollCallAsTeacher(ureq.getIdentity());
if (lectureBlocks.size() > 0) {
Formatter format = Formatter.getInstance(getLocale());
lectureBlockToStart = lectureBlocks.get(0);
String[] args = new String[] { lectureBlockToStart.getEntry().getDisplayname(), lectureBlockToStart.getEntry().getExternalRef() == null ? "" : lectureBlockToStart.getEntry().getExternalRef(), lectureBlockToStart.getTitle(), (lectureBlockToStart.getStartDate() == null ? "" : format.formatDate(lectureBlockToStart.getStartDate())), (lectureBlockToStart.getStartDate() == null ? "" : format.formatTimeShort(lectureBlockToStart.getStartDate())), (lectureBlockToStart.getEndDate() == null ? "" : format.formatTimeShort(lectureBlockToStart.getEndDate())) };
flc.contextPut("message", translate("interceptor.start", args));
}
}
return lectureBlockToStart != null;
}
use of org.olat.core.util.Formatter in project openolat by klemens.
the class TeacherRollCallController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
StringBuilder sb = new StringBuilder();
List<Identity> teachers = lectureService.getTeachers(lectureBlock);
for (Identity teacher : teachers) {
if (sb.length() > 0)
sb.append(", ");
sb.append(StringHelper.escapeHtml(userManager.getUserDisplayName(teacher)));
}
Formatter formatter = Formatter.getInstance(getLocale());
String date = formatter.formatDate(lectureBlock.getStartDate());
String startTime = formatter.formatTimeShort(lectureBlock.getStartDate());
String endTime = formatter.formatTimeShort(lectureBlock.getEndDate());
String[] args = new String[] { // {0}
lectureBlock.getTitle(), // {1}
sb.toString(), // {2}
date, // {3}
startTime, // {4}
endTime };
layoutCont.contextPut("date", date);
layoutCont.contextPut("startTime", startTime);
layoutCont.contextPut("endTime", endTime);
layoutCont.contextPut("dateAndTime", translate("lecture.block.dateAndTime", args));
layoutCont.contextPut("teachers", sb.toString());
layoutCont.contextPut("lectureBlockTitle", StringHelper.escapeHtml(lectureBlock.getTitle()));
layoutCont.contextPut("lectureBlockExternalId", StringHelper.escapeHtml(lectureBlock.getExternalId()));
StringBuilder description = Formatter.stripTabsAndReturns(Formatter.formatURLsAsLinks(lectureBlock.getDescription()));
layoutCont.contextPut("lectureBlockDescription", StringHelper.xssScan(description));
StringBuilder preparation = Formatter.stripTabsAndReturns(Formatter.formatURLsAsLinks(lectureBlock.getPreparation()));
layoutCont.contextPut("lectureBlockPreparation", StringHelper.xssScan(preparation));
layoutCont.contextPut("lectureBlockLocation", StringHelper.escapeHtml(lectureBlock.getLocation()));
layoutCont.contextPut("lectureBlock", lectureBlock);
layoutCont.contextPut("lectureBlockOptional", !lectureBlock.isCompulsory());
layoutCont.setFormTitle(translate("lecture.block", args));
layoutCont.setFormDescription(StringHelper.escapeJavaScript(lectureBlock.getDescription()));
}
// table
FlexiTableSortOptions options = new FlexiTableSortOptions();
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(RollCols.username));
options.setDefaultOrderBy(new SortKey(RollCols.username.sortKey(), true));
}
int colPos = USER_PROPS_OFFSET;
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
String propName = userPropertyHandler.getName();
boolean visible = userManager.isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
FlexiColumnModel col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName);
columnsModel.addFlexiColumnModel(col);
colPos++;
if (!options.hasDefaultOrderBy()) {
options.setDefaultOrderBy(new SortKey(propName, true));
} else if (UserConstants.LASTNAME.equals(propName)) {
options.setDefaultOrderBy(new SortKey(propName, true));
}
}
if (lectureBlock.isCompulsory()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(RollCols.status));
for (int i = 0; i < numOfLectures; i++) {
DefaultFlexiColumnModel col = new DefaultFlexiColumnModel("table.header.lecture." + (i + 1), i + CHECKBOX_OFFSET, true, "lecture." + (i + 1));
col.setAlwaysVisible(true);
columnsModel.addFlexiColumnModel(col);
}
// all button
DefaultFlexiColumnModel allCol = new DefaultFlexiColumnModel("all", RollCols.all.ordinal(), "all", new BooleanCellRenderer(new StaticFlexiCellRenderer(translate("all"), "all", null, null, translate("all.desc")), null));
allCol.setAlwaysVisible(true);
columnsModel.addFlexiColumnModel(allCol);
if (secCallback.canViewAuthorizedAbsences() || secCallback.canEditAuthorizedAbsences()) {
DefaultFlexiColumnModel authorizedCol = new DefaultFlexiColumnModel(RollCols.authorizedAbsence);
authorizedCol.setAlwaysVisible(true);
columnsModel.addFlexiColumnModel(authorizedCol);
}
}
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(RollCols.comment));
tableModel = new TeacherRollCallDataModel(columnsModel, secCallback, getLocale());
tableEl = uifactory.addTableElement(getWindowControl(), "table", tableModel, 20, false, getTranslator(), formLayout);
tableEl.setCustomizeColumns(true);
tableEl.setSortSettings(options);
tableEl.setAndLoadPersistedPreferences(ureq, "teacher-roll-call");
// buttons
uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
quickSaveButton = uifactory.addFormSubmitButton("save", "save.temporary", formLayout);
quickSaveButton.setElementCssClass("o_sel_lecture_quick_save");
closeLectureBlocksButton = uifactory.addFormLink("close.lecture.blocks", formLayout, Link.BUTTON);
closeLectureBlocksButton.setElementCssClass("o_sel_lecture_close");
if (lectureModule.isStatusCancelledEnabled()) {
cancelLectureBlockButton = uifactory.addFormLink("cancel.lecture.blocks", formLayout, Link.BUTTON);
}
reopenButton = uifactory.addFormLink("reopen.lecture.blocks", formLayout, Link.BUTTON);
reopenButton.setElementCssClass("o_sel_lecture_reopen");
updateUI();
}
use of org.olat.core.util.Formatter in project openolat by klemens.
the class IQComponentRenderer method buildMenu.
/**
* Method buildMenu.
*
* @return DOCUMENT ME!
*/
private StringOutput buildMenu(IQComponent comp, Translator translator, Renderer r, URLBuilder ubu) {
StringOutput sb = new StringOutput();
AssessmentInstance ai = comp.getAssessmentInstance();
AssessmentContext ac = ai.getAssessmentContext();
boolean renderSectionTitlesOnly = comp.getMenuDisplayConf().isRenderSectionsOnly();
sb.append("<div id=\"o_qti_menu\">");
sb.append("<h4>");
sb.append(StringHelper.escapeHtml(ac.getTitle()));
sb.append("</h4>");
sb.append("<table border=0 width=\"100%\">");
// append assessment navigation
Formatter formatter = Formatter.getInstance(translator.getLocale());
int scnt = ac.getSectionContextCount();
for (int i = 0; i < scnt; i++) {
SectionContext sc = ac.getSectionContext(i);
boolean clickable = (ai.isSectionPage() && sc.isOpen()) || (!ai.isSectionPage());
clickable = clickable && !ai.isClosed();
clickable = clickable && ai.isMenu();
sb.append("<tr>");
sb.append(addSectionLink(r, ubu, formatter, sc, i, clickable, ac.getCurrentSectionContextPos() == i, ai.isSectionPage()));
sb.append("</tr>");
if (!renderSectionTitlesOnly) {
// not only sections, but render questions to
int icnt = sc.getItemContextCount();
for (int j = 0; j < icnt; j++) {
ItemContext itc = sc.getItemContext(j);
clickable = !ai.isSectionPage() && sc.isOpen() && itc.isOpen();
clickable = clickable && !ai.isClosed();
clickable = clickable && ai.isMenu();
sb.append("<tr>");
sb.append(addItemLink(r, ubu, formatter, ai, itc, i, j, clickable, (ac.getCurrentSectionContextPos() == i && sc.getCurrentItemContextPos() == j), !ai.isSurvey()));
sb.append("</tr>");
}
}
}
sb.append("</table>");
sb.append("</div>");
return sb;
}
use of org.olat.core.util.Formatter in project openolat by klemens.
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();
}
Aggregations