Search in sources :

Example 21 with AssessmentModeToGroup

use of org.olat.course.assessment.AssessmentModeToGroup in project openolat by klemens.

the class AssessmentModeManagerImpl method getAssessedIdentityKeys.

@Override
public Set<Long> getAssessedIdentityKeys(AssessmentMode assessmentMode) {
    Target targetAudience = assessmentMode.getTargetAudience();
    RepositoryEntry re = assessmentMode.getRepositoryEntry();
    Set<Long> assessedKeys = new HashSet<>();
    if (targetAudience == Target.course || targetAudience == Target.courseAndGroups) {
        List<Long> courseMemberKeys = assessmentMode.isApplySettingsForCoach() ? repositoryEntryRelationDao.getMemberKeys(re, RepositoryEntryRelationType.defaultGroup, GroupRoles.coach.name(), GroupRoles.participant.name()) : repositoryEntryRelationDao.getMemberKeys(re, RepositoryEntryRelationType.defaultGroup, GroupRoles.participant.name());
        assessedKeys.addAll(courseMemberKeys);
    }
    if (targetAudience == Target.groups || targetAudience == Target.courseAndGroups) {
        List<BusinessGroup> groups = new ArrayList<>();
        Set<AssessmentModeToArea> modeToAreas = assessmentMode.getAreas();
        if (modeToAreas.size() > 0) {
            List<BGArea> areas = new ArrayList<>(modeToAreas.size());
            for (AssessmentModeToArea modeToArea : modeToAreas) {
                areas.add(modeToArea.getArea());
            }
            List<BusinessGroup> groupsInAreas = areaMgr.findBusinessGroupsOfAreas(areas);
            groups.addAll(groupsInAreas);
        }
        Set<AssessmentModeToGroup> modeToGroups = assessmentMode.getGroups();
        if (modeToGroups.size() > 0) {
            for (AssessmentModeToGroup modeToGroup : modeToGroups) {
                groups.add(modeToGroup.getBusinessGroup());
            }
        }
        List<Long> groupMemberKeys = assessmentMode.isApplySettingsForCoach() ? businessGroupRelationDao.getMemberKeys(groups, GroupRoles.coach.name(), GroupRoles.participant.name()) : businessGroupRelationDao.getMemberKeys(groups, GroupRoles.participant.name());
        assessedKeys.addAll(groupMemberKeys);
    }
    return assessedKeys;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) Target(org.olat.course.assessment.AssessmentMode.Target) BGArea(org.olat.group.area.BGArea) HashSet(java.util.HashSet)

Example 22 with AssessmentModeToGroup

use of org.olat.course.assessment.AssessmentModeToGroup in project openolat by klemens.

the class AssessmentModeEditController method save.

