diff --git a/src/main/java/org/olat/modules/lecture/ui/TeacherLecturesTableController.java b/src/main/java/org/olat/modules/lecture/ui/TeacherLecturesTableController.java index 32c6c951a43a8549a2e9b803d819e8e2bd6fec19..4866d3cdaf74805a4acc14fa0020019031d403df 100644 --- a/src/main/java/org/olat/modules/lecture/ui/TeacherLecturesTableController.java +++ b/src/main/java/org/olat/modules/lecture/ui/TeacherLecturesTableController.java @@ -20,6 +20,7 @@ package org.olat.modules.lecture.ui; import java.io.IOException; +import java.util.Collections; import java.util.List; import javax.xml.transform.TransformerException; @@ -69,6 +70,7 @@ import org.olat.modules.lecture.RollCallSecurityCallback; import org.olat.modules.lecture.model.LectureBlockRow; import org.olat.modules.lecture.model.RollCallSecurityCallbackImpl; import org.olat.modules.lecture.ui.TeacherOverviewDataModel.TeachCols; +import org.olat.modules.lecture.ui.component.IdentityComparator; import org.olat.modules.lecture.ui.component.LectureBlockStatusCellRenderer; import org.olat.modules.lecture.ui.component.YesNoCellRenderer; import org.olat.modules.lecture.ui.event.ReopenLectureBlockEvent; @@ -297,6 +299,9 @@ public class TeacherLecturesTableController extends FormBasicController implemen private void doExportAttendanceList(UserRequest ureq, LectureBlock row) { LectureBlock lectureBlock = lectureService.getLectureBlock(row); List<Identity> participants = lectureService.getParticipants(lectureBlock); + if(participants.size() > 1) { + Collections.sort(participants, new IdentityComparator(getLocale())); + } List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(row); try { LecturesBlockPDFExport export = new LecturesBlockPDFExport(lectureBlock, authorizedAbsenceEnabled, getTranslator()); @@ -311,6 +316,9 @@ public class TeacherLecturesTableController extends FormBasicController implemen private void doExportAttendanceListForSignature(UserRequest ureq, LectureBlock row) { LectureBlock lectureBlock = lectureService.getLectureBlock(row); List<Identity> participants = lectureService.getParticipants(lectureBlock); + if(participants.size() > 1) { + Collections.sort(participants, new IdentityComparator(getLocale())); + } try { LecturesBlockSignaturePDFExport export = new LecturesBlockSignaturePDFExport(lectureBlock, getTranslator()); export.setTeacher(userManager.getUserDisplayName(getIdentity())); diff --git a/src/main/java/org/olat/modules/lecture/ui/component/IdentityComparator.java b/src/main/java/org/olat/modules/lecture/ui/component/IdentityComparator.java new file mode 100644 index 0000000000000000000000000000000000000000..fc5740c466cde5f9b184bb246e4bcf1970ffcf1b --- /dev/null +++ b/src/main/java/org/olat/modules/lecture/ui/component/IdentityComparator.java @@ -0,0 +1,83 @@ +/** + * <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.modules.lecture.ui.component; + +import java.text.Collator; +import java.util.Comparator; +import java.util.Locale; + +import org.olat.core.id.Identity; +import org.olat.core.id.UserConstants; + +/** + * + * Initial date: 3 déc. 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class IdentityComparator implements Comparator<Identity> { + + private final Collator collator; + + public IdentityComparator(Locale locale) { + collator = Collator.getInstance(locale); + } + + @Override + public int compare(Identity id1, Identity id2) { + int c = 0; + if(id1 == null || id2 == null) { + c = compareNullObjects(id1, id2); + } else { + String l1 = id1.getUser().getLastName(); + String l2 = id2.getUser().getLastName(); + if(l1 == null || l2 == null) { + c = compareNullObjects(l1, l2); + } else { + c = collator.compare(l1, l2); + } + + if(c == 0) { + String f1 = id1.getUser().getProperty(UserConstants.FIRSTNAME, null); + String f2 = id2.getUser().getProperty(UserConstants.FIRSTNAME, null); + if(f1 == null || f2 == null) { + c = compareNullObjects(f1, f2); + } else { + c = collator.compare(f1, f2); + } + } + + if(c == 0) { + Long k1 = id1.getKey(); + Long k2 = id2.getKey(); + c = k1.compareTo(k2); + } + } + + return c; + } + + private final int compareNullObjects(final Object a, final Object b) { + boolean ba = (a == null); + boolean bb = (b == null); + return ba? (bb? 0: -1):(bb? 1: 0); + } + +}