use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method processSubscribersByEmail.
private void processSubscribersByEmail(Identity ident) {
if (ident.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
// send only to active user
return;
}
String userInterval = getUserIntervalOrDefault(ident);
if ("never".equals(userInterval)) {
return;
}
long start = System.currentTimeMillis();
Date compareDate = getCompareDateFromInterval(userInterval);
Property p = propertyManager.findProperty(ident, null, null, null, LATEST_EMAIL_USER_PROP);
if (p != null) {
Date latestEmail = new Date(p.getLongValue());
if (latestEmail.after(compareDate)) {
// nothing to do
return;
}
}
Date defaultCompareDate = getDefaultCompareDate();
List<Subscriber> subscribers = getSubscribers(ident);
if (subscribers.isEmpty()) {
return;
}
String langPrefs = null;
if (ident.getUser() != null && ident.getUser().getPreferences() != null) {
langPrefs = ident.getUser().getPreferences().getLanguage();
}
Locale locale = I18nManager.getInstance().getLocaleOrDefault(langPrefs);
boolean veto = false;
Subscriber latestSub = null;
List<SubscriptionItem> items = new ArrayList<>();
List<Subscriber> subsToUpdate = new ArrayList<>();
for (Subscriber sub : subscribers) {
Date latestEmail = sub.getLatestEmailed();
SubscriptionItem subsitem = null;
if (latestEmail == null || compareDate.after(latestEmail)) {
// no notif. ever sent until now
if (latestEmail == null) {
latestEmail = defaultCompareDate;
} else if (latestEmail.before(defaultCompareDate)) {
// no notification older than a month
latestEmail = defaultCompareDate;
}
subsitem = createSubscriptionItem(sub, locale, SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, latestEmail);
} else if (latestEmail != null && latestEmail.after(compareDate)) {
// already send an email within the user's settings interval
// veto = true;
}
if (subsitem != null) {
items.add(subsitem);
subsToUpdate.add(sub);
}
latestSub = sub;
}
Translator translator = Util.createPackageTranslator(NotificationSubscriptionController.class, locale);
notifySubscribersByEmail(latestSub, items, subsToUpdate, translator, start, veto);
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class SubscriptionListItem method getHTMLContent.
private String getHTMLContent(Locale locale) {
StringBuilder sb = new StringBuilder();
Translator trans = Util.createPackageTranslator(ContextualSubscriptionController.class, locale);
Formatter form = Formatter.getInstance(locale);
String datePart = trans.translate("subscription.listitem.dateprefix", new String[] { form.formatDateAndTime(date) });
sb.append("<li>");
if (iconCssClass != null) {
sb.append("<i class=\"o_icon o_icon-fw ");
sb.append(iconCssClass);
sb.append("\"></i>");
}
if (StringHelper.containsNonWhitespace(link)) {
sb.append("<a href=\"");
sb.append(link);
sb.append("\">");
}
if (StringHelper.containsNonWhitespace(description)) {
sb.append(new OWASPAntiSamyXSSFilter().filter(description.trim()));
}
if (StringHelper.containsNonWhitespace(link))
sb.append("</a>");
sb.append(" <span class='o_nowrap o_date'>").append(datePart.trim()).append("</span>");
sb.append("</li>");
return sb.toString();
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class NotificationsPortlet method createInstance.
/**
* @see org.olat.gui.control.generic.portal.AbstractPortlet#createInstance(org.olat.core.gui.control.WindowControl, org.olat.core.gui.UserRequest, java.util.Map)
*/
public Portlet createInstance(WindowControl wControl, UserRequest ureq, Map<String, String> configuration) {
Translator translator = Util.createPackageTranslator(NotificationsPortlet.class, ureq.getLocale());
NotificationsPortlet p = new NotificationsPortlet();
p.setName(this.getName());
p.setConfiguration(configuration);
p.setDefaultMaxEntries(getDefaultMaxEntries());
p.setTranslator(translator);
return p;
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class Form method create.
/**
* create a new form, where the caller is attached as component listener.
* Caller receives form validation success or failure events.
*
* @param name
* @param translator
* @param rootFormContainer if null the default layout is choosen, otherwise
* the given layouting container is taken.
* @param listener the component listener of this form, typically the caller
* @return
*/
public static Form create(String id, String name, FormItemContainer formLayout, Controller listener) {
Form form = new Form();
// this is where the formitems go to
form.formLayout = formLayout;
form.formLayout.setRootForm(form);
form.formListeners = new ArrayList<FormBasicController>(1);
if (listener instanceof FormBasicController) {
form.formListeners.add((FormBasicController) listener);
}
Translator translator = formLayout.getTranslator();
if (translator == null) {
throw new AssertException("please provide a translator in the FormItemContainer <" + formLayout.getName() + ">");
}
// renders header + <formLayout> + footer of html form
form.formWrapperComponent = new FormWrapperContainer(id, name, translator, form);
form.formWrapperComponent.addListener(listener);
// form.formWrapperComponent.put(formLayout.getComponent().getComponentName(), formLayout.getComponent());
// generate name for form and dispatch uri hidden field
form.formName = Form.FORMID + form.formWrapperComponent.getDispatchID();
form.dispatchFieldId = form.formName + "_dispatchuri";
form.eventFieldId = form.formName + "_eventval";
return form;
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class FormLayoutContainer method add.
@Override
public void add(String name, FormItem formComp) {
if (!hasRootForm) {
throw new AssertionError("first ensure that the layout container knows about its rootform!!");
}
// set the formtranslator, and parent
Translator itemTranslator = formComp.getTranslator();
if (itemTranslator != null && itemTranslator instanceof PackageTranslator) {
// let the FormItem provide a more specialized translator
PackageTranslator itemPt = (PackageTranslator) itemTranslator;
itemTranslator = PackageTranslator.cascadeTranslators(itemPt, translator);
} else {
itemTranslator = translator;
}
formComp.setTranslator(itemTranslator);
formComp.setRootForm(getRootForm());
//
String formCompName = name;
// book keeping of FormComponent order
formComponentsNames.add(formCompName);
formComponents.put(formCompName, formComp);
/*
* add the gui representation
*/
formLayoutContainer.put(formCompName, formComp.getComponent());
formLayoutContainer.put(formCompName + FormItem.ERRORC, formComp.getErrorC());
formLayoutContainer.put(formCompName + FormItem.EXAMPLEC, formComp.getExampleC());
formLayoutContainer.put(formCompName + FormItem.LABELC, formComp.getLabelC());
// Check for multipart data, add upload limit to form
if (formComp instanceof FormMultipartItem) {
getRootForm().setMultipartEnabled(true);
}
}
Aggregations