Skip to content

Commit

Permalink
SAK-32515 Section Info: Improve sorting functionality by including 'r…
Browse files Browse the repository at this point in the history
…eadOnly' sections in the 'unassigned' students selector (sakaiproject#4440)
  • Loading branch information
manuelal authored and ern committed Jul 11, 2017
1 parent 9e138cd commit a2f368f
Showing 1 changed file with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down Expand Up @@ -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<available1.size() && k2 < available2.size()) {
ParticipationRecord p1=(ParticipationRecord)available1.get(k1);
ParticipationRecord p2=(ParticipationRecord)available2.get(k2);
String a1=p1.getUser().getSortName();
String a2=p2.getUser().getSortName();
if (a1.compareTo(a2)==0) {
available.add(p2);
k1++; k2++;
} else if (a1.compareTo(a2) < 0) {
k1++;
} else {
k2++;
}
}
}
else {
available = getSectionManager().getSectionEnrollments(availableSectionUuid);
}
Collections.sort(available, EditManagersBean.sortNameComparator);
Expand All @@ -89,9 +115,23 @@ public void init() {

// Build the list of available sections
List sectionsInCategory = getSectionManager().getSectionsInCategory(getSiteContext(), currentSection.getCategory());
List<CourseSection> all= getAllSiteSections();
List sectionsReadOnly= new ArrayList<CourseSection>();
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<CourseSection>) 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit a2f368f

Please sign in to comment.