From ec2083463b43528f7f602e293b6e936897f5cce7 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Sun, 15 Mar 2020 11:00:36 +0100
Subject: [PATCH] no-jira: use the "no" score accounting in course preview

---
 .../run/preview/PreviewRunController.java     | 21 +++++++------------
 .../userview/UserCourseEnvironmentImpl.java   | 14 ++++++++++++-
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/olat/course/run/preview/PreviewRunController.java b/src/main/java/org/olat/course/run/preview/PreviewRunController.java
index 18bcbaf855e..acb7e932b14 100644
--- a/src/main/java/org/olat/course/run/preview/PreviewRunController.java
+++ b/src/main/java/org/olat/course/run/preview/PreviewRunController.java
@@ -53,6 +53,8 @@ import org.olat.course.run.RunMainController;
 import org.olat.course.run.environment.CourseEnvironment;
 import org.olat.course.run.navigation.NavigationHandler;
 import org.olat.course.run.navigation.NodeClickedRef;
+import org.olat.course.run.scoring.NoEvaluationAccounting;
+import org.olat.course.run.scoring.ScoreAccounting;
 import org.olat.course.run.userview.UserCourseEnvironment;
 import org.olat.course.run.userview.UserCourseEnvironmentImpl;
 import org.olat.group.BusinessGroup;
@@ -92,8 +94,9 @@ public class PreviewRunController extends MainLayoutBasicController {
 		luTree = new MenuTree(null, "luTreeRun", this);
 		luTree.setScrollTopOnClick(true);
 
-		// build up the running structure for this user;
-		uce = new UserCourseEnvironmentImpl(identEnv, cenv);
+		// build up the running structure for this user
+		ScoreAccounting noScoreAccounting = new NoEvaluationAccounting();
+		uce = new UserCourseEnvironmentImpl(identEnv, cenv, noScoreAccounting);
 		navHandler = new NavigationHandler(uce, null, true);
 		
 		// evaluate scoring
@@ -149,11 +152,7 @@ public class PreviewRunController extends MainLayoutBasicController {
 		}
 		return sb.toString();
 	}
-	
-	/**
-	 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
-	 *      org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
-	 */
+
 	@Override
 	public void event(UserRequest ureq, Component source, Event event) {
 		if (source == luTree) {
@@ -206,10 +205,7 @@ public class PreviewRunController extends MainLayoutBasicController {
 		}
 	}
 
-	/**
-	 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
-	 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
-	 */
+
 	@Override
 	public void event(UserRequest ureq, Controller source, Event event) {
 		if (source == currentNodeController) {
@@ -266,9 +262,6 @@ public class PreviewRunController extends MainLayoutBasicController {
 		return true;
 	}
 
-	/**
-	 * @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
-	 */
 	@Override
 	protected void doDispose() {
 		if (currentNodeController != null) {
diff --git a/src/main/java/org/olat/course/run/userview/UserCourseEnvironmentImpl.java b/src/main/java/org/olat/course/run/userview/UserCourseEnvironmentImpl.java
index fa952b9edba..bf905bc81e7 100644
--- a/src/main/java/org/olat/course/run/userview/UserCourseEnvironmentImpl.java
+++ b/src/main/java/org/olat/course/run/userview/UserCourseEnvironmentImpl.java
@@ -84,6 +84,18 @@ public class UserCourseEnvironmentImpl implements UserCourseEnvironment {
 			courseReadOnly = courseEnvironment.getCourseGroupManager().getCourseEntry().getEntryStatus() == RepositoryEntryStatusEnum.closed;
 		}
 	}
+
+	/**
+	 * Constructor used for previewing the course.
+	 * 
+	 * @param identityEnvironment The identity environment
+	 * @param courseEnvironment The course environment
+	 * @param scoreAccounting Fix the score accounting implementation
+	 */
+	public UserCourseEnvironmentImpl(IdentityEnvironment identityEnvironment, CourseEnvironment courseEnvironment, ScoreAccounting scoreAccounting) {
+		this(identityEnvironment, courseEnvironment, null, null, null, null, null, null, null, null);
+		this.scoreAccounting = scoreAccounting;
+	}
 	
 	public UserCourseEnvironmentImpl(IdentityEnvironment identityEnvironment, CourseEnvironment courseEnvironment, Boolean courseReadOnly) {
 		this(identityEnvironment, courseEnvironment, null, null, null, null, null, null, null, courseReadOnly);
@@ -161,7 +173,7 @@ public class UserCourseEnvironmentImpl implements UserCourseEnvironment {
 	}
 	
 	private void initScoreAccounting() {
-		scoreAccounting = isParticipant()? new AssessmentAccounting(this): new NoEvaluationAccounting();
+		scoreAccounting = isParticipant() ? new AssessmentAccounting(this): new NoEvaluationAccounting();
 	}
 
 	@Override
-- 
GitLab