Search in sources :

Example 36 with ReminderRuleImpl

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

the class RepositoryEntryRoleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Translator translator = formLayout.getTranslator();
    String[] values = new String[] { translator.translate("course.role.owner"), translator.translate("course.role.coach"), translator.translate("course.role.participant"), translator.translate("course.role.participantAndCoach"), translator.translate("course.role.ownerAndCoach"), translator.translate("course.role.all") };
    roleEl = uifactory.addDropdownSingleselect("role." + CodeHelper.getRAMUniqueID(), null, formLayout, keys, values, null);
    boolean selected = false;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl roleRule = (ReminderRuleImpl) rule;
        String role = roleRule.getRightOperand();
        for (String key : keys) {
            if (key.equals(role)) {
                roleEl.select(key, true);
                selected = true;
            }
        }
    }
    if (!selected) {
        roleEl.select(keys[0], true);
    }
    return roleEl;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl)

Example 37 with ReminderRuleImpl

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

the class UserPropertyEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/user_prop.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    FormLayoutContainer userPropCont = FormLayoutContainer.createCustomFormLayout("user.prop.".concat(id), formLayout.getTranslator(), page);
    userPropCont.setRootForm(formLayout.getRootForm());
    formLayout.add(userPropCont);
    userPropCont.getFormItemComponent().contextPut("id", id);
    Translator trans = Util.createPackageTranslator(UserPropertyHandler.class, ureq.getLocale(), formLayout.getTranslator());
    int numOfProperties = userPropertyHandlers.size();
    String[] propKeys = new String[numOfProperties];
    String[] propValues = new String[numOfProperties];
    for (int i = 0; i < numOfProperties; i++) {
        UserPropertyHandler handler = userPropertyHandlers.get(i);
        propKeys[i] = handler.getName();
        propValues[i] = trans.translate(handler.i18nFormElementLabelKey());
    }
    String currentPropertyName = null;
    String currentPropertyValue = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentPropertyName = r.getLeftOperand();
        currentPropertyValue = r.getRightOperand();
    }
    propEl = uifactory.addDropdownSingleselect("user.prop.".concat(id), null, userPropCont, propKeys, propValues, null);
    propEl.setDomReplacementWrapperRequired(false);
    if (currentPropertyName != null) {
        for (String propKey : propKeys) {
            if (currentPropertyName.equals(propKey)) {
                propEl.select(propKey, true);
            }
        }
    }
    valueEl = uifactory.addTextElement("user.value.".concat(id), null, 128, currentPropertyValue, userPropCont);
    valueEl.setDomReplacementWrapperRequired(false);
    return userPropCont;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 38 with ReminderRuleImpl

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

the class ReminderServiceImpl method optimizeStartDate.

private void optimizeStartDate(Reminder reminder) {
    Date startDate = null;
    String configuration = reminder.getConfiguration();
    if (StringHelper.containsNonWhitespace(configuration)) {
        ReminderRules rules = toRules(configuration);
        for (ReminderRule rule : rules.getRules()) {
            if (rule instanceof ReminderRuleImpl && ReminderRuleEngine.DATE_RULE_TYPE.equals(rule.getType())) {
                ReminderRuleImpl r = (ReminderRuleImpl) rule;
                if (DateRuleSPI.AFTER.equals(r.getOperator()) && StringHelper.containsNonWhitespace(r.getRightOperand())) {
                    try {
                        Date date = Formatter.parseDatetime(r.getRightOperand());
                        if (startDate == null) {
                            startDate = date;
                        } else if (startDate.compareTo(date) > 0) {
                            startDate = date;
                        }
                    } catch (ParseException e) {
                        log.error("", e);
                    }
                }
            }
        }
    }
    ((ReminderImpl) reminder).setStartDate(startDate);
}
Also used : ReminderRule(org.olat.modules.reminder.ReminderRule) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ReminderRules(org.olat.modules.reminder.model.ReminderRules) ReminderImpl(org.olat.modules.reminder.model.ReminderImpl) ParseException(java.text.ParseException) Date(java.util.Date)

Example 39 with ReminderRuleImpl

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

the class AbstractLaunchDateRuleSPI method filter.

@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        Date now = new Date();
        int distance = Integer.parseInt(r.getRightOperand());
        LaunchUnit unit = LaunchUnit.valueOf(r.getRightUnit());
        Map<Long, Date> initialLaunchDates = getLaunchDates(rule, entry, identities);
        for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
            Identity identity = identityIt.next();
            Date initialLaunchDate = initialLaunchDates.get(identity.getKey());
            if (initialLaunchDate == null) {
                identityIt.remove();
            } else if (!after(initialLaunchDate, now, distance, unit)) {
                identityIt.remove();
            }
        }
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 40 with ReminderRuleImpl

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

the class BusinessGroupRoleRuleSPI method clone.

@Override
public ReminderRule clone(ReminderRule rule, CourseEnvironmentMapper envMapper) {
    ReminderRuleImpl clone = (ReminderRuleImpl) rule.clone();
    String groupKey = clone.getRightOperand();
    boolean found = false;
    if (StringHelper.isLong(groupKey)) {
        Long key = Long.parseLong(groupKey);
        for (BusinessGroupReference ref : envMapper.getGroups()) {
            if (key.equals(ref.getOriginalKey()) && ref.getKey() != null) {
                clone.setRightOperand(ref.getKey().toString());
                found = true;
            }
        }
    }
    return found ? clone : null;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) BusinessGroupReference(org.olat.group.model.BusinessGroupReference)

Aggregations

ReminderRuleImpl (org.olat.modules.reminder.model.ReminderRuleImpl)114 ArrayList (java.util.ArrayList)46 Identity (org.olat.core.id.Identity)26 ReminderRule (org.olat.modules.reminder.ReminderRule)26 ICourse (org.olat.course.ICourse)22 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)20 CourseNode (org.olat.course.nodes.CourseNode)20 Test (org.junit.Test)16 Date (java.util.Date)14 Translator (org.olat.core.gui.translator.Translator)14 GTACourseNode (org.olat.course.nodes.GTACourseNode)14 List (java.util.List)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 TaskList (org.olat.course.nodes.gta.TaskList)10 Calendar (java.util.Calendar)8 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)8 ParseException (java.text.ParseException)6 InitialAttemptsRuleSPI (org.olat.course.reminder.rule.InitialAttemptsRuleSPI)6 ScoreRuleSPI (org.olat.course.reminder.rule.ScoreRuleSPI)6 File (java.io.File)4