/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <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>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.course.condition.interpreter;
import org.olat.core.gui.translator.PackageTranslator;
import org.olat.course.condition.interpreter.score.GetPassedFunction;
import org.olat.course.condition.interpreter.score.GetPassedWithCourseIdFunction;
import org.olat.course.condition.interpreter.score.GetScoreFunction;
import org.olat.course.condition.interpreter.score.GetScoreWithCourseIdFunction;
import org.olat.course.editor.CourseEditorEnv;
import org.olat.course.run.userview.UserCourseEnvironment;
import com.neemsoft.jmep.Environment;
/**
* Special condition-interpreter for assessment tool group- / course-structure-selection.
* This condition-interpreter evalute only group conditions and insert dummy function for all
* other conditions.
*
* @author Christian Guretzki
*/
public class OnlyGroupConditionInterpreter extends ConditionInterpreter{
/**
* ConditionInterpreter interpretes course conditions.
*
* @param userCourseEnv
*/
public OnlyGroupConditionInterpreter(UserCourseEnvironment userCourseEnv) {
super();
uce = userCourseEnv;
//
CourseEditorEnv cev = uce.getCourseEditorEnv();
if (cev != null) {
translator = new PackageTranslator(PACKAGE, cev.getEditorEnvLocale());
}
env = new Environment();
// constants: add for user convenience
env.addConstant("true", 1);
env.addConstant("false", 0);
// variables
env.addVariable(NowVariable.name, new DummyVariable(userCourseEnv));
// functions
env.addFunction(DateFunction.name, new DummyDateFunction(userCourseEnv));
env.addFunction("inGroup", new InLearningGroupFunction(userCourseEnv, "inGroup")); // legacy
env.addFunction("inLearningGroup", new InLearningGroupFunction(userCourseEnv, "inLearningGroup"));
env.addFunction(InRightGroupFunction.name, new InRightGroupFunction(userCourseEnv));
env.addFunction(InLearningAreaFunction.name, new InLearningAreaFunction(userCourseEnv));
env.addFunction(IsUserFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(IsGuestFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(IsGlobalAuthorFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction("hasAttribute", new DummyBooleanFunction(userCourseEnv));
env.addFunction("isInAttribute", new DummyBooleanFunction(userCourseEnv));
env.addFunction(GetUserPropertyFunction.name, new DummyStringFunction(userCourseEnv));
env.addFunction(HasLanguageFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(InInstitutionFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(IsCourseCoachFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(IsCourseAdministratorFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(GetAttemptsFunction.name, new DummyIntegerFunction(userCourseEnv));
// enrollment building block specific functions
env.addFunction(GetInitialEnrollmentDateFunction.name, new DummyDateFunction(userCourseEnv));
env.addFunction(GetRecentEnrollmentDateFunction.name, new DummyDateFunction(userCourseEnv));
// functions to calculate score
env.addFunction(GetPassedFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(GetScoreFunction.name, new DummyDoubleFunction(userCourseEnv));
env.addFunction(GetPassedWithCourseIdFunction.name, new DummyBooleanFunction(userCourseEnv));
env.addFunction(GetScoreWithCourseIdFunction.name, new DummyDoubleFunction(userCourseEnv));
// units
env.addUnit("min", new MinuteUnit());
env.addUnit("h", new HourUnit());
env.addUnit("d", new DayUnit());
env.addUnit("w", new WeekUnit());
env.addUnit("m", new MonthUnit());
}
}
//////////////////////////////////
// Dummy function implementations
//////////////////////////////////
class DummyBooleanFunction extends AbstractFunction {
public DummyBooleanFunction(UserCourseEnvironment userCourseEnv) {
super(userCourseEnv);
}
public Object call(Object[] inStack) {
// return allways true, because it is a dummy implementation without condition
return ConditionInterpreter.INT_TRUE;
}
protected Object defaultValue() {
return ConditionInterpreter.INT_TRUE;
}
}
class DummyDateFunction extends AbstractFunction {
public DummyDateFunction(UserCourseEnvironment userCourseEnv ) {
super(userCourseEnv);
}
public Object call(Object[] inStack) {
// return allways true, because it is a dummy implementation without condition
return new Double(0);
}
protected Object defaultValue() {
return new Double(0);
}
}
class DummyDoubleFunction extends AbstractFunction {
public DummyDoubleFunction(UserCourseEnvironment userCourseEnv ) {
super(userCourseEnv);
}
public Object call(Object[] inStack) {
return Double.MIN_VALUE;
}
protected Object defaultValue() {
return Double.MIN_VALUE;
}
}
class DummyIntegerFunction extends AbstractFunction {
public DummyIntegerFunction(UserCourseEnvironment userCourseEnv ) {
super(userCourseEnv);
}
public Object call(Object[] inStack) {
return Integer.MIN_VALUE;
}
protected Object defaultValue() {
return Integer.MIN_VALUE;
}
}
class DummyStringFunction extends AbstractFunction {
public DummyStringFunction(UserCourseEnvironment userCourseEnv ) {
super(userCourseEnv);
}
public Object call(Object[] inStack) {
return "";
}
protected Object defaultValue() {
return "";
}
}
class DummyVariable extends AbstractVariable {
public static final String name = "now";
/**
* Default constructor to use the current date
* @param userCourseEnv
*/
public DummyVariable(UserCourseEnvironment userCourseEnv) {
super(userCourseEnv);
}
/**
* @see com.neemsoft.jmep.VariableCB#getValue()
*/
public Object getValue() {
return new Double(0);
}
}