From a2f368f93f9ff444214ed249216079a4bbae3bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Almansa=20Le=C3=A1ndrez?= Date: Tue, 11 Jul 2017 16:36:32 +0200 Subject: [PATCH] SAK-32515 Section Info: Improve sorting functionality by including 'readOnly' sections in the 'unassigned' students selector (#4440) --- .../jsf/backingbean/EditStudentsBean.java | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/sections/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/EditStudentsBean.java b/sections/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/EditStudentsBean.java index e68905764aca..e476b4cefbce 100644 --- a/sections/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/EditStudentsBean.java +++ b/sections/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/EditStudentsBean.java @@ -40,7 +40,8 @@ import org.sakaiproject.section.api.facade.Role; import org.sakaiproject.tool.section.decorator.SectionDecorator; import org.sakaiproject.tool.section.jsf.JsfUtil; -import org.sakaiproject.component.cover.ServerConfigurationService; +import org.sakaiproject.tool.section.jsf.backingbean.EditManagersBean; +import org.sakaiproject.component.cover.ServerConfigurationService; /** * Controls the edit students page (where students are assigned to sections). * @@ -76,7 +77,32 @@ public void init() { List available; if(StringUtils.trimToNull(availableSectionUuid) == null) { available = getSectionManager().getUnsectionedEnrollments(currentSection.getCourse().getUuid(), currentSection.getCategory()); - } else { + } + else if (this.isFromCategoryReadOnly(availableSectionUuid)) { + List available1=getSectionManager().getUnsectionedEnrollments(currentSection.getCourse().getUuid(), currentSection.getCategory()); + List available2= getSectionManager().getSectionEnrollments(availableSectionUuid); + available=new ArrayList(); + + Collections.sort(available1, EditManagersBean.sortNameComparator); + Collections.sort(available2, EditManagersBean.sortNameComparator); + + int k1 = 0; int k2 = 0; + while (k1 all= getAllSiteSections(); + List sectionsReadOnly= new ArrayList(); + for (CourseSection section : all){ + String sectionUid=section.getUuid(); + if(this.isFromCategoryReadOnly(sectionUid)) + { + sectionsReadOnly.add(section); + } + } Collections.sort(sectionsInCategory); + Collections.sort(sectionsReadOnly); availableSectionItems = new ArrayList(); availableSectionItems.add(new SelectItem("", JsfUtil.getLocalizedMessage("edit_student_unassigned"))); + for (CourseSection section : ((List) sectionsReadOnly)){ + + availableSectionItems.add(new SelectItem(section.getUuid(), section.getTitle()+" ("+JsfUtil.getLocalizedMessage("edit_student_unassigned")+")")); + } for(Iterator iter = sectionsInCategory.iterator(); iter.hasNext();) { CourseSection section = (CourseSection)iter.next(); // Don't include the current section @@ -142,7 +182,9 @@ private String update_with_override(){ if(StringUtils.trimToNull(availableSectionUuid) != null) { availableUserUuids = getHighlightedUsers("memberForm:availableUsers"); try { - getSectionManager().setSectionMemberships(availableUserUuids, Role.STUDENT, availableSectionUuid); + if(!(this.isFromCategoryReadOnly(availableSectionUuid))) { + getSectionManager().setSectionMemberships(availableUserUuids, Role.STUDENT, availableSectionUuid); + } } catch (RoleConfigurationException rce) { JsfUtil.addErrorMessage(JsfUtil.getLocalizedMessage("role_config_error")); return null; @@ -274,4 +316,12 @@ public List getAvailableSectionItems() { public Integer getSectionMax() { return sectionMax; } + //SAK-32515 + //We only need sections that belong to "readonly" categories from property + //called "section.info.readonly.section.categories" in sakai.properties. + public boolean isFromCategoryReadOnly(String secUuid) { + CourseSection section=getSectionManager().getSection(secUuid); + SectionDecorator sc=new SectionDecorator(section, true); + return sc.isReadOnly() && !section.isLocked(); + } }