Skip to content
Snippets Groups Projects
Commit d46403d9 authored by srosse's avatar srosse
Browse files

FXOLAT-123: limit the notifications of SCORM results to test with "passed" or "completed"

parent 57504fa3
No related branches found
No related tags found
No related merge requests found
...@@ -64,9 +64,11 @@ import org.olat.course.nodes.AssessableCourseNode; ...@@ -64,9 +64,11 @@ import org.olat.course.nodes.AssessableCourseNode;
import org.olat.course.nodes.CourseNode; import org.olat.course.nodes.CourseNode;
import org.olat.course.nodes.CourseNodeFactory; import org.olat.course.nodes.CourseNodeFactory;
import org.olat.course.nodes.STCourseNode; import org.olat.course.nodes.STCourseNode;
import org.olat.course.nodes.ScormCourseNode;
import org.olat.course.properties.CoursePropertyManager; import org.olat.course.properties.CoursePropertyManager;
import org.olat.course.run.environment.CourseEnvironment; import org.olat.course.run.environment.CourseEnvironment;
import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroup;
import org.olat.modules.scorm.assessment.ScormAssessmentManager;
import org.olat.notifications.NotificationsUpgradeHelper; import org.olat.notifications.NotificationsUpgradeHelper;
import org.olat.properties.Property; import org.olat.properties.Property;
import org.olat.repository.RepositoryManager; import org.olat.repository.RepositoryManager;
...@@ -357,6 +359,15 @@ public class AssessmentNotificationsHandler implements NotificationsHandler { ...@@ -357,6 +359,15 @@ public class AssessmentNotificationsHandler implements NotificationsHandler {
} }
} }
if(test instanceof ScormCourseNode) {
ScormCourseNode scormTest = (ScormCourseNode)test;
//check if completed or passed
String status = ScormAssessmentManager.getInstance().getLastLessonStatus(assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
if(!"passed".equals(status) && !"completed".equals(status)) {
continue;
}
}
String desc; String desc;
String type = translator.translate("notifications.entry." + test.getType()); String type = translator.translate("notifications.entry." + test.getType());
if(score == null) { if(score == null) {
......
...@@ -22,6 +22,7 @@ package org.olat.modules.scorm.assessment; ...@@ -22,6 +22,7 @@ package org.olat.modules.scorm.assessment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -148,6 +149,16 @@ public class ScormAssessmentManager extends BasicManager { ...@@ -148,6 +149,16 @@ public class ScormAssessmentManager extends BasicManager {
} }
// </OLATCE-289> // </OLATCE-289>
public String getLastLessonStatus(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
List<CmiData> scoDatas = visitScoDatas(username, courseEnv, node);
for(CmiData scoData:scoDatas) {
if("cmi.core.lesson_status".equals(scoData.getKey())) {
return scoData.getValue();
}
}
return null;
}
/** /**
* Return all the datas in the sco datamodels of a SCORM course * Return all the datas in the sco datamodels of a SCORM course
* @param username * @param username
...@@ -157,40 +168,20 @@ public class ScormAssessmentManager extends BasicManager { ...@@ -157,40 +168,20 @@ public class ScormAssessmentManager extends BasicManager {
*/ */
public List<CmiData> visitScoDatas(String username, CourseEnvironment courseEnv, ScormCourseNode node) { public List<CmiData> visitScoDatas(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
VFSContainer scoContainer = ScormDirectoryHelper.getScoDirectory(username, courseEnv, node); VFSContainer scoContainer = ScormDirectoryHelper.getScoDirectory(username, courseEnv, node);
if(scoContainer == null) if(scoContainer == null) {
return Collections.emptyList(); return Collections.emptyList();
}
List<CmiData> datas = collectData(scoContainer); List<VFSItem> contents = scoContainer.getItems(new XMLFilter());
Collections.sort(datas, new CmiDataComparator()); if(contents.isEmpty()) {
return datas; return Collections.emptyList();
}
private List<CmiData> collectData(VFSContainer scoFolder) {
List<CmiData> datas = new ArrayList<CmiData>();
List<VFSItem> contents = scoFolder.getItems(new XMLFilter());
for(VFSItem file:contents) {
ScoDocument document = new ScoDocument(null);
try {
if(file instanceof LocalFileImpl) {
document.loadDocument(((LocalFileImpl)file).getBasefile());
}
else {
logger.warn("Cannot use this type of VSFItem to load a SCO Datamodel: " + file.getClass().getName(), null);
continue;
}
String fileName = file.getName();
String itemId = fileName.substring(0, fileName.length() - 4);
String[][] scoModel = document.getScoModel();
for(String[] line:scoModel) {
datas.add(new CmiData(itemId, line[0], line[1]));
}
} catch (Exception e) {
logger.error("Cannot load a SCO Datamodel", e);
}
} }
if(contents.size() > 1) {
Collections.sort(contents, new FileDateComparator());
}
VFSItem file = contents.get(0);
List<CmiData> datas = collectData(file);
return datas; return datas;
} }
...@@ -204,4 +195,22 @@ public class ScormAssessmentManager extends BasicManager { ...@@ -204,4 +195,22 @@ public class ScormAssessmentManager extends BasicManager {
return false; return false;
} }
} }
public class FileDateComparator implements Comparator<VFSItem> {
@Override
public int compare(VFSItem f1, VFSItem f2) {
if(f1 == null) return -1;
if(f2 == null) return 1;
long l1 = f1.getLastModified();
long l2 = f2.getLastModified();
if(l1 < l2) {
return 1;
}
if (l1 == l2) {
return 0;
}
return -1;
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment