Search in sources :

Example 6 with Formatter

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

the class CertificatePhantomWorker method fillRepositoryEntry.

private void fillRepositoryEntry(VelocityContext context) {
    String title = entry.getDisplayname();
    context.put("title", title);
    String description = entry.getDescription();
    context.put("description", description);
    String requirements = entry.getRequirements();
    context.put("requirements", requirements);
    String objectives = entry.getObjectives();
    context.put("objectives", objectives);
    String credits = entry.getCredits();
    context.put("credits", credits);
    String externalRef = entry.getExternalRef();
    context.put("externalReference", externalRef);
    String authors = entry.getAuthors();
    context.put("authors", authors);
    String expenditureOfWorks = entry.getExpenditureOfWork();
    context.put("expenditureOfWorks", expenditureOfWorks);
    String mainLanguage = entry.getMainLanguage();
    context.put("mainLanguage", mainLanguage);
    if (entry.getLifecycle() != null) {
        Formatter format = Formatter.getInstance(locale);
        Date from = entry.getLifecycle().getValidFrom();
        String formattedFrom = format.formatDate(from);
        context.put("from", formattedFrom);
        String formattedFromLong = format.formatDateLong(from);
        context.put("fromLong", formattedFromLong);
        Date to = entry.getLifecycle().getValidTo();
        String formattedTo = format.formatDate(to);
        context.put("to", formattedTo);
        String formattedToLong = format.formatDateLong(to);
        context.put("toLong", formattedToLong);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) Date(java.util.Date)

Example 7 with Formatter

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

the class CalendarNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
        Long id = p.getResId();
        String type = p.getSubidentifier();
        try {
            Translator translator = Util.createPackageTranslator(CalendarModule.class, locale);
            String calType = null;
            String title = null;
            if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                String displayName = re.getDisplayname();
                calType = CalendarManager.TYPE_COURSE;
                title = translator.translate("cal.notifications.header.course", new String[] { displayName });
            } else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
                BusinessGroup group = businessGroupDao.load(id);
                calType = CalendarManager.TYPE_GROUP;
                if (group == null) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
                title = translator.translate("cal.notifications.header.group", new String[] { group.getName() });
            }
            if (calType != null) {
                Formatter form = Formatter.getInstance(locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_CALENDAR_ICON), null);
                String bPath;
                if (StringHelper.containsNonWhitespace(p.getBusinessPath())) {
                    bPath = p.getBusinessPath();
                } else if ("CalendarManager.course".equals(p.getResName())) {
                    try {
                        OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.getCourseTypeName(), p.getResId());
                        RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, true);
                        // Fallback
                        bPath = "[RepositoryEntry:" + re.getKey() + "]";
                    } catch (Exception e) {
                        log.error("Error processing calendar notifications of publisher:" + p.getKey(), e);
                        return notificationsManager.getNoSubscriptionInfo();
                    }
                } else {
                    // cannot make link without business path
                    return notificationsManager.getNoSubscriptionInfo();
                }
                Kalendar cal = calendarManager.getCalendar(calType, id.toString());
                Collection<KalendarEvent> calEvents = cal.getEvents();
                for (KalendarEvent kalendarEvent : calEvents) {
                    if (showEvent(compareDate, kalendarEvent)) {
                        log.debug("found a KalendarEvent: " + kalendarEvent.getSubject() + " with time: " + kalendarEvent.getBegin() + " modified before: " + compareDate.toString(), null);
                        // found a modified event in this calendar
                        Date modDate = null;
                        if (kalendarEvent.getLastModified() > 0) {
                            modDate = new Date(kalendarEvent.getLastModified());
                        } else if (kalendarEvent.getCreated() > 0) {
                            modDate = new Date(kalendarEvent.getCreated());
                        } else if (kalendarEvent.getBegin() != null) {
                            modDate = kalendarEvent.getBegin();
                        }
                        String subject = kalendarEvent.getSubject();
                        String author = kalendarEvent.getCreatedBy();
                        if (author == null)
                            author = "";
                        String location = "";
                        if (StringHelper.containsNonWhitespace(kalendarEvent.getLocation())) {
                            location = kalendarEvent.getLocation() == null ? "" : translator.translate("cal.notifications.location", new String[] { kalendarEvent.getLocation() });
                        }
                        String dateStr;
                        if (kalendarEvent.isAllDayEvent()) {
                            dateStr = form.formatDate(kalendarEvent.getBegin());
                        } else {
                            dateStr = form.formatDate(kalendarEvent.getBegin()) + " - " + form.formatDate(kalendarEvent.getEnd());
                        }
                        String desc = translator.translate("cal.notifications.entry", new String[] { subject, dateStr, location, author });
                        String businessPath = bPath + "[path=" + kalendarEvent.getID() + ":0]";
                        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                        SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_CALENDAR_ICON);
                        si.addSubscriptionListItem(subListItem);
                    }
                }
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            checkPublisher(p);
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } else {
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) Formatter(org.olat.core.util.Formatter) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Kalendar(org.olat.commons.calendar.model.Kalendar) Translator(org.olat.core.gui.translator.Translator)

Example 8 with Formatter

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

the class PortfolioAssessmentDetailsController method loadModel.

