Search in sources :

Example 1 with AssessmentData

use of org.olat.course.nodes.cl.model.AssessmentData in project OpenOLAT by OpenOLAT.

the class CheckListAssessmentController method getAssessmentDataViews.

private List<CheckListAssessmentRow> getAssessmentDataViews(List<AssessmentData> datas, List<Checkbox> checkbox) {
    List<CheckListAssessmentRow> dataViews = new ArrayList<>();
    int numOfcheckbox = checkbox.size();
    Map<String, Integer> indexed = new HashMap<>();
    for (int i = numOfcheckbox; i-- > 0; ) {
        indexed.put(checkbox.get(i).getCheckboxId(), new Integer(i));
    }
    for (AssessmentData data : datas) {
        Float[] scores = new Float[numOfcheckbox];
        Boolean[] checkBool = new Boolean[numOfcheckbox];
        float totalPoints = 0.0f;
        for (DBCheck check : data.getChecks()) {
            Float score = check.getScore();
            if (score != null) {
                totalPoints += score.floatValue();
            }
            if (check.getChecked() == null)
                continue;
            check.getCheckbox();
            Integer index = indexed.get(check.getCheckbox().getCheckboxId());
            if (index != null) {
                int i = index.intValue();
                if (i >= 0 && i < numOfcheckbox) {
                    scores[i] = score;
                    checkBool[i] = check.getChecked();
                }
            }
        }
        if (maxScore != null && maxScore.floatValue() > 0f && totalPoints > maxScore.floatValue()) {
            totalPoints = maxScore.floatValue();
        }
        CheckListAssessmentRow row = new CheckListAssessmentRow(data.getIdentity(), checkBool, scores, totalPoints, userPropertyHandlers, getLocale());
        dataViews.add(row);
    }
    return dataViews;
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData)

Example 2 with AssessmentData

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

the class CheckListAssessmentController method loadDatas.

