Search in sources :

Example 16 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.

the class CheckListRunController method doCheck.

private boolean doCheck(UserRequest ureq, CheckboxWrapper wrapper, boolean checked) {
    DBCheckbox theOne;
    if (wrapper.getDbCheckbox() == null) {
        String uuid = wrapper.getCheckbox().getCheckboxId();
        theOne = checkboxManager.loadCheckbox(courseOres, courseNode.getIdent(), uuid);
    } else {
        theOne = wrapper.getDbCheckbox();
    }
    if (theOne == null) {
        // only warning because this happen in course preview
        logWarn("A checkbox is missing: " + courseOres + " / " + courseNode.getIdent(), null);
    } else {
        Float score;
        if (checked) {
            score = wrapper.getCheckbox().getPoints();
        } else {
            score = 0f;
        }
        checkboxManager.check(theOne, getIdentity(), score, Boolean.valueOf(checked));
        // make sure all results is on the database before calculating some scores
        // manager commit already
        courseNode.updateScoreEvaluation(getIdentity(), userCourseEnv, getIdentity(), Role.user);
        Checkbox checkbox = wrapper.getCheckbox();
        logUpdateCheck(checkbox.getCheckboxId(), checkbox.getTitle());
    }
    exposeUserDataToVC(ureq, flc);
    return courseNode.hasScoreConfigured() || courseNode.hasPassedConfigured();
}
Also used : Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox)

Example 17 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.

the class CheckListRunController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    boolean readOnly = isReadOnly();
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("readOnly", Boolean.valueOf(readOnly));
        if (dueDate != null) {
            layoutCont.contextPut("dueDate", dueDate);
            layoutCont.contextPut("in-due-date", isPanelOpen(ureq, "due-date", true));
            if (dueDate.compareTo(new Date()) < 0) {
                layoutCont.contextPut("afterDueDate", Boolean.TRUE);
            }
        }
        layoutCont.contextPut("withScore", new Boolean(withScore));
        if (courseNode.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD, false)) {
            HighScoreRunController highScoreCtr = new HighScoreRunController(ureq, getWindowControl(), userCourseEnv, courseNode, this.mainForm);
            if (highScoreCtr.isViewHighscore()) {
                Component highScoreComponent = highScoreCtr.getInitialComponent();
                layoutCont.put("highScore", highScoreComponent);
            }
        }
        List<DBCheck> checks = checkboxManager.loadCheck(getIdentity(), courseOres, courseNode.getIdent());
        Map<String, DBCheck> uuidToCheckMap = new HashMap<>();
        for (DBCheck check : checks) {
            uuidToCheckMap.put(check.getCheckbox().getCheckboxId(), check);
        }
        List<Checkbox> list = checkboxList.getList();
        List<CheckboxWrapper> wrappers = new ArrayList<>(list.size());
        for (Checkbox checkbox : list) {
            DBCheck check = uuidToCheckMap.get(checkbox.getCheckboxId());
            CheckboxWrapper wrapper = forgeCheckboxWrapper(checkbox, check, readOnly, formLayout);
            layoutCont.add(wrapper.getCheckboxEl());
            wrappers.add(wrapper);
        }
        layoutCont.contextPut("checkboxList", wrappers);
        if (withScore || withPassed) {
            layoutCont.contextPut("enableScoreInfo", Boolean.TRUE);
            exposeConfigToVC(ureq, layoutCont);
            exposeUserDataToVC(ureq, layoutCont);
        } else {
            layoutCont.contextPut("enableScoreInfo", Boolean.FALSE);
        }
    }
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HighScoreRunController(org.olat.course.highscore.ui.HighScoreRunController) Date(java.util.Date) Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Component(org.olat.core.gui.components.Component)

Example 18 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.

