Search in sources :

Example 1 with SendTime

use of org.olat.modules.reminder.model.SendTime in project OpenOLAT by OpenOLAT.

the class ReminderModule method getCronExpression.

protected String getCronExpression() {
    StringBuilder sb = new StringBuilder();
    int hour = 9;
    int minute = 0;
    SendTime parsedTime = SendTime.parse(getDefaultSendTime());
    if (parsedTime.isValid()) {
        hour = parsedTime.getHour();
        minute = parsedTime.getMinute();
    }
    ReminderInterval intervalVal = ReminderInterval.byKey(getInterval());
    String cronInterval;
    if (intervalVal != null && !ReminderInterval.every24.equals(intervalVal)) {
        int i = intervalVal.interval();
        if (i < hour) {
            // correct the first time the cron job starts
            int rest = hour % i;
            hour = rest;
        }
        cronInterval = "/" + intervalVal.interval();
    } else {
        // or 24 hours
        cronInterval = "";
    }
    sb.append("0 ").append(minute).append(" ").append(hour).append(cronInterval).append(" * * ?");
    return sb.toString();
}
Also used : SendTime(org.olat.modules.reminder.model.SendTime)

Example 2 with SendTime

use of org.olat.modules.reminder.model.SendTime in project openolat by klemens.

the class ReminderModule method getCronExpression.

protected String getCronExpression() {
    StringBuilder sb = new StringBuilder();
    int hour = 9;
    int minute = 0;
    SendTime parsedTime = SendTime.parse(getDefaultSendTime());
    if (parsedTime.isValid()) {
        hour = parsedTime.getHour();
        minute = parsedTime.getMinute();
    }
    ReminderInterval intervalVal = ReminderInterval.byKey(getInterval());
    String cronInterval;
    if (intervalVal != null && !ReminderInterval.every24.equals(intervalVal)) {
        int i = intervalVal.interval();
        if (i < hour) {
            // correct the first time the cron job starts
            int rest = hour % i;
            hour = rest;
        }
        cronInterval = "/" + intervalVal.interval();
    } else {
        // or 24 hours
        cronInterval = "";
    }
    sb.append("0 ").append(minute).append(" ").append(hour).append(cronInterval).append(" * * ?");
    return sb.toString();
}
Also used : SendTime(org.olat.modules.reminder.model.SendTime)

Example 3 with SendTime

use of org.olat.modules.reminder.model.SendTime in project OpenOLAT by OpenOLAT.

the class ReminderAdminController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("reminder.admin.title");
    String[] enableValues = new String[] { translate("on") };
    enableEl = uifactory.addCheckboxesHorizontal("enable.reminders", formLayout, enableKeys, enableValues);
    enableEl.addActionListener(FormEvent.ONCHANGE);
    enableEl.select(enableKeys[0], reminderModule.isEnabled());
    String interval = reminderModule.getInterval();
    intervalEl = uifactory.addDropdownSingleselect("interval", formLayout, intervalKeys, intervalValues, null);
    boolean found = false;
    if (StringHelper.containsNonWhitespace(interval)) {
        for (String intervalKey : intervalKeys) {
            if (intervalKey.equals(interval)) {
                intervalEl.select(intervalKey, true);
                found = true;
            }
        }
    }
    if (!found) {
        intervalEl.select(intervalKeys[0], true);
    }
    int hour = 9;
    int minute = 0;
    SendTime parsedTime = SendTime.parse(reminderModule.getDefaultSendTime());
    if (parsedTime.isValid()) {
        hour = parsedTime.getHour();
        minute = parsedTime.getMinute();
    }
    String timePage = velocity_root + "/time.html";
    timeLayout = FormLayoutContainer.createCustomFormLayout("send.time", getTranslator(), timePage);
    timeLayout.setRootForm(mainForm);
    formLayout.add(timeLayout);
    timeLayout.setLabel("default.send.time", null);
    String hourStr = (hour < 10 ? "0" : "") + hour;
    hoursEl = uifactory.addTextElement("hours", null, 2, hourStr, timeLayout);
    hoursEl.setDisplaySize(2);
    hoursEl.setDomReplacementWrapperRequired(false);
    String minuteStr = (minute < 10 ? "0" : "") + minute;
    minutesEl = uifactory.addTextElement("minutes", null, 2, minuteStr, timeLayout);
    minutesEl.setDisplaySize(2);
    minutesEl.setDomReplacementWrapperRequired(false);
    String[] timezoneKeys = TimeZone.getAvailableIDs();
    String[] timezoneValues = new String[timezoneKeys.length];
    for (int i = timezoneKeys.length; i-- > 0; ) {
        timezoneValues[i] = timezoneKeys[i] + " (" + TimeZone.getTimeZone(timezoneKeys[i]).getDisplayName(true, TimeZone.LONG, getLocale()) + ")";
    }
    timezoneEl = uifactory.addDropdownSingleselect("timezone", timeLayout, timezoneKeys, timezoneValues, null);
    timezoneEl.setEnabled(false);
    ((AbstractComponent) timezoneEl.getComponent()).setDomReplacementWrapperRequired(false);
    TimeZone defaultTimeZone = reminderModule.getDefaultSendTimeZone();
    for (int i = timezoneKeys.length; i-- > 0; ) {
        if (defaultTimeZone.getID().equals(timezoneKeys[i])) {
            timezoneEl.select(defaultTimeZone.getID(), true);
        }
    }
    timeLayout.setVisible(reminderModule.isEnabled());
    /*
		enableSmsEl = uifactory.addCheckboxesHorizontal("enable.sms.reminders", formLayout, enableKeys, enableValues);
		enableSmsEl.addActionListener(FormEvent.ONCHANGE);
		enableSmsEl.select(enableKeys[0], reminderModule.isSmsEnabled());
		enableSmsEl.setVisible(reminderModule.isEnabled());
		*/
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsCont.setRootForm(mainForm);
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("save", buttonsCont);
}
Also used : SendTime(org.olat.modules.reminder.model.SendTime) AbstractComponent(org.olat.core.gui.components.AbstractComponent) TimeZone(java.util.TimeZone) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 4 with SendTime

