Search in sources :

Example 1 with BGPermission

use of org.olat.course.member.PermissionHelper.BGPermission in project OpenOLAT by OpenOLAT.

the class EditMembershipController method loadModel.

private void loadModel(Identity memberToLoad) {
    BusinessGroupQueryParams params = new BusinessGroupQueryParams();
    if (repoEntry == null) {
        params.setBusinessGroupKey(businessGroup.getKey());
    } else {
        params.setRepositoryEntry(repoEntry);
    }
    List<StatisticsBusinessGroupRow> groups = businessGroupService.findBusinessGroupsStatistics(params);
    if (groups.size() > 1) {
        Collections.sort(groups, new BusinessGroupRowComparator(getLocale()));
    }
    boolean defaultMembership = false;
    if (memberToLoad == null) {
        if (repoEntry != null && groups.isEmpty()) {
            boolean managed = RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.membersmanagement) && !overrideManaged;
            if (!managed) {
                repoRightsEl.select("participant", true);
            }
        } else if (repoEntry == null && groups.size() == 1) {
            boolean managed = BusinessGroupManagedFlag.isManaged(groups.get(0).getManagedFlags(), BusinessGroupManagedFlag.membersmanagement) && !overrideManaged;
            if (!managed) {
                defaultMembership = true;
            }
        }
    }
    List<Long> businessGroupKeys = new ArrayList<>(groups.size());
    groups.forEach(group -> businessGroupKeys.add(group.getKey()));
    groupMemberships = memberToLoad == null ? Collections.<BusinessGroupMembership>emptyList() : businessGroupService.getBusinessGroupMembership(businessGroupKeys, memberToLoad);
    List<MemberOption> options = new ArrayList<MemberOption>();
    for (StatisticsBusinessGroupRow group : groups) {
        boolean managed = BusinessGroupManagedFlag.isManaged(group.getManagedFlags(), BusinessGroupManagedFlag.membersmanagement) && !overrideManaged;
        MemberOption option = new MemberOption(group);
        BGPermission bgPermission = PermissionHelper.getPermission(group.getKey(), memberToLoad, groupMemberships);
        option.setTutor(createSelection(bgPermission.isTutor(), !managed, GroupRoles.coach.name()));
        option.setParticipant(createSelection(bgPermission.isParticipant() || defaultMembership, !managed, GroupRoles.participant.name()));
        boolean waitingListEnable = !managed && group.isWaitingListEnabled();
        option.setWaiting(createSelection(bgPermission.isWaitingList(), waitingListEnable, GroupRoles.waiting.name()));
        options.add(option);
    }
    tableDataModel.setObjects(options);
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BusinessGroupRowComparator(org.olat.group.model.comparator.BusinessGroupRowComparator) BGPermission(org.olat.course.member.PermissionHelper.BGPermission) ArrayList(java.util.ArrayList)

Example 2 with BGPermission

use of org.olat.course.member.PermissionHelper.BGPermission in project OpenOLAT by OpenOLAT.

the class EditMembershipController method collectGroupChanges.

public void collectGroupChanges(MemberPermissionChangeEvent e) {
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    for (MemberOption option : tableDataModel.getObjects()) {
        BGPermission bgPermission = PermissionHelper.getPermission(option.getGroupKey(), member, groupMemberships);
        BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(member, option.getGroup());
        boolean bgTutor = option.getTutor().isAtLeastSelected(1);
        change.setTutor(bgPermission.isTutor() == bgTutor ? null : new Boolean(bgTutor));
        boolean bgParticipant = option.getParticipant().isAtLeastSelected(1);
        change.setParticipant(bgPermission.isParticipant() == bgParticipant ? null : new Boolean(bgParticipant));
        boolean bgWaitingList = option.getWaiting().isEnabled() && option.getWaiting().isAtLeastSelected(1);
        change.setWaitingList(bgPermission.isWaitingList() == bgWaitingList ? null : new Boolean(bgWaitingList));
        if (change.getTutor() != null || change.getParticipant() != null || change.getWaitingList() != null) {
            changes.add(change);
        }
    }
    e.setGroupChanges(changes);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) BGPermission(org.olat.course.member.PermissionHelper.BGPermission) ArrayList(java.util.ArrayList)

Example 3 with BGPermission

use of org.olat.course.member.PermissionHelper.BGPermission in project openolat by klemens.