private void loadModel(UserRequest ureq, Binder loadedBinder) {
    if (loadedBinder == null) {
        mainVC.contextPut("noMap", Boolean.TRUE);
    } else {
        Formatter formatter = Formatter.getInstance(getLocale());
        String templateTitle = loadedBinder.getTemplate().getTitle();
        mainVC.contextPut("templateTitle", templateTitle);
        String copyDate = "";
        if (loadedBinder.getCopyDate() != null) {
            copyDate = formatter.formatDateAndTime(loadedBinder.getCopyDate());
        }
        mainVC.contextPut("copyDate", copyDate);
        String returnDate = "";
        if (loadedBinder.getReturnDate() != null) {
            returnDate = formatter.formatDateAndTime(loadedBinder.getReturnDate());
        }
        mainVC.contextPut("returnDate", returnDate);
        List<AccessRights> rights = portfolioService.getAccessRights(loadedBinder, getIdentity());
        BinderSecurityCallback secCallback = BinderSecurityCallbackFactory.getCallbackForCourseCoach(loadedBinder, rights);
        BinderConfiguration config = BinderConfiguration.createConfig(loadedBinder);
        assessmentCtrl = new BinderAssessmentController(ureq, getWindowControl(), secCallback, loadedBinder, config);
        listenTo(assessmentCtrl);
        mainVC.put("assessment", assessmentCtrl.getInitialComponent());
    }
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) Formatter(org.olat.core.util.Formatter) BinderSecurityCallback(org.olat.modules.portfolio.BinderSecurityCallback) BinderConfiguration(org.olat.modules.portfolio.BinderConfiguration)

Example 9 with Formatter

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

the class ParticipantLectureBlocksController method loadModel.

private void loadModel() {
    Date now = new Date();
    Formatter formatter = Formatter.getInstance(getLocale());
    String separator = translate("user.fullname.separator");
    List<LectureBlockAndRollCall> rollCalls = lectureService.getParticipantLectureBlocks(entry, assessedIdentity, separator);
    List<LectureBlockAuditLog> sendAppealLogs = lectureService.getAuditLog(entry, assessedIdentity, LectureBlockAuditLog.Action.sendAppeal);
    Map<Long, Date> appealDates = new HashMap<>();
    for (LectureBlockAuditLog sendAppealLog : sendAppealLogs) {
        if (sendAppealLog.getRollCallKey() != null) {
            appealDates.put(sendAppealLog.getRollCallKey(), sendAppealLog.getCreationDate());
        }
    }
    List<LectureBlockAndRollCallRow> rows = new ArrayList<>(rollCalls.size());
    for (LectureBlockAndRollCall rollCall : rollCalls) {
        LectureBlockAndRollCallRow row = new LectureBlockAndRollCallRow(rollCall);
        if (appealEnabled && !LectureBlockStatus.cancelled.equals(row.getRow().getStatus()) && rollCall.isCompulsory()) {
            int lectures = row.getRow().getEffectiveLecturesNumber();
            if (lectures <= 0) {
                lectures = row.getRow().getPlannedLecturesNumber();
            }
            int attended = row.getRow().getLecturesAttendedNumber();
            if (attended < lectures) {
                Date date = row.getRow().getDate();
                Calendar cal = Calendar.getInstance();
                cal.setTime(date);
                cal = CalendarUtils.getEndOfDay(cal);
                cal.add(Calendar.DATE, appealOffset);
                Date beginAppeal = CalendarUtils.removeTime(cal.getTime());
                cal.add(Calendar.DATE, appealPeriod);
                Date endAppeal = CalendarUtils.getEndOfDay(cal).getTime();
                Date sendAppealDate = null;
                if (row.getRow().getRollCallRef() != null) {
                    sendAppealDate = appealDates.get(row.getRow().getRollCallRef().getKey());
                }
                FormLink appealLink = null;
                if (sendAppealDate != null) {
                    String appealFrom = translate("appeal.sent", new String[] { formatter.formatDate(sendAppealDate) });
                    appealLink = uifactory.addFormLink("appeal_" + count++, "appealsend", appealFrom, null, flc, Link.LINK | Link.NONTRANSLATED);
                    appealLink.setTitle(translate("appeal.sent.tooltip", new String[] { formatter.formatDate(sendAppealDate), formatter.formatDate(beginAppeal), formatter.formatDate(endAppeal) }));
                    appealLink.setEnabled(false);
                    appealLink.setDomReplacementWrapperRequired(false);
                } else if (now.compareTo(beginAppeal) >= 0 && now.compareTo(endAppeal) <= 0) {
                    appealLink = uifactory.addFormLink("appeal_" + count++, "appeal", translate("appeal"), null, flc, Link.LINK | Link.NONTRANSLATED);
                    appealLink.setTitle(translate("appeal.tooltip", new String[] { formatter.formatDate(beginAppeal), formatter.formatDate(endAppeal) }));
                    appealLink.setUserObject(row);
                // appeal
                } else if (now.compareTo(endAppeal) > 0) {
                    // appeal closed
                    appealLink = uifactory.addFormLink("appeal_" + count++, "aclosed", "appeal.closed", null, flc, Link.LINK);
                    appealLink.setEnabled(false);
                    appealLink.setDomReplacementWrapperRequired(false);
                } else if (now.compareTo(date) >= 0) {
                    // appeal at
                    String appealFrom = translate("appeal.from", new String[] { formatter.formatDate(beginAppeal) });
                    appealLink = uifactory.addFormLink("appeal_" + count++, "appealat", appealFrom, null, flc, Link.LINK | Link.NONTRANSLATED);
                    appealLink.setEnabled(false);
                    appealLink.setDomReplacementWrapperRequired(false);
                }
                row.setAppealButton(appealLink);
            }
        }
        rows.add(row);
    }
    tableModel.setObjects(rows);
    tableEl.reset(true, true, true);
}
Also used : LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) LectureBlockAuditLog(org.olat.modules.lecture.LectureBlockAuditLog) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Date(java.util.Date)

Example 10 with Formatter

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

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;
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) Formatter(org.olat.core.util.Formatter)

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