Search in sources :

Example 26 with BusinessGroupMembership

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

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 27 with BusinessGroupMembership

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

the class BusinessGroupMainRunController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == bgEditCntrllr) {
        // changes from the admin controller
        if (event == Event.CHANGED_EVENT) {
            businessGroup = bgEditCntrllr.getBusinessGroup();
            chatAvailable = isChatAvailable();
            TreeModel trMdl = buildTreeModel();
            bgTree.setTreeModel(trMdl);
            bgTree.setSelectedNode(nodeAdmin);
        } else if (event == Event.CANCELLED_EVENT) {
            // could not get lock on business group, back to inital screen
            bgTree.setSelectedNodeId(bgTree.getTreeModel().getRootNode().getIdent());
            mainPanel.setContent(main);
        }
    } else if (source == resourcesCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            int rowid = te.getRowId();
            RepositoryTableModel repoTableModel = (RepositoryTableModel) resourcesCtr.getTableDataModel();
            if (RepositoryTableModel.TABLE_ACTION_SELECT_LINK.equals(actionid)) {
                RepositoryEntry currentRepoEntry = repoTableModel.getObject(rowid);
                OLATResource ores = currentRepoEntry.getOlatResource();
                if (ores == null)
                    throw new AssertException("repoEntry had no olatresource, repoKey = " + currentRepoEntry.getKey());
                addLoggingResourceable(LoggingResourceable.wrap(ores, OlatResourceableType.genRepoEntry));
                String businessPath = "[RepositoryEntry:" + currentRepoEntry.getKey() + "]";
                NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
            }
        }
    } else if (source == sendToChooserForm) {
        if (event == Event.DONE_EVENT) {
            removeAsListenerAndDispose(collabToolCtr);
            collabToolCtr = createContactFormController(ureq);
            listenTo(collabToolCtr);
            mainPanel.setContent(collabToolCtr.getInitialComponent());
        } else if (event == Event.CANCELLED_EVENT) {
            // back to group overview
            bgTree.setSelectedNodeId(bgTree.getTreeModel().getRootNode().getIdent());
            mainPanel.setContent(main);
        }
    } else if (source == collabToolCtr) {
        if (event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.BACK_EVENT || event == Event.FAILED_EVENT) {
            // In all cases (success or failure) we
            // go back to the group overview page.
            bgTree.setSelectedNodeId(bgTree.getTreeModel().getRootNode().getIdent());
            mainPanel.setContent(main);
        }
    } else if (source == accessController) {
        if (event.equals(AccessEvent.ACCESS_OK_EVENT)) {
            removeAsListenerAndDispose(accessController);
            accessController = null;
            // check if on waiting list
            List<BusinessGroupMembership> memberships = businessGroupService.getBusinessGroupMembership(Collections.singletonList(businessGroup.getKey()), getIdentity());
            if (isOnWaitinglist(memberships)) {
                Component cmp = getOnWaitingListMessage(ureq, businessGroup);
                mainPanel.setContent(cmp);
            } else {
                mainPanel.setContent(main);
                bgTree.setTreeModel(buildTreeModel());
                needActivation = false;
            }
        } else if (event.equals(AccessEvent.ACCESS_FAILED_EVENT)) {
            String msg = ((AccessEvent) event).getMessage();
            if (StringHelper.containsNonWhitespace(msg)) {
                getWindowControl().setError(msg);
            } else {
                showError("error.accesscontrol");
            }
        }
    }
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryTableModel(org.olat.repository.ui.RepositoryTableModel) AssertException(org.olat.core.logging.AssertException) TableEvent(org.olat.core.gui.components.table.TableEvent) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Component(org.olat.core.gui.components.Component)

Example 28 with BusinessGroupMembership

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

the class AbstractMemberListController method updateTableModel.