the class CheckboxAssessmentController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (checkboxEl == source) {
        int nextCheckboxIndex = checkboxEl.getSelected();
        saveCurrentSelectCheckbox();
        Checkbox box = checkboxList.getList().get(nextCheckboxIndex);
        boolean hasPoints = box.getPoints() != null && box.getPoints().floatValue() > 0f;
        List<CheckboxAssessmentRow> rows = model.getObjects();
        for (CheckboxAssessmentRow row : rows) {
            Boolean[] checkedArr = row.getChecked();
            if (checkedArr[nextCheckboxIndex] != null && checkedArr[nextCheckboxIndex].booleanValue()) {
                row.getCheckedEl().select(onKeys[0], true);
            } else {
                row.getCheckedEl().select(onKeys[0], false);
            }
            Float[] scores = row.getScores();
            if (scores[nextCheckboxIndex] != null && scores[nextCheckboxIndex] != null) {
                row.getPointEl().setValue(AssessmentHelper.getRoundedScore(scores[nextCheckboxIndex]));
            } else {
                row.getPointEl().setValue("");
            }
            row.getPointEl().setVisible(hasPoints);
        }
        currentCheckboxIndex = nextCheckboxIndex;
    } else if (source instanceof MultipleSelectionElement) {
        MultipleSelectionElement checkEl = (MultipleSelectionElement) source;
        if (checkEl.getUserObject() instanceof CheckboxAssessmentRow) {
            CheckboxAssessmentRow row = (CheckboxAssessmentRow) checkEl.getUserObject();
            if (row.getPointEl().isVisible()) {
                boolean checked = checkEl.isAtLeastSelected(1);
                if (checked) {
                    int nextCheckboxIndex = checkboxEl.getSelected();
                    Checkbox box = checkboxList.getList().get(nextCheckboxIndex);
                    String pointVal = AssessmentHelper.getRoundedScore(box.getPoints());
                    row.getPointEl().setValue(pointVal);
                } else {
                    row.getPointEl().setValue("");
                }
            }
        }
    } else if (selectAllBoxButton == source) {
        doSelectAll();
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Checkbox(org.olat.course.nodes.cl.model.Checkbox)

Example 19 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.

the class CheckboxManagerImpl method syncCheckbox.

@Override
public void syncCheckbox(CheckboxList checkboxList, OLATResourceable ores, String resSubPath) {
    List<DBCheckbox> dbCheckboxList = loadCheckbox(ores, resSubPath);
    Map<String, DBCheckbox> uuids = new HashMap<String, DBCheckbox>();
    for (DBCheckbox dbCheckbox : dbCheckboxList) {
        uuids.put(dbCheckbox.getCheckboxId(), dbCheckbox);
    }
    if (checkboxList != null && checkboxList.getList() != null) {
        List<Checkbox> resCheckboxList = checkboxList.getList();
        for (Checkbox resCheckbox : resCheckboxList) {
            String resUuid = resCheckbox.getCheckboxId();
            if (uuids.containsKey(resUuid)) {
                // already synched
                uuids.remove(resUuid);
            } else {
                createDBCheckbox(resUuid, ores, resSubPath);
            }
        }
    }
    for (DBCheckbox dbCheckbox : uuids.values()) {
        System.out.println("Remove them??? " + dbCheckbox.getCheckboxId());
    }
}
Also used : HashMap(java.util.HashMap) Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox)

Example 20 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.

the class AssessedIdentityCheckListController method doUpdateCheck.

private void doUpdateCheck(CheckboxWrapper wrapper, boolean check) {
    // nothing to do
    if (wrapper.getPointEl() == null)
        return;
    if (check) {
        if (!StringHelper.containsNonWhitespace(wrapper.getPointEl().getValue())) {
            Checkbox checkbox = wrapper.getCheckbox();
            Float points = checkbox.getPoints();
            if (points != null) {
                String val = AssessmentHelper.getRoundedScore(points);
                wrapper.getPointEl().setValue(val);
            }
        }
    } else if (wrapper.getPointEl() != null) {
        wrapper.getPointEl().setValue("");
    }
    // hide when not yet checked
    wrapper.getPointEl().setVisible(check);
}
Also used : Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox)

Aggregations

Checkbox (org.olat.course.nodes.cl.model.Checkbox)58 CheckboxList (org.olat.course.nodes.cl.model.CheckboxList)24 ArrayList (java.util.ArrayList)16 CheckboxManager (org.olat.course.nodes.cl.CheckboxManager)14 ModuleConfiguration (org.olat.modules.ModuleConfiguration)14 File (java.io.File)12 HashMap (java.util.HashMap)12 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)12 Identity (org.olat.core.id.Identity)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 ICourse (org.olat.course.ICourse)8 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)8 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6 DBCheck (org.olat.course.nodes.cl.model.DBCheck)6 Date (java.util.Date)4 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)4