the class EditMembershipController method collectGroupChanges.

public void collectGroupChanges(MemberPermissionChangeEvent e) {
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    for (MemberOption option : tableDataModel.getObjects()) {
        BGPermission bgPermission = PermissionHelper.getPermission(option.getGroupKey(), member, groupMemberships);
        BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(member, option.getGroup());
        boolean bgTutor = option.getTutor().isAtLeastSelected(1);
        change.setTutor(bgPermission.isTutor() == bgTutor ? null : new Boolean(bgTutor));
        boolean bgParticipant = option.getParticipant().isAtLeastSelected(1);
        change.setParticipant(bgPermission.isParticipant() == bgParticipant ? null : new Boolean(bgParticipant));
        boolean bgWaitingList = option.getWaiting().isEnabled() && option.getWaiting().isAtLeastSelected(1);
        change.setWaitingList(bgPermission.isWaitingList() == bgWaitingList ? null : new Boolean(bgWaitingList));
        if (change.getTutor() != null || change.getParticipant() != null || change.getWaitingList() != null) {
            changes.add(change);
        }
    }
    e.setGroupChanges(changes);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) BGPermission(org.olat.course.member.PermissionHelper.BGPermission) ArrayList(java.util.ArrayList)

Example 4 with BGPermission

use of org.olat.course.member.PermissionHelper.BGPermission in project openolat by klemens.

the class EditMembershipController method loadModel.

private void loadModel(Identity memberToLoad) {
    BusinessGroupQueryParams params = new BusinessGroupQueryParams();
    if (repoEntry == null) {
        params.setBusinessGroupKey(businessGroup.getKey());
    } else {
        params.setRepositoryEntry(repoEntry);
    }
    List<StatisticsBusinessGroupRow> groups = businessGroupService.findBusinessGroupsStatistics(params);
    if (groups.size() > 1) {
        Collections.sort(groups, new BusinessGroupRowComparator(getLocale()));
    }
    boolean defaultMembership = false;
    if (memberToLoad == null) {
        if (repoEntry != null && groups.isEmpty()) {
            boolean managed = RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.membersmanagement) && !overrideManaged;
            if (!managed) {
                repoRightsEl.select("participant", true);
            }
        } else if (repoEntry == null && groups.size() == 1) {
            boolean managed = BusinessGroupManagedFlag.isManaged(groups.get(0).getManagedFlags(), BusinessGroupManagedFlag.membersmanagement) && !overrideManaged;
            if (!managed) {
                defaultMembership = true;
            }
        }
    }
    List<Long> businessGroupKeys = new ArrayList<>(groups.size());
    groups.forEach(group -> businessGroupKeys.add(group.getKey()));
    groupMemberships = memberToLoad == null ? Collections.<BusinessGroupMembership>emptyList() : businessGroupService.getBusinessGroupMembership(businessGroupKeys, memberToLoad);
    List<MemberOption> options = new ArrayList<MemberOption>();
    for (StatisticsBusinessGroupRow group : groups) {
        boolean managed = BusinessGroupManagedFlag.isManaged(group.getManagedFlags(), BusinessGroupManagedFlag.membersmanagement) && !overrideManaged;
        MemberOption option = new MemberOption(group);
        BGPermission bgPermission = PermissionHelper.getPermission(group.getKey(), memberToLoad, groupMemberships);
        option.setTutor(createSelection(bgPermission.isTutor(), !managed, GroupRoles.coach.name()));
        option.setParticipant(createSelection(bgPermission.isParticipant() || defaultMembership, !managed, GroupRoles.participant.name()));
        boolean waitingListEnable = !managed && group.isWaitingListEnabled();
        option.setWaiting(createSelection(bgPermission.isWaitingList(), waitingListEnable, GroupRoles.waiting.name()));
        options.add(option);
    }
    tableDataModel.setObjects(options);
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BusinessGroupRowComparator(org.olat.group.model.comparator.BusinessGroupRowComparator) BGPermission(org.olat.course.member.PermissionHelper.BGPermission) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)4 BGPermission (org.olat.course.member.PermissionHelper.BGPermission)4 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupMembershipChange (org.olat.group.model.BusinessGroupMembershipChange)2 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)2 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)2 BusinessGroupRowComparator (org.olat.group.model.comparator.BusinessGroupRowComparator)2