Search in sources :

Example 81 with ReminderRuleImpl

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

the class ScoreRuleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/score.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
    ruleCont.setRootForm(formLayout.getRootForm());
    formLayout.add(ruleCont);
    ruleCont.getFormItemComponent().contextPut("id", id);
    ICourse course = CourseFactory.loadCourse(entry);
    String currentValue = null;
    String currentOperator = null;
    String currentCourseNode = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentOperator = r.getOperator();
        currentValue = r.getRightOperand();
        currentCourseNode = r.getLeftOperand();
    }
    List<CourseNode> attemptableNodes = new ArrayList<>();
    searchScoreableNodes(course.getRunStructure().getRootNode(), attemptableNodes);
    String[] nodeKeys = new String[attemptableNodes.size()];
    String[] nodeValues = new String[attemptableNodes.size()];
    for (int i = 0; i < attemptableNodes.size(); i++) {
        CourseNode attemptableNode = attemptableNodes.get(i);
        nodeKeys[i] = attemptableNode.getIdent();
        nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
    }
    courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
    courseNodeEl.setDomReplacementWrapperRequired(false);
    boolean nodeSelected = false;
    if (currentCourseNode != null) {
        for (String nodeKey : nodeKeys) {
            if (currentCourseNode.equals(nodeKey)) {
                courseNodeEl.select(nodeKey, true);
                nodeSelected = true;
            }
        }
    }
    if (!nodeSelected && nodeKeys.length > 0) {
        courseNodeEl.select(nodeKeys[0], true);
    }
    if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
        courseNodeEl.setErrorKey("error.course.node.found", null);
    }
    operatorEl = uifactory.addDropdownSingleselect("operators.".concat(id), null, ruleCont, operatorKeys, operatorKeys, null);
    operatorEl.setDomReplacementWrapperRequired(false);
    boolean opSelected = false;
    if (currentOperator != null) {
        for (String operatorKey : operatorKeys) {
            if (currentOperator.equals(operatorKey)) {
                operatorEl.select(operatorKey, true);
                opSelected = true;
            }
        }
    }
    if (!opSelected) {
        operatorEl.select(operatorKeys[2], true);
    }
    valueEl = uifactory.addTextElement("value.".concat(id), null, 128, currentValue, ruleCont);
    valueEl.setDomReplacementWrapperRequired(false);
    valueEl.setDisplaySize(3);
    return ruleCont;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 82 with ReminderRuleImpl

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

the class ScoreRuleEditor method getConfiguration.

@Override
public ReminderRule getConfiguration() {
    ReminderRuleImpl configuredRule = null;
    if (courseNodeEl.isOneSelected() && operatorEl.isOneSelected() && StringHelper.containsNonWhitespace(valueEl.getValue())) {
        configuredRule = new ReminderRuleImpl();
        configuredRule.setType(ScoreRuleSPI.class.getSimpleName());
        configuredRule.setLeftOperand(courseNodeEl.getSelectedKey());
        configuredRule.setOperator(operatorEl.getSelectedKey());
        configuredRule.setRightOperand(valueEl.getValue());
    }
    return configuredRule;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ScoreRuleSPI(org.olat.course.reminder.rule.ScoreRuleSPI)

Example 83 with ReminderRuleImpl

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

the class PassedRuleSPI method filter.

@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        String nodeIdent = r.getLeftOperand();
        String status = r.getRightOperand();
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
        if (courseNode == null) {
            identities.clear();
            log.error("Passed rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
            return;
        }
        Map<Long, Boolean> passeds;
        if (courseNode instanceof STCourseNode) {
            passeds = new HashMap<>();
            STCourseNode structureNode = (STCourseNode) courseNode;
            if (structureNode.hasPassedConfigured()) {
                for (Identity identity : identities) {
                    UserCourseEnvironment uce = AssessmentHelper.createAndInitUserCourseEnvironment(identity, course);
                    ScoreEvaluation scoreEval = structureNode.getUserScoreEvaluation(uce);
                    Boolean passed = scoreEval.getPassed();
                    if (passed != null) {
                        passeds.put(identity.getKey(), passed);
                    }
                }
            }
        } else {
            passeds = helperDao.getPassed(entry, courseNode, identities);
        }
        if ("passed".equals(status)) {
            for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
                Boolean passed = passeds.get(identityIt.next().getKey());
                if (passed == null || !passed.booleanValue()) {
                    identityIt.remove();
                }
            }
        } else if ("failed".equals(status)) {
            for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
                Boolean passed = passeds.get(identityIt.next().getKey());
                if (passed != null && passed.booleanValue()) {
                    identityIt.remove();
                }
            }
        }
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) STCourseNode(org.olat.course.nodes.STCourseNode) Iterator(java.util.Iterator) STCourseNode(org.olat.course.nodes.STCourseNode) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 84 with ReminderRuleImpl

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

the class AttemptsRuleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/attempts.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
    ruleCont.setRootForm(formLayout.getRootForm());
    formLayout.add(ruleCont);
    ruleCont.getFormItemComponent().contextPut("id", id);
    ICourse course = CourseFactory.loadCourse(entry);
    String currentValue = null;
    String currentOperator = null;
    String currentCourseNode = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentOperator = r.getOperator();
        currentValue = r.getRightOperand();
        currentCourseNode = r.getLeftOperand();
    }
    List<CourseNode> attemptableNodes = new ArrayList<>();
    searchAttemptableNodes(course.getRunStructure().getRootNode(), attemptableNodes);
    String[] nodeKeys = new String[attemptableNodes.size()];
    String[] nodeValues = new String[attemptableNodes.size()];
    for (int i = 0; i < attemptableNodes.size(); i++) {
        CourseNode attemptableNode = attemptableNodes.get(i);
        nodeKeys[i] = attemptableNode.getIdent();
        nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
    }
    courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
    courseNodeEl.setDomReplacementWrapperRequired(false);
    boolean nodeSelected = false;
    if (currentCourseNode != null) {
        for (String nodeKey : nodeKeys) {
            if (currentCourseNode.equals(nodeKey)) {
                courseNodeEl.select(nodeKey, true);
                nodeSelected = true;
            }
        }
    }
    if (!nodeSelected && nodeKeys.length > 0) {
        courseNodeEl.select(nodeKeys[0], true);
    }
    if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
        courseNodeEl.setErrorKey("error.course.node.found", null);
    }
    operatorEl = uifactory.addDropdownSingleselect("operators.".concat(id), null, ruleCont, operatorKeys, operatorKeys, null);
    operatorEl.setDomReplacementWrapperRequired(false);
    boolean opSelected = false;
    if (currentOperator != null) {
        for (String operatorKey : operatorKeys) {
            if (currentOperator.equals(operatorKey)) {
                operatorEl.select(operatorKey, true);
                opSelected = true;
            }
        }
    }
    if (!opSelected) {
        operatorEl.select(operatorKeys[2], true);
    }
    valueEl = uifactory.addTextElement("value.".concat(id), null, 128, currentValue, ruleCont);
    valueEl.setDomReplacementWrapperRequired(false);
    valueEl.setDisplaySize(3);
    return ruleCont;
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) QTICourseNode(org.olat.course.nodes.QTICourseNode)

Example 85 with ReminderRuleImpl

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

the class BeforeDateTaskRuleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/date_rule.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    Translator trans = Util.createPackageTranslator(BeforeDateTaskRuleEditor.class, formLayout.getTranslator().getLocale(), formLayout.getTranslator());
    FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("taks.".concat(id), formLayout.getTranslator(), page);
    ruleCont.setRootForm(formLayout.getRootForm());
    ruleCont.setTranslator(trans);
    formLayout.add(ruleCont);
    ICourse course = CourseFactory.loadCourse(entry);
    String currentValue = null;
    String currentUnit = null;
    String currentCourseNode = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentUnit = r.getRightUnit();
        currentValue = r.getRightOperand();
        currentCourseNode = r.getLeftOperand();
    }
    List<CourseNode> attemptableNodes = new ArrayList<>();
    searchNodesWithDeadlines(course.getRunStructure().getRootNode(), attemptableNodes);
    String[] nodeKeys = new String[attemptableNodes.size()];
    String[] nodeValues = new String[attemptableNodes.size()];
    for (int i = 0; i < attemptableNodes.size(); i++) {
        CourseNode attemptableNode = attemptableNodes.get(i);
        nodeKeys[i] = attemptableNode.getIdent();
        nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
    }
    courseNodeEl = uifactory.addDropdownSingleselect("coursenodes", null, ruleCont, nodeKeys, nodeValues, null);
    courseNodeEl.setDomReplacementWrapperRequired(false);
    boolean nodeSelected = false;
    if (currentCourseNode != null) {
        for (String nodeKey : nodeKeys) {
            if (currentCourseNode.equals(nodeKey)) {
                courseNodeEl.select(nodeKey, true);
                nodeSelected = true;
            }
        }
    }
    if (!nodeSelected && nodeKeys.length > 0) {
        courseNodeEl.select(nodeKeys[0], true);
    }
    if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
        courseNodeEl.setErrorKey("error.course.node.found", null);
    }
    valueEl = uifactory.addTextElement("value", null, 128, currentValue, ruleCont);
    valueEl.setDomReplacementWrapperRequired(false);
    valueEl.setDisplaySize(3);
    String[] unitValues = new String[] { trans.translate(LaunchUnit.day.name()), trans.translate(LaunchUnit.week.name()), trans.translate(LaunchUnit.month.name()), trans.translate(LaunchUnit.year.name()) };
    unitEl = uifactory.addDropdownSingleselect("unit", null, ruleCont, unitKeys, unitValues, null);
    unitEl.setDomReplacementWrapperRequired(false);
    boolean selected = false;
    if (currentUnit != null) {
        for (String unitKey : unitKeys) {
            if (currentUnit.equals(unitKey)) {
                unitEl.select(unitKey, true);
                selected = true;
            }
        }
    }
    if (!selected) {
        unitEl.select(unitKeys[1], true);
    }
    return ruleCont;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode)

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