private void save(UserRequest ureq, boolean forceStatus) {
    if (assessmentMode.getKey() != null) {
        assessmentMode = assessmentModeMgr.getAssessmentModeById(assessmentMode.getKey());
    }
    assessmentMode.setName(nameEl.getValue());
    assessmentMode.setDescription(descriptionEl.getValue());
    assessmentMode.setBegin(beginEl.getDate());
    if (leadTimeEl.getIntValue() > 0) {
        assessmentMode.setLeadTime(leadTimeEl.getIntValue());
    } else {
        assessmentMode.setLeadTime(0);
    }
    assessmentMode.setEnd(endEl.getDate());
    if (followupTimeEl.getIntValue() > 0) {
        assessmentMode.setFollowupTime(followupTimeEl.getIntValue());
    } else {
        assessmentMode.setFollowupTime(0);
    }
    if (startModeEl.isOneSelected() && startModeEl.isSelected(1)) {
        assessmentMode.setManualBeginEnd(true);
    } else {
        assessmentMode.setManualBeginEnd(false);
    }
    String targetKey = targetEl.getSelectedKey();
    assessmentMode.setTargetAudience(AssessmentMode.Target.valueOf(targetKey));
    boolean elementRestrictions = courseElementsRestrictionEl.isAtLeastSelected(1);
    assessmentMode.setRestrictAccessElements(elementRestrictions);
    if (elementRestrictions) {
        StringBuilder sb = new StringBuilder();
        for (String elementKey : elementKeys) {
            if (sb.length() > 0)
                sb.append(",");
            sb.append(elementKey);
        }
        assessmentMode.setElementList(sb.toString());
    } else {
        assessmentMode.setElementList(null);
    }
    if (StringHelper.containsNonWhitespace(startElementKey)) {
        assessmentMode.setStartElement(startElementKey);
    } else {
        assessmentMode.setStartElement(null);
    }
    boolean ipRestriction = ipsEl.isAtLeastSelected(1);
    assessmentMode.setRestrictAccessIps(ipRestriction);
    if (ipRestriction) {
        assessmentMode.setIpList(ipListEl.getValue());
    } else {
        assessmentMode.setIpList(null);
    }
    boolean safeExamEnabled = safeExamBrowserEl.isAtLeastSelected(1);
    assessmentMode.setSafeExamBrowser(safeExamEnabled);
    if (safeExamEnabled) {
        assessmentMode.setSafeExamBrowserKey(safeExamBrowserKeyEl.getValue());
        assessmentMode.setSafeExamBrowserHint(safeExamBrowserHintEl.getValue());
    } else {
        assessmentMode.setSafeExamBrowserKey(null);
        assessmentMode.setSafeExamBrowserHint(null);
    }
    assessmentMode.setApplySettingsForCoach(forCoachEl.isAtLeastSelected(1));
    // mode need to be persisted for the following relations
    if (assessmentMode.getKey() == null) {
        assessmentMode = assessmentModeMgr.persist(assessmentMode);
    }
    // update groups
    if (groupKeys.isEmpty()) {
        if (!assessmentMode.getGroups().isEmpty()) {
            assessmentMode.getGroups().clear();
        }
    } else {
        Set<Long> currentKeys = new HashSet<>();
        for (Iterator<AssessmentModeToGroup> modeToGroupIt = assessmentMode.getGroups().iterator(); modeToGroupIt.hasNext(); ) {
            Long currentKey = modeToGroupIt.next().getBusinessGroup().getKey();
            if (!groupKeys.contains(currentKey)) {
                modeToGroupIt.remove();
            } else {
                currentKeys.add(currentKey);
            }
        }
        for (Long groupKey : groupKeys) {
            if (!currentKeys.contains(groupKey)) {
                BusinessGroup group = businessGroupService.loadBusinessGroup(groupKey);
                AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(assessmentMode, group);
                assessmentMode.getGroups().add(modeToGroup);
            }
        }
    }
    // update areas
    if (areaKeys.isEmpty()) {
        if (!assessmentMode.getAreas().isEmpty()) {
            assessmentMode.getAreas().clear();
        }
    } else {
        Set<Long> currentKeys = new HashSet<>();
        for (Iterator<AssessmentModeToArea> modeToAreaIt = assessmentMode.getAreas().iterator(); modeToAreaIt.hasNext(); ) {
            Long currentKey = modeToAreaIt.next().getArea().getKey();
            if (!areaKeys.contains(currentKey)) {
                modeToAreaIt.remove();
            } else {
                currentKeys.add(currentKey);
            }
        }
        for (Long areaKey : areaKeys) {
            if (!currentKeys.contains(areaKey)) {
                BGArea area = areaMgr.loadArea(areaKey);
                AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(assessmentMode, area);
                assessmentMode.getAreas().add(modeToArea);
            }
        }
    }
    assessmentMode = assessmentModeMgr.merge(assessmentMode, forceStatus);
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) HashSet(java.util.HashSet)

Aggregations

AssessmentModeToGroup (org.olat.course.assessment.AssessmentModeToGroup)22 BusinessGroup (org.olat.group.BusinessGroup)22 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Test (org.junit.Test)16 Identity (org.olat.core.id.Identity)16 AssessmentMode (org.olat.course.assessment.AssessmentMode)16 BGArea (org.olat.group.area.BGArea)10 AssessmentModeToArea (org.olat.course.assessment.AssessmentModeToArea)8 HashSet (java.util.HashSet)4 Target (org.olat.course.assessment.AssessmentMode.Target)4 ArrayList (java.util.ArrayList)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 ICourse (org.olat.course.ICourse)2 Status (org.olat.course.assessment.AssessmentMode.Status)2 CourseNode (org.olat.course.nodes.CourseNode)2 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)2