use of org.olat.modules.reminder.model.SendTime in project OpenOLAT by OpenOLAT.

the class CourseReminderEditController method getSendTimeDescription.

protected String getSendTimeDescription() {
    String interval = reminderModule.getInterval();
    String desc = translate("interval." + interval);
    String time;
    SendTime parsedTime = SendTime.parse(reminderModule.getDefaultSendTime());
    if (parsedTime.isValid()) {
        int hour = parsedTime.getHour();
        int minute = parsedTime.getMinute();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, minute);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        time = Formatter.getInstance(getLocale()).formatTimeShort(cal.getTime());
    } else {
        time = "ERROR";
    }
    String descText = translate("send.time.description", new String[] { desc, time });
    String infoText = "<br /><em class='text-muted'>" + translate("send.time.info") + "</em>";
    return descText + infoText;
}
Also used : SendTime(org.olat.modules.reminder.model.SendTime) Calendar(java.util.Calendar)

Example 5 with SendTime

use of org.olat.modules.reminder.model.SendTime in project openolat by klemens.

the class ReminderAdminController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("reminder.admin.title");
    String[] enableValues = new String[] { translate("on") };
    enableEl = uifactory.addCheckboxesHorizontal("enable.reminders", formLayout, enableKeys, enableValues);
    enableEl.addActionListener(FormEvent.ONCHANGE);
    enableEl.select(enableKeys[0], reminderModule.isEnabled());
    String interval = reminderModule.getInterval();
    intervalEl = uifactory.addDropdownSingleselect("interval", formLayout, intervalKeys, intervalValues, null);
    boolean found = false;
    if (StringHelper.containsNonWhitespace(interval)) {
        for (String intervalKey : intervalKeys) {
            if (intervalKey.equals(interval)) {
                intervalEl.select(intervalKey, true);
                found = true;
            }
        }
    }
    if (!found) {
        intervalEl.select(intervalKeys[0], true);
    }
    int hour = 9;
    int minute = 0;
    SendTime parsedTime = SendTime.parse(reminderModule.getDefaultSendTime());
    if (parsedTime.isValid()) {
        hour = parsedTime.getHour();
        minute = parsedTime.getMinute();
    }
    String timePage = velocity_root + "/time.html";
    timeLayout = FormLayoutContainer.createCustomFormLayout("send.time", getTranslator(), timePage);
    timeLayout.setRootForm(mainForm);
    formLayout.add(timeLayout);
    timeLayout.setLabel("default.send.time", null);
    String hourStr = (hour < 10 ? "0" : "") + hour;
    hoursEl = uifactory.addTextElement("hours", null, 2, hourStr, timeLayout);
    hoursEl.setDisplaySize(2);
    hoursEl.setDomReplacementWrapperRequired(false);
    String minuteStr = (minute < 10 ? "0" : "") + minute;
    minutesEl = uifactory.addTextElement("minutes", null, 2, minuteStr, timeLayout);
    minutesEl.setDisplaySize(2);
    minutesEl.setDomReplacementWrapperRequired(false);
    String[] timezoneKeys = TimeZone.getAvailableIDs();
    String[] timezoneValues = new String[timezoneKeys.length];
    for (int i = timezoneKeys.length; i-- > 0; ) {
        timezoneValues[i] = timezoneKeys[i] + " (" + TimeZone.getTimeZone(timezoneKeys[i]).getDisplayName(true, TimeZone.LONG, getLocale()) + ")";
    }
    timezoneEl = uifactory.addDropdownSingleselect("timezone", timeLayout, timezoneKeys, timezoneValues, null);
    timezoneEl.setEnabled(false);
    ((AbstractComponent) timezoneEl.getComponent()).setDomReplacementWrapperRequired(false);
    TimeZone defaultTimeZone = reminderModule.getDefaultSendTimeZone();
    for (int i = timezoneKeys.length; i-- > 0; ) {
        if (defaultTimeZone.getID().equals(timezoneKeys[i])) {
            timezoneEl.select(defaultTimeZone.getID(), true);
        }
    }
    timeLayout.setVisible(reminderModule.isEnabled());
    /*
		enableSmsEl = uifactory.addCheckboxesHorizontal("enable.sms.reminders", formLayout, enableKeys, enableValues);
		enableSmsEl.addActionListener(FormEvent.ONCHANGE);
		enableSmsEl.select(enableKeys[0], reminderModule.isSmsEnabled());
		enableSmsEl.setVisible(reminderModule.isEnabled());
		*/
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsCont.setRootForm(mainForm);
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("save", buttonsCont);
}
Also used : SendTime(org.olat.modules.reminder.model.SendTime) AbstractComponent(org.olat.core.gui.components.AbstractComponent) TimeZone(java.util.TimeZone) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

SendTime (org.olat.modules.reminder.model.SendTime)6 Calendar (java.util.Calendar)2 TimeZone (java.util.TimeZone)2 AbstractComponent (org.olat.core.gui.components.AbstractComponent)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2