Search in sources :

Example 6 with AssessmentBatch

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

the class CheckListAssessmentController method doSave.

private void doSave() {
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    // save all rows
    List<CheckListAssessmentRow> rows = model.getBackedUpRows();
    List<AssessmentBatch> batchElements = new ArrayList<>(rows.size());
    Set<Long> assessedIdentityToUpdate = new HashSet<>();
    for (CheckListAssessmentRow row : rows) {
        Boolean[] checked = row.getChecked();
        Boolean[] editedChecked = new Boolean[numOfCheckbox];
        MultipleSelectionElement[] checkedEls = row.getCheckedEl();
        if (checkedEls != null) {
            for (int i = 0; i < numOfCheckbox; i++) {
                MultipleSelectionElement checkEl = checkedEls[i];
                boolean editedValue = checkEl.isAtLeastSelected(1);
                editedChecked[i] = new Boolean(editedValue);
                boolean currentValue;
                if (checked != null && checked.length > 0 && i < checked.length && checked[i] != null) {
                    currentValue = checked[i].booleanValue();
                } else {
                    currentValue = false;
                }
                if (editedValue != currentValue) {
                    Checkbox checkbox = checkboxList.getList().get(i);
                    String checkboxId = checkbox.getCheckboxId();
                    Float score = editedValue ? checkbox.getPoints() : new Float(0f);
                    batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, score, editedValue));
                    assessedIdentityToUpdate.add(row.getIdentityKey());
                }
                flc.remove(checkEl);
            }
        }
        row.setCheckedEl(null);
        row.setChecked(editedChecked);
    }
    doDisableEditingMode();
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    if (assessedIdentityToUpdate.size() > 0) {
        DBFactory.getInstance().commit();
        ICourse course = CourseFactory.loadCourse(courseOres);
        List<Identity> assessedIdentities = securityManager.loadIdentityByKeys(assessedIdentityToUpdate);
        for (Identity assessedIdentity : assessedIdentities) {
            UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
        }
    }
    reloadTable();
}
Also used : UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 7 with AssessmentBatch

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

the class CheckboxAssessmentController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    saveCurrentSelectCheckbox();
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    Map<Long, CheckListAssessmentRow> identityToInitialRow = new HashMap<>();
    for (CheckListAssessmentRow initialRow : initialRows) {
        identityToInitialRow.put(initialRow.getIdentityKey(), initialRow);
    }
    Set<Long> assessedIdentityToUpdate = new HashSet<>();
    List<CheckboxAssessmentRow> rows = model.getObjects();
    List<AssessmentBatch> batchElements = new ArrayList<>();
    for (CheckboxAssessmentRow row : rows) {
        CheckListAssessmentRow initialRow = identityToInitialRow.get(row.getIdentityKey());
        Boolean[] checked = initialRow.getChecked();
        Boolean[] editedChecked = row.getChecked();
        Float[] scores = initialRow.getScores();
        Float[] editedScores = row.getScores();
        for (int i = 0; i < numOfCheckbox; i++) {
            Checkbox box = checkboxList.getList().get(i);
            boolean currentValue = getSecureValue(checked, i);
            boolean editedValue = getSecureValue(editedChecked, i);
            Float currentPoint = getSecureValue(scores, i);
            ;
            Float editedPoint;
            if (box.getPoints() != null && box.getPoints().floatValue() > 0f) {
                editedPoint = getSecureValue(editedScores, i);
            } else {
                editedPoint = null;
            }
            if ((editedValue != currentValue) || ((currentPoint == null && editedPoint != null) || (currentPoint != null && editedPoint == null) || (currentPoint != null && !currentPoint.equals(editedPoint)))) {
                Checkbox checkbox = checkboxList.getList().get(i);
                String checkboxId = checkbox.getCheckboxId();
                batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, editedPoint, editedValue));
                assessedIdentityToUpdate.add(row.getIdentityKey());
            }
        }
    }
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    if (assessedIdentityToUpdate.size() > 0) {
        DBFactory.getInstance().commit();
        ICourse course = CourseFactory.loadCourse(courseOres);
        List<Identity> assessedIdentities = securityManager.loadIdentityByKeys(assessedIdentityToUpdate);
        for (Identity assessedIdentity : assessedIdentities) {
            UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : HashMap(java.util.HashMap) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 8 with AssessmentBatch

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

the class AssessedIdentityCheckListController method doSave.

private void doSave() {
    List<AssessmentBatch> batchElements = new ArrayList<>();
    for (CheckboxWrapper wrapper : wrappers) {
        Float editedPoint = null;
        if (wrapper.getPointEl() != null) {
            String val = wrapper.getPointEl().getValue();
            if (StringHelper.containsNonWhitespace(val)) {
                try {
                    editedPoint = new Float(val);
                } catch (NumberFormatException e) {
                    editedPoint = null;
                }
            }
        }
        boolean editedValue = wrapper.getCheckboxEl().isAtLeastSelected(1);
        Float currentPoint = null;
        boolean currentValue = false;
        if (wrapper.getCheck() != null) {
            currentPoint = wrapper.getCheck().getScore();
            Boolean checkObj = wrapper.getCheck().getChecked();
            if (checkObj != null && checkObj.booleanValue()) {
                currentValue = checkObj.booleanValue();
            }
        }
        if ((editedValue != currentValue) || ((currentPoint == null && editedPoint != null) || (currentPoint != null && editedPoint == null) || (currentPoint != null && !currentPoint.equals(editedPoint)))) {
            String boxId = wrapper.getCheckbox().getCheckboxId();
            batchElements.add(new AssessmentBatch(assessedIdentity.getKey(), boxId, editedPoint, editedValue));
        }
    }
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
}
Also used : AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) ArrayList(java.util.ArrayList)

Aggregations

AssessmentBatch (org.olat.course.nodes.cl.model.AssessmentBatch)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Identity (org.olat.core.id.Identity)6 HashMap (java.util.HashMap)4 ICourse (org.olat.course.ICourse)4 Checkbox (org.olat.course.nodes.cl.model.Checkbox)4 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)4 EntityManager (javax.persistence.EntityManager)2 IdentityImpl (org.olat.basesecurity.IdentityImpl)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 DBCheck (org.olat.course.nodes.cl.model.DBCheck)2 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)2