private List<CheckListAssessmentRow> loadDatas() {
    if (!(coachCourseEnv instanceof UserCourseEnvironmentImpl)) {
        return Collections.emptyList();
    }
    UserCourseEnvironmentImpl env = (UserCourseEnvironmentImpl) coachCourseEnv;
    List<Checkbox> checkboxColl = checkboxList.getList();
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    boolean courseAdmin = env.isAdmin();
    RepositoryEntry re = env.getCourseRepositoryEntry();
    boolean courseTutor = repositoryService.hasRole(getIdentity(), re, GroupRoles.coach.name());
    Set<Long> missingIdentityKeys = new HashSet<>();
    if (courseTutor || courseAdmin) {
        List<RepositoryEntryMembership> repoMemberships = repositoryManager.getRepositoryEntryMembership(re);
        for (RepositoryEntryMembership repoMembership : repoMemberships) {
            if (repoMembership.isParticipant()) {
                missingIdentityKeys.add(repoMembership.getIdentityKey());
            }
        }
    }
    List<BusinessGroup> coachedGroups = courseAdmin ? coachCourseEnv.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups() : env.getCoachedGroups();
    List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(courseOres, courseNode.getIdent(), courseTutor || courseAdmin ? re : null, coachedGroups);
    List<CheckListAssessmentRow> boxList = getAssessmentDataViews(dataList, checkboxColl);
    Map<Long, CheckListAssessmentRow> identityToView = new HashMap<>();
    for (CheckListAssessmentRow box : boxList) {
        identityToView.put(box.getIdentityKey(), box);
        missingIdentityKeys.remove(box.getIdentityKey());
    }
    List<BusinessGroupMembership> memberships = businessGroupService.getBusinessGroupsMembership(coachedGroups);
    for (BusinessGroupMembership membership : memberships) {
        if (!membership.isParticipant())
            continue;
        Long identityKey = membership.getIdentityKey();
        if (!identityToView.containsKey(identityKey)) {
            missingIdentityKeys.add(identityKey);
        }
    }
    List<Identity> missingIdentities = securityManager.loadIdentityByKeys(missingIdentityKeys);
    for (Identity missingIdentity : missingIdentities) {
        Boolean[] checked = new Boolean[numOfCheckbox];
        Float[] scores = new Float[numOfCheckbox];
        CheckListAssessmentRow view = new CheckListAssessmentRow(missingIdentity, checked, scores, null, userPropertyHandlers, getLocale());
        identityToView.put(missingIdentity.getKey(), view);
    }
    for (BusinessGroupMembership membership : memberships) {
        if (!membership.isParticipant())
            continue;
        CheckListAssessmentRow view = identityToView.get(membership.getIdentityKey());
        if (view != null) {
            view.addGroupKey(membership.getGroupKey());
        }
    }
    List<CheckListAssessmentRow> views = new ArrayList<>();
    views.addAll(identityToView.values());
    return views;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Example 3 with AssessmentData

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

the class CheckListAssessmentController method getAssessmentDataViews.

private List<CheckListAssessmentRow> getAssessmentDataViews(List<AssessmentData> datas, List<Checkbox> checkbox) {
    List<CheckListAssessmentRow> dataViews = new ArrayList<>();
    int numOfcheckbox = checkbox.size();
    Map<String, Integer> indexed = new HashMap<>();
    for (int i = numOfcheckbox; i-- > 0; ) {
        indexed.put(checkbox.get(i).getCheckboxId(), new Integer(i));
    }
    for (AssessmentData data : datas) {
        Float[] scores = new Float[numOfcheckbox];
        Boolean[] checkBool = new Boolean[numOfcheckbox];
        float totalPoints = 0.0f;
        for (DBCheck check : data.getChecks()) {
            Float score = check.getScore();
            if (score != null) {
                totalPoints += score.floatValue();
            }
            if (check.getChecked() == null)
                continue;
            check.getCheckbox();
            Integer index = indexed.get(check.getCheckbox().getCheckboxId());
            if (index != null) {
                int i = index.intValue();
                if (i >= 0 && i < numOfcheckbox) {
                    scores[i] = score;
                    checkBool[i] = check.getChecked();
                }
            }
        }
        if (maxScore != null && maxScore.floatValue() > 0f && totalPoints > maxScore.floatValue()) {
            totalPoints = maxScore.floatValue();
        }
        CheckListAssessmentRow row = new CheckListAssessmentRow(data.getIdentity(), checkBool, scores, totalPoints, userPropertyHandlers, getLocale());
        dataViews.add(row);
    }
    return dataViews;
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData)

Example 4 with AssessmentData

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

the class CheckListExcelExport method exportAll.

public void exportAll(String filename, ZipOutputStream exportStream) {
    List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(course, courseNode.getIdent(), null, null);
    try (OutputStream out = new ShieldOutputStream(exportStream)) {
        exportStream.putNextEntry(new ZipEntry(filename + ".xlsx"));
        exportWorkbook(dataList, out);
        exportStream.closeEntry();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 5 with AssessmentData

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

the class CheckboxManagerImpl method getAssessmentDatas.

@Override
public List<AssessmentData> getAssessmentDatas(OLATResourceable ores, String resSubPath, RepositoryEntry re, List<BusinessGroup> businessGroups) {
    StringBuilder sb = new StringBuilder();
    sb.append("select check from clcheck check").append(" inner join fetch check.checkbox box").append(" inner join fetch check.identity ident").append(" inner join fetch ident.user identUser").append(" where box.resName=:resName and box.resId=:resId");
    if (StringHelper.containsNonWhitespace(resSubPath)) {
        sb.append(" and box.resSubPath=:resSubPath");
    }
    boolean hasBusinessGroups = businessGroups != null && businessGroups.size() > 0;
    if (hasBusinessGroups) {
        sb.append(" and ");
        if (re != null) {
            sb.append(" ( ");
        }
        sb.append(" check.identity.key in ( select membership.identity.key from bgroupmember membership ").append("   where membership.group in (:baseGroups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
    }
    if (re != null) {
        if (hasBusinessGroups) {
            sb.append(" or ");
        } else {
            sb.append(" and ");
        }
        sb.append(" check.identity.key in ( select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append("   where rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
        if (hasBusinessGroups) {
            sb.append(" ) ");
        }
    }
    TypedQuery<DBCheck> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), DBCheck.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId());
    if (StringHelper.containsNonWhitespace(resSubPath)) {
        query.setParameter("resSubPath", resSubPath);
    }
    if (hasBusinessGroups) {
        List<Group> groups = new ArrayList<>(businessGroups.size());
        for (BusinessGroup businessGroup : businessGroups) {
            groups.add(businessGroup.getBaseGroup());
        }
        query.setParameter("baseGroups", groups);
    }
    if (re != null) {
        query.setParameter("repoKey", re.getKey());
    }
    List<DBCheck> checks = query.getResultList();
    Map<Long, AssessmentData> identToBox = new HashMap<Long, AssessmentData>();
    for (DBCheck check : checks) {
        AssessmentData data = identToBox.get(check.getIdentity().getKey());
        if (data == null) {
            data = new AssessmentData(check.getIdentity());
            identToBox.put(check.getIdentity().getKey(), data);
        }
        data.getChecks().add(check);
    }
    return new ArrayList<AssessmentData>(identToBox.values());
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) DBCheck(org.olat.course.nodes.cl.model.DBCheck) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData)

Aggregations

AssessmentData (org.olat.course.nodes.cl.model.AssessmentData)20 Identity (org.olat.core.id.Identity)14 DBCheck (org.olat.course.nodes.cl.model.DBCheck)14 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Test (org.junit.Test)8 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)8 BusinessGroup (org.olat.group.BusinessGroup)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 ShieldOutputStream (org.olat.core.util.io.ShieldOutputStream)4 Checkbox (org.olat.course.nodes.cl.model.Checkbox)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 Collections (java.util.Collections)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2