From a1841cf8c0b39d558fc58f9a12d76c9ad70c639a Mon Sep 17 00:00:00 2001 From: lmihalkovic <laurent.michalkovic@frentix.com> Date: Fri, 20 May 2016 11:42:25 +0200 Subject: [PATCH] OO-2007: added membership summary information to course summary view --- .../olat/course/nodes/MembersCourseNode.java | 3 +- .../MembersCourseNodeRunController.java | 141 +------------- .../course/nodes/members/MembersHelpers.java | 173 +++++++++++++++++ .../members/MembersPeekViewController.java | 180 ++++++++++++++++++ 4 files changed, 359 insertions(+), 138 deletions(-) create mode 100644 src/main/java/org/olat/course/nodes/members/MembersHelpers.java create mode 100644 src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java diff --git a/src/main/java/org/olat/course/nodes/MembersCourseNode.java b/src/main/java/org/olat/course/nodes/MembersCourseNode.java index 70ccce9441d..c52146bec76 100644 --- a/src/main/java/org/olat/course/nodes/MembersCourseNode.java +++ b/src/main/java/org/olat/course/nodes/MembersCourseNode.java @@ -38,6 +38,7 @@ import org.olat.course.editor.formfragments.MembersSelectorFormFragment; import org.olat.course.nodes.info.InfoCourseNodeEditController; import org.olat.course.nodes.members.MembersCourseNodeEditController; import org.olat.course.nodes.members.MembersCourseNodeRunController; +import org.olat.course.nodes.members.MembersPeekViewController; import org.olat.course.run.navigation.NodeRunConstructionResult; import org.olat.course.run.userview.NodeEvaluation; import org.olat.course.run.userview.UserCourseEnvironment; @@ -145,7 +146,7 @@ public class MembersCourseNode extends AbstractAccessableCourseNode { @Override public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne) { - return super.createPeekViewRunController(ureq, wControl, userCourseEnv, ne); + return new MembersPeekViewController(ureq, wControl, userCourseEnv, this.getModuleConfiguration()); //TODO check if this is the desired // updateModuleConfigDefaults(false); diff --git a/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java b/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java index 9467ffa49e0..114010187d9 100644 --- a/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java +++ b/src/main/java/org/olat/course/nodes/members/MembersCourseNodeRunController.java @@ -31,7 +31,6 @@ import java.util.Set; import org.olat.NewControllerFactory; import org.olat.basesecurity.BaseSecurity; -import org.olat.basesecurity.GroupRoles; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -99,8 +98,6 @@ public class MembersCourseNodeRunController extends FormBasicController { private final boolean canEmail; private final boolean showOwners; -// private final boolean showCoaches; -// private final boolean showParticipants; private final boolean chatEnabled; private MembersMailController mailCtrl; @@ -137,8 +134,6 @@ public class MembersCourseNodeRunController extends FormBasicController { portraitManager = DisplayPortraitManager.getInstance(); showOwners = config.getBooleanSafe(MembersCourseNode.CONFIG_KEY_SHOWOWNER); -// showCoaches = config.getBooleanSafe(CONFIG_KEY_SHOWCOACHES); -// showParticipants = config.getBooleanSafe(CONFIG_KEY_SHOWPARTICIPANTS); chatEnabled = imModule.isEnabled() && imModule.isPrivateEnabled(); MembersCourseNodeConfiguration nodeConfig = (MembersCourseNodeConfiguration)CourseNodeFactory.getInstance().getCourseNodeConfiguration("cmembers"); @@ -157,7 +152,8 @@ public class MembersCourseNodeRunController extends FormBasicController { List<Identity> owners; if(showOwners) { - owners = getOwners(); + RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry(); + owners = MembersHelpers.getOwners(repositoryService, courseRepositoryEntry); } else { owners = Collections.emptyList(); } @@ -170,7 +166,7 @@ public class MembersCourseNodeRunController extends FormBasicController { || membersFrag.hasAnyOf(MembersCourseNode.CONFIG_KEY_COACHES_GROUP, MembersCourseNode.CONFIG_KEY_COACHES_AREA)) { CourseGroupManager cgm = courseEnv.getCourseGroupManager(); - addCoaches(membersFrag, cgm, coaches); + MembersHelpers.addCoaches(membersFrag, cgm, businessGroupService, coaches); showCoaches = true; } @@ -180,7 +176,7 @@ public class MembersCourseNodeRunController extends FormBasicController { || membersFrag.hasAnyOf(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP, MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA)) { CourseGroupManager cgm = courseEnv.getCourseGroupManager(); - addParticipants(membersFrag, cgm, participants); + MembersHelpers.addParticipants(membersFrag, cgm, businessGroupService, participants); showParticipants = true; } @@ -211,11 +207,6 @@ public class MembersCourseNodeRunController extends FormBasicController { } } - private List<Identity> getOwners() { - RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry(); - return repositoryService.getMembers(courseRepositoryEntry, GroupRoles.owner.name()); - } - private List<Member> initFormMemberList(String name, List<Identity> ids, Set<Long> duplicateCatcher, FormItemContainer formLayout, boolean withEmail) { String page = velocity_root + "/memberList.html"; @@ -476,128 +467,4 @@ public class MembersCourseNodeRunController extends FormBasicController { } } -// // ------------------- -// private List<Identity> retrieveOwnersFromCourse(CourseGroupManager cgm){; -// List<Identity> ownerList = repositoryService.getMembers(cgm.getCourseEntry(), GroupRoles.owner.name()); -// return ownerList; -// } - - // ------------------- - private void addCoaches(IModuleConfiguration moduleConfiguration, CourseGroupManager cgm, List<Identity> list) { - - if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_COACHES_GROUP)) { - String coachGroupNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_GROUP); - List<Long> coachGroupKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_GROUP_ID); - if(coachGroupKeys == null && StringHelper.containsNonWhitespace(coachGroupNames)) { - coachGroupKeys = businessGroupService.toGroupKeys(coachGroupNames, cgm.getCourseEntry()); - } - list.addAll(retrieveCoachesFromGroups(coachGroupKeys, cgm)); - } - - if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_COACHES_AREA)) { - String coachAreaNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_AREA); - List<Long> coachAreaKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_AREA_IDS); - if(coachAreaKeys == null && StringHelper.containsNonWhitespace(coachAreaNames)) { - coachAreaKeys = businessGroupService.toGroupKeys(coachAreaNames, cgm.getCourseEntry()); - } - list.addAll(retrieveCoachesFromAreas(coachAreaKeys, cgm)); - } - - if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_COURSE - , MembersCourseNode.CONFIG_KEY_COACHES_ALL)) { - list.addAll(retrieveCoachesFromCourse(cgm)); - } - if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_ALL)) { - list.addAll(retrieveCoachesFromCourseGroups(cgm)); - } - } - - private List<Identity> retrieveCoachesFromAreas(List<Long> areaKeys, CourseGroupManager cgm) { - List<Identity> coaches = cgm.getCoachesFromAreas(areaKeys); - Set<Identity> coachesWithoutDuplicates = new HashSet<Identity>(coaches); - coaches = new ArrayList<Identity>(coachesWithoutDuplicates); - return coaches; - } - - private List<Identity> retrieveCoachesFromGroups(List<Long> groupKeys, CourseGroupManager cgm) { - List<Identity> coaches = new ArrayList<Identity>(new HashSet<Identity>(cgm.getCoachesFromBusinessGroups(groupKeys))); - return coaches; - } - - private List<Identity> retrieveCoachesFromCourse(CourseGroupManager cgm) { - List<Identity> coaches = cgm.getCoaches(); - return coaches; - } - - private List<Identity> retrieveCoachesFromCourseGroups(CourseGroupManager cgm) { - Set<Identity> uniq = new HashSet<Identity>(); - { - List<Identity> coaches = cgm.getCoachesFromAreas(); - uniq.addAll(coaches); - } - { - List<Identity> coaches = cgm.getCoachesFromBusinessGroups(); - uniq.addAll(coaches); - } - return new ArrayList<Identity>(uniq); - } - - // ------------------- - private void addParticipants(IModuleConfiguration moduleConfiguration, CourseGroupManager cgm, List<Identity> list) { - - if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP)) { - String participantGroupNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP); - List<Long> participantGroupKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP_ID); - if(participantGroupKeys == null && StringHelper.containsNonWhitespace(participantGroupNames)) { - participantGroupKeys = businessGroupService.toGroupKeys(participantGroupNames, cgm.getCourseEntry()); - } - list.addAll(retrieveParticipantsFromGroups(participantGroupKeys, cgm)); - } - - if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA)) { - String participantAreaNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA); - List<Long> participantAreaKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA_ID); - if(participantAreaKeys == null && StringHelper.containsNonWhitespace(participantAreaNames)) { - participantAreaKeys = businessGroupService.toGroupKeys(participantAreaNames, cgm.getCourseEntry()); - } - list.addAll(retrieveParticipantsFromAreas(participantAreaKeys, cgm)); - } - - if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_COURSE - , MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL)) { - list.addAll(retrieveParticipantsFromCourse(cgm)); - } - if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL)) { - list.addAll(retrieveParticipantsFromCourseGroups(cgm)); - } - } - - private List<Identity> retrieveParticipantsFromAreas(List<Long> areaKeys, CourseGroupManager cgm) { - List<Identity> participiants = cgm.getParticipantsFromAreas(areaKeys); - return participiants; - } - - private List<Identity> retrieveParticipantsFromGroups(List<Long> groupKeys, CourseGroupManager cgm) { - List<Identity> participiants = cgm.getParticipantsFromBusinessGroups(groupKeys); - return participiants; - } - - private List<Identity> retrieveParticipantsFromCourse(CourseGroupManager cgm) { - List<Identity> participiants = cgm.getParticipants(); - return participiants; - } - - private List<Identity> retrieveParticipantsFromCourseGroups(CourseGroupManager cgm) { - Set<Identity> uniq = new HashSet<Identity>(); - { - List<Identity> participiants = cgm.getParticipantsFromAreas(); - uniq.addAll(participiants); - } - { - List<Identity> participiants = cgm.getParticipantsFromBusinessGroups(); - uniq.addAll(participiants); - } - return new ArrayList<Identity>(uniq); - } - } diff --git a/src/main/java/org/olat/course/nodes/members/MembersHelpers.java b/src/main/java/org/olat/course/nodes/members/MembersHelpers.java new file mode 100644 index 00000000000..5beb12d2ac1 --- /dev/null +++ b/src/main/java/org/olat/course/nodes/members/MembersHelpers.java @@ -0,0 +1,173 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.nodes.members; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.olat.basesecurity.GroupRoles; +import org.olat.core.id.Identity; +import org.olat.core.util.StringHelper; +import org.olat.course.groupsandrights.CourseGroupManager; +import org.olat.course.nodes.MembersCourseNode; +import org.olat.group.BusinessGroupService; +import org.olat.modules.IModuleConfiguration; +import org.olat.repository.RepositoryEntry; +import org.olat.repository.RepositoryService; + +/** + * + * <p>Initial date: May 20, 2016 + * @author lmihalkovic, http://www.frentix.com + */ +/*public*/ class MembersHelpers { + private MembersHelpers() { + // CANNOT CREATE + } + + // ----------------------------------------------------- + + static List<Identity> getOwners(RepositoryService repositoryService, RepositoryEntry courseRepositoryEntry) { + return repositoryService.getMembers(courseRepositoryEntry, GroupRoles.owner.name()); + } + + // ----------------------------------------------------- + + static void addCoaches(IModuleConfiguration moduleConfiguration, CourseGroupManager cgm, BusinessGroupService bgs, List<Identity> list) { + + if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_COACHES_GROUP)) { + String coachGroupNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_GROUP); + List<Long> coachGroupKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_GROUP_ID); + if(coachGroupKeys == null && StringHelper.containsNonWhitespace(coachGroupNames)) { + coachGroupKeys = bgs.toGroupKeys(coachGroupNames, cgm.getCourseEntry()); + } + list.addAll(retrieveCoachesFromGroups(coachGroupKeys, cgm)); + } + + if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_COACHES_AREA)) { + String coachAreaNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_AREA); + List<Long> coachAreaKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_COACHES_AREA_IDS); + if(coachAreaKeys == null && StringHelper.containsNonWhitespace(coachAreaNames)) { + coachAreaKeys = bgs.toGroupKeys(coachAreaNames, cgm.getCourseEntry()); + } + list.addAll(retrieveCoachesFromAreas(coachAreaKeys, cgm)); + } + + if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_COURSE + , MembersCourseNode.CONFIG_KEY_COACHES_ALL)) { + list.addAll(retrieveCoachesFromCourse(cgm)); + } + if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_ALL)) { + list.addAll(retrieveCoachesFromCourseGroups(cgm)); + } + } + + static List<Identity> retrieveCoachesFromAreas(List<Long> areaKeys, CourseGroupManager cgm) { + List<Identity> coaches = cgm.getCoachesFromAreas(areaKeys); + Set<Identity> coachesWithoutDuplicates = new HashSet<Identity>(coaches); + coaches = new ArrayList<Identity>(coachesWithoutDuplicates); + return coaches; + } + + static List<Identity> retrieveCoachesFromGroups(List<Long> groupKeys, CourseGroupManager cgm) { + List<Identity> coaches = new ArrayList<Identity>(new HashSet<Identity>(cgm.getCoachesFromBusinessGroups(groupKeys))); + return coaches; + } + + static List<Identity> retrieveCoachesFromCourse(CourseGroupManager cgm) { + List<Identity> coaches = cgm.getCoaches(); + return coaches; + } + + static List<Identity> retrieveCoachesFromCourseGroups(CourseGroupManager cgm) { + Set<Identity> uniq = new HashSet<Identity>(); + { + List<Identity> coaches = cgm.getCoachesFromAreas(); + uniq.addAll(coaches); + } + { + List<Identity> coaches = cgm.getCoachesFromBusinessGroups(); + uniq.addAll(coaches); + } + return new ArrayList<Identity>(uniq); + } + + // ----------------------------------------------------- + + static void addParticipants(IModuleConfiguration moduleConfiguration, CourseGroupManager cgm, BusinessGroupService bgs, List<Identity> list) { + + if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP)) { + String participantGroupNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP); + List<Long> participantGroupKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_GROUP_ID); + if(participantGroupKeys == null && StringHelper.containsNonWhitespace(participantGroupNames)) { + participantGroupKeys = bgs.toGroupKeys(participantGroupNames, cgm.getCourseEntry()); + } + list.addAll(retrieveParticipantsFromGroups(participantGroupKeys, cgm)); + } + + if(moduleConfiguration.has(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA)) { + String participantAreaNames = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA); + List<Long> participantAreaKeys = moduleConfiguration.val(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_AREA_ID); + if(participantAreaKeys == null && StringHelper.containsNonWhitespace(participantAreaNames)) { + participantAreaKeys = bgs.toGroupKeys(participantAreaNames, cgm.getCourseEntry()); + } + list.addAll(retrieveParticipantsFromAreas(participantAreaKeys, cgm)); + } + + if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_COURSE + , MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL)) { + list.addAll(retrieveParticipantsFromCourse(cgm)); + } + if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_PARTICIPANTS_ALL)) { + list.addAll(retrieveParticipantsFromCourseGroups(cgm)); + } + } + + static List<Identity> retrieveParticipantsFromAreas(List<Long> areaKeys, CourseGroupManager cgm) { + List<Identity> participiants = cgm.getParticipantsFromAreas(areaKeys); + return participiants; + } + + static List<Identity> retrieveParticipantsFromGroups(List<Long> groupKeys, CourseGroupManager cgm) { + List<Identity> participiants = cgm.getParticipantsFromBusinessGroups(groupKeys); + return participiants; + } + + static List<Identity> retrieveParticipantsFromCourse(CourseGroupManager cgm) { + List<Identity> participiants = cgm.getParticipants(); + return participiants; + } + + static List<Identity> retrieveParticipantsFromCourseGroups(CourseGroupManager cgm) { + Set<Identity> uniq = new HashSet<Identity>(); + { + List<Identity> participiants = cgm.getParticipantsFromAreas(); + uniq.addAll(participiants); + } + { + List<Identity> participiants = cgm.getParticipantsFromBusinessGroups(); + uniq.addAll(participiants); + } + return new ArrayList<Identity>(uniq); + } + +} diff --git a/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java b/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java new file mode 100644 index 00000000000..e6d7527e67f --- /dev/null +++ b/src/main/java/org/olat/course/nodes/members/MembersPeekViewController.java @@ -0,0 +1,180 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.nodes.members; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.table.ColumnDescriptor; +import org.olat.core.gui.components.table.DefaultColumnDescriptor; +import org.olat.core.gui.components.table.DefaultTableDataModel; +import org.olat.core.gui.components.table.TableController; +import org.olat.core.gui.components.table.TableGuiConfiguration; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.core.id.Identity; +import org.olat.course.groupsandrights.CourseGroupManager; +import org.olat.course.run.environment.CourseEnvironment; +import org.olat.course.run.userview.UserCourseEnvironment; +import org.olat.group.BusinessGroupService; +import org.olat.modules.IModuleConfiguration; +import org.olat.modules.ModuleConfiguration; +import org.olat.repository.RepositoryEntry; +import org.olat.repository.RepositoryService; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * + * <p>Initial date: May 19, 2016 + * @author lmihalkovic, http://www.frentix.com + */ +public class MembersPeekViewController extends BasicController { + + @Autowired + private RepositoryService repositoryService; + @Autowired + private BusinessGroupService businessGroupService; + + + private final CourseEnvironment courseEnv; + private TableController tableController; + + List<Row> entries = new ArrayList<>(); + + public MembersPeekViewController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, ModuleConfiguration config) { + super(ureq, wControl); + + courseEnv = userCourseEnv.getCourseEnvironment(); + + readFormData(config); + initForm(ureq, userCourseEnv); + } + + private void initForm(UserRequest ureq, UserCourseEnvironment courseEnv) { + + TableGuiConfiguration tableConfig = new TableGuiConfiguration(); + tableConfig.setDisplayTableHeader(false); + tableConfig.setCustomCssClass("o_portlet_table table-condensed"); + tableConfig.setDisplayRowCount(false); + tableConfig.setPageingEnabled(false); + tableConfig.setDownloadOffered(false); + tableConfig.setSortingEnabled(false); + + removeAsListenerAndDispose(tableController); + tableController = new TableController(tableConfig, ureq, getWindowControl(), getTranslator()); + listenTo(tableController); + + tableController.addColumnDescriptor(new DefaultColumnDescriptor("members.type", 0, null, ureq.getLocale())); + tableController.addColumnDescriptor(new DefaultColumnDescriptor("members.count", 1, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT)); + tableController.setTableDataModel(new DefaultTableDataModel<Row>(entries) { + @Override + public int getColumnCount() { + return 2; + } + + @Override + public Object getValueAt(int row, int col) { + Row r = entries.get(row); + if (col == 0) { return r.col1; } + if (col == 1) { return r.col2; } + return null; + } + }); + + putInitialPanel(tableController.getInitialComponent()); + + } + + protected void readFormData(ModuleConfiguration config) { + IModuleConfiguration membersFrag = IModuleConfiguration.fragment("members", config); + + CourseGroupManager cgm = courseEnv.getCourseGroupManager(); + + + RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry(); + List<Identity> owners = MembersHelpers.getOwners(repositoryService, courseRepositoryEntry); + + List<Identity> coaches = new ArrayList<>(); + MembersHelpers.addCoaches(membersFrag, cgm, businessGroupService, coaches); + + List<Identity> participants = new ArrayList<>(); + MembersHelpers.addParticipants(membersFrag, cgm, businessGroupService, participants); + + Set<Long> duplicateCatcher = new HashSet<Long>(); + List<Identity> filteredOwners = owners.stream() + .filter(ident -> { + if (duplicateCatcher.contains(ident.getKey())) { + return false; + } + duplicateCatcher.add(ident.getKey()); + return true; + }) + .collect(Collectors.toList()); + + List<Identity> filteredCoaches = coaches.stream() + .filter(ident -> { + if (duplicateCatcher.contains(ident.getKey())) { + return false; + } + duplicateCatcher.add(ident.getKey()); + return true; + }) + .collect(Collectors.toList()); + + List<Identity> filteredParticipants = participants.stream() + .filter(ident -> { + if (duplicateCatcher.contains(ident.getKey())) { + return false; + } + duplicateCatcher.add(ident.getKey()); + return true; + }) + .collect(Collectors.toList()); + + entries.add(new Row(translate("members.owners"), Integer.toString(filteredOwners.size()))); + entries.add(new Row(translate("members.coaches"), Integer.toString(filteredCoaches.size()))); + entries.add(new Row(translate("members.participants"), Integer.toString(filteredParticipants.size()))); + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // nothing + } + + @Override + protected void doDispose() { + // nothing + } + + private static class Row { + String col1; + String col2; + public Row(String col1, String col2) { + this.col1 = col1; + this.col2 = col2; + } + } +} -- GitLab