protected List<MemberView> updateTableModel(SearchMembersParams params) {
    // course membership
    boolean managedMembersRepo = RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.membersmanagement);
    List<RepositoryEntryMembership> repoMemberships = repoEntry == null ? Collections.<RepositoryEntryMembership>emptyList() : repositoryManager.getRepositoryEntryMembership(repoEntry);
    // groups membership
    List<BusinessGroup> groups = repoEntry == null ? Collections.singletonList(businessGroup) : businessGroupService.findBusinessGroups(null, repoEntry, 0, -1);
    List<Long> groupKeys = new ArrayList<Long>();
    Map<Long, BusinessGroupShort> keyToGroupMap = new HashMap<>();
    for (BusinessGroup group : groups) {
        groupKeys.add(group.getKey());
        keyToGroupMap.put(group.getKey(), group);
    }
    List<BusinessGroupMembership> memberships = groups.isEmpty() ? Collections.<BusinessGroupMembership>emptyList() : businessGroupService.getBusinessGroupsMembership(groups);
    // get identities
    Set<Long> identityKeys = new HashSet<>();
    for (RepositoryEntryMembership membership : repoMemberships) {
        identityKeys.add(membership.getIdentityKey());
    }
    for (BusinessGroupMembership membership : memberships) {
        identityKeys.add(membership.getIdentityKey());
    }
    List<Identity> identities;
    if (identityKeys.isEmpty()) {
        identities = new ArrayList<>(0);
    } else {
        identities = filterIdentities(params, identityKeys);
    }
    Map<Long, MemberView> keyToMemberMap = new HashMap<>();
    List<MemberView> memberList = new ArrayList<>();
    Locale locale = getLocale();
    // reservations
    if (params.isPending()) {
        List<OLATResource> resourcesForReservations = new ArrayList<>();
        if (repoEntry != null) {
            resourcesForReservations.add(repoEntry.getOlatResource());
        }
        for (BusinessGroup group : groups) {
            resourcesForReservations.add(group.getResource());
        }
        List<ResourceReservation> reservations = acService.getReservations(resourcesForReservations);
        List<Long> pendingIdentityKeys = new ArrayList<>(reservations.size());
        for (ResourceReservation reservation : reservations) {
            pendingIdentityKeys.add(reservation.getIdentity().getKey());
        }
        if (StringHelper.containsNonWhitespace(params.getSearchString()) || StringHelper.containsNonWhitespace(params.getLogin()) || (params.getUserPropertiesSearch() != null && !params.getUserPropertiesSearch().isEmpty())) {
            List<Identity> pendingIdentities = filterIdentities(params, pendingIdentityKeys);
            pendingIdentityKeys.retainAll(PersistenceHelper.toKeys(pendingIdentities));
        }
        for (ResourceReservation reservation : reservations) {
            Identity identity = reservation.getIdentity();
            if (pendingIdentityKeys.contains(identity.getKey())) {
                MemberView member = new MemberView(identity, userPropertyHandlers, locale);
                member.getMembership().setPending(true);
                memberList.add(member);
                forgeLinks(member);
                keyToMemberMap.put(identity.getKey(), member);
            }
        }
    }
    Long me = getIdentity().getKey();
    Set<Long> loadStatus = new HashSet<>();
    for (Identity identity : identities) {
        MemberView member = new MemberView(identity, userPropertyHandlers, locale);
        if (chatEnabled) {
            if (identity.getKey().equals(me)) {
                member.setOnlineStatus("me");
            } else if (sessionManager.isOnline(identity.getKey())) {
                loadStatus.add(identity.getKey());
            } else {
                member.setOnlineStatus(Presence.unavailable.name());
            }
        }
        memberList.add(member);
        forgeLinks(member);
        keyToMemberMap.put(identity.getKey(), member);
    }
    if (loadStatus.size() > 0) {
        List<Long> statusToLoadList = new ArrayList<>(loadStatus);
        Map<Long, String> statusMap = imService.getBuddyStatus(statusToLoadList);
        for (Long toLoad : statusToLoadList) {
            String status = statusMap.get(toLoad);
            MemberView member = keyToMemberMap.get(toLoad);
            if (status == null) {
                member.setOnlineStatus(Presence.available.name());
            } else {
                member.setOnlineStatus(status);
            }
        }
    }
    for (BusinessGroupMembership membership : memberships) {
        Long identityKey = membership.getIdentityKey();
        MemberView memberView = keyToMemberMap.get(identityKey);
        if (memberView != null) {
            memberView.setFirstTime(membership.getCreationDate());
            memberView.setLastTime(membership.getLastModified());
            if (membership.isOwner()) {
                memberView.getMembership().setGroupTutor(true);
            }
            if (membership.isParticipant()) {
                memberView.getMembership().setGroupParticipant(true);
            }
            if (membership.isWaiting()) {
                memberView.getMembership().setGroupWaiting(true);
            }
            Long groupKey = membership.getGroupKey();
            BusinessGroupShort group = keyToGroupMap.get(groupKey);
            memberView.addGroup(group);
        }
    }
    for (RepositoryEntryMembership membership : repoMemberships) {
        Long identityKey = membership.getIdentityKey();
        MemberView memberView = keyToMemberMap.get(identityKey);
        if (memberView != null) {
            memberView.setFirstTime(membership.getCreationDate());
            memberView.setLastTime(membership.getLastModified());
            memberView.getMembership().setManagedMembersRepo(managedMembersRepo);
            if (membership.isOwner()) {
                memberView.getMembership().setRepoOwner(true);
            }
            if (membership.isCoach()) {
                memberView.getMembership().setRepoTutor(true);
            }
            if (membership.isParticipant()) {
                memberView.getMembership().setRepoParticipant(true);
            }
        }
    }
    if (repoEntry != null) {
        Map<Long, Date> lastLaunchDates = userInfosMgr.getRecentLaunchDates(repoEntry.getOlatResource());
        for (MemberView memberView : keyToMemberMap.values()) {
            Long identityKey = memberView.getIdentityKey();
            Date date = lastLaunchDates.get(identityKey);
            memberView.setLastTime(date);
        }
    }
    // the order of the filter is important
    filterByRoles(memberList, params);
    filterByOrigin(memberList, params);
    memberListModel.setObjects(memberList);
    membersTable.reset(true, true, true);
    return memberList;
}
Also used : Locale(java.util.Locale) BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupShort(org.olat.group.BusinessGroupShort) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 29 with BusinessGroupMembership

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

Example 30 with BusinessGroupMembership

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

the class FavoritBusinessGroupListController method searchTableItems.

@Override
protected List<BGTableItem> searchTableItems(BusinessGroupQueryParams params) {
    List<BusinessGroupRow> rows = businessGroupService.findBusinessGroupsWithMemberships(params, getIdentity());
    List<BGTableItem> items = new ArrayList<>(rows.size());
    for (BusinessGroupRow 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);
        items.add(item);
    }
    return items;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) BusinessGroupRow(org.olat.group.model.BusinessGroupRow)

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