Search in sources :

Example 21 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership 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 22 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership in project OpenOLAT by OpenOLAT.

the class CourseBusinessGroupListController method searchTableItems.

@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
    List<StatisticsBusinessGroupRow> rows = businessGroupService.findBusinessGroupsFromRepositoryEntry(params, getIdentity(), getResource());
    List<BGTableItem> items = new ArrayList<>(rows.size());
    for (StatisticsBusinessGroupRow row : rows) {
        BusinessGroupMembership membership = row.getMember();
        Boolean allowLeave = membership != null;
        Boolean allowDelete = isAdmin() ? Boolean.TRUE : (membership == null ? null : new Boolean(membership.isOwner()));
        FormLink markLink = uifactory.addFormLink("mark_" + row.getKey(), "mark", "", null, null, Link.NONTRANSLATED);
        markLink.setIconLeftCSS(row.isMarked() ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
        BGTableItem item = new BGTableItem(row, markLink, allowLeave, allowDelete);
        item.setNumOfOwners(row.getNumOfCoaches());
        item.setNumOfParticipants(row.getNumOfParticipants());
        item.setNumWaiting(row.getNumWaiting());
        item.setNumOfPendings(row.getNumPending());
        items.add(item);
    }
    return items;
}
Also used : StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupMembership(org.olat.group.BusinessGroupMembership) BGTableItem(org.olat.group.ui.main.BGTableItem) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 23 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership in project openolat by klemens.

the class MembersTableController method getMembersFromIdentity.

private List<MemberView> getMembersFromIdentity(UserRequest ureq, List<Identity> identities, Map<Long, BusinessGroupMembership> groupmemberships, Map<Long, Date> recentLaunches, Map<Long, Date> initialLaunches) {
    if (!deduplicateList) {
        duplicateCatcher = new HashSet<>();
    }
    List<MemberView> memberList = new ArrayList<>();
    for (Identity identity : identities) {
        MemberView member = new MemberView(identity, userPropertyHandlers, getLocale());
        if (userLastTimeVisible) {
            if (repoEntry == null) {
                BusinessGroupMembership groupmembership = groupmemberships.get(identity.getKey());
                if (groupmembership != null) {
                    member.setFirstTime(groupmembership.getCreationDate());
                    member.setLastTime(groupmembership.getLastModified());
                }
            } else {
                member.setFirstTime(initialLaunches.get(identity.getKey()));
                member.setLastTime(recentLaunches.get(identity.getKey()));
            }
        }
        if (!duplicateCatcher.contains(member)) {
            memberList.add(member);
            if (!identity.equals(ureq.getIdentity())) {
                forgeChatLink(member);
            }
        }
        duplicateCatcher.add(member);
    }
    return memberList;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) MemberView(org.olat.group.ui.main.MemberView)

Example 24 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership in project openolat by klemens.

the class MembersExportManager method getGroupMembershipMap.

public Map<Long, BusinessGroupMembership> getGroupMembershipMap(List<BusinessGroup> groups) {
    List<BusinessGroupMembership> groupMemberships = businessGroupService.getBusinessGroupsMembership(groups);
    Map<Long, BusinessGroupMembership> map = new HashMap<>();
    for (BusinessGroupMembership membership : groupMemberships) {
        map.put(membership.getIdentityKey(), membership);
    }
    return map;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) HashMap(java.util.HashMap)

Example 25 with BusinessGroupMembership

use of org.olat.group.BusinessGroupMembership in project openolat by klemens.

the class MembersExportManager method getXlsMediaResource.

public MediaResource getXlsMediaResource(boolean showOwners, boolean showCoaches, boolean showParticipants, boolean showWaiting, List<Identity> owners, List<Identity> coaches, List<Identity> participants, List<Identity> waiting, Translator translator, List<UserPropertyHandler> userPropertyHandlers, RepositoryEntry repoEntry, BusinessGroup businessGroup) {
    // TODO
    Map<Long, BusinessGroupMembership> groupmemberships;
    Map<Long, RepositoryEntryMembership> repomemberships;
    if (repoEntry == null) {
        List<BusinessGroup> groups = new ArrayList<>();
        groups.add(businessGroup);
        groupmemberships = getGroupMembershipMap(groups);
        repomemberships = new HashMap<>();
    } else {
        repomemberships = getRepoMembershipMap(repoEntry);
        List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, repoEntry, 0, -1);
        groupmemberships = getGroupMembershipMap(groups);
    }
    List<List<Identity>> roleMembers = new ArrayList<>();
    if (showOwners) {
        roleMembers.add(owners);
    }
    if (showCoaches) {
        roleMembers.add(coaches);
    }
    if (showParticipants) {
        roleMembers.add(participants);
    }
    if (showWaiting) {
        roleMembers.add(waiting);
    }
    Translator repoTranslator = Util.createPackageTranslator(Member.class, translator.getLocale());
    Translator groupTranslator = Util.createPackageTranslator(GroupMembersRunController.class, translator.getLocale());
    Map<Identity, StringBuilder> membersMap = new HashMap<>();
    List<Identity> rows = new ArrayList<>();
    for (List<Identity> membersList : roleMembers) {
        for (Identity member : membersList) {
            Long memberKey = member.getKey();
            if (repomemberships != null && !repomemberships.isEmpty() && repomemberships.containsKey(memberKey)) {
                RepositoryEntryMembership repomembership = repomemberships.get(memberKey);
                if (repomembership.isOwner()) {
                    putRoleToMember(rows, membersMap, member, "owners", repoTranslator);
                }
                if (repomembership.isCoach()) {
                    putRoleToMember(rows, membersMap, member, "coaches", repoTranslator);
                }
                if (repomembership.isParticipant()) {
                    putRoleToMember(rows, membersMap, member, "participants", repoTranslator);
                }
            }
            if (groupmemberships != null && !groupmemberships.isEmpty() && groupmemberships.containsKey(memberKey)) {
                BusinessGroupMembership groupmembership = groupmemberships.get(memberKey);
                if (groupmembership.isOwner()) {
                    putRoleToMember(rows, membersMap, member, "coaches", groupTranslator);
                }
                if (groupmembership.isParticipant()) {
                    putRoleToMember(rows, membersMap, member, "participants", groupTranslator);
                }
                if (groupmembership.isWaiting()) {
                    putRoleToMember(rows, membersMap, member, "waiting", groupTranslator);
                }
            }
        }
    }
    Translator handlerTranslator = userManager.getPropertyHandlerTranslator(translator);
    XlsMembersExport exporter = new XlsMembersExport();
    MediaResource resource = exporter.export(rows, membersMap, handlerTranslator, userPropertyHandlers);
    return resource;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) List(java.util.List) MediaResource(org.olat.core.gui.media.MediaResource) Identity(org.olat.core.id.Identity)

Aggregations

BusinessGroupMembership (org.olat.group.BusinessGroupMembership)34 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 Identity (org.olat.core.id.Identity)10 BusinessGroup (org.olat.group.BusinessGroup)10 RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)8 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 HashSet (java.util.HashSet)4 List (java.util.List)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 Locale (java.util.Locale)2 Test (org.junit.Test)2 Component (org.olat.core.gui.components.Component)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)2