Search in sources :

Example 31 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.

the class GetPassedWithCourseIdFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 2) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.nodereference"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
    }
    /*
		 * argument type check
		 */
    Long courseRepoEntryKey;
    try {
        Object arg = inStack[0];
        if (arg instanceof Number) {
            courseRepoEntryKey = new Long(((Number) arg).longValue());
        } else if (arg instanceof String) {
            courseRepoEntryKey = Long.decode((String) arg);
        } else {
            courseRepoEntryKey = null;
        }
    } catch (NumberFormatException nfe) {
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
    }
    /*
		 * no integrity check can be done - other course might not exist anymore
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        return defaultValue();
    }
    /*
		 * the real function evaluation which is used during run time
		 */
    EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
    RepositoryEntryRef courseRef = new RepositoryEntryRefImpl(courseRepoEntryKey);
    UserEfficiencyStatement es = esm.getUserEfficiencyStatementLightByRepositoryEntry(courseRef, getUserCourseEnv().getIdentityEnvironment().getIdentity());
    if (es == null)
        return defaultValue();
    Boolean passed = es.getPassed();
    if (passed == null) {
        return defaultValue();
    }
    // finally check existing value
    return passed.booleanValue() ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 32 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.

the class GetScoreFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.nodereference"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
    String childId = (String) inStack[0];
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        if (!cev.existsNode(childId)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, childId, "error.notfound.coursenodeid", "solution.copypastenodeid"));
        }
        if (!cev.isAssessable(childId)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, childId, "error.notassessable.coursenodid", "solution.takeassessablenode"));
        }
        // dependencies to parents as they create cycles.
        if (!childId.equals(cev.getCurrentCourseNodeId()) || cev.getNode(cev.getCurrentCourseNodeId()) instanceof STCourseNode) {
            cev.addSoftReference("courseNodeId", childId, true);
        }
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    /*
		 * the real function evaluation which is used during run time
		 */
    ScoreAccounting sa = getUserCourseEnv().getScoreAccounting();
    Float score = sa.evalScoreOfCourseNode(childId);
    return new Double(score);
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) STCourseNode(org.olat.course.nodes.STCourseNode) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting)

Example 33 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.

the class Sleep method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    } else if (Settings.isDebuging()) {
        long sleep = 30000;
        if (inStack == null || inStack.length == 0) {
        // stay with default
        } else if (inStack[0] instanceof String) {
            String sleepStr = (String) inStack[0];
            sleep = Long.parseLong(sleepStr);
        }
        try {
            Thread.sleep(sleep);
        } catch (InterruptedException e) {
            log.error("", e);
        }
    }
    return ConditionInterpreter.INT_TRUE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv)

Example 34 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.

the class TodayVariable method getValue.

/**
 * @see com.neemsoft.jmep.VariableCB#getValue()
 */
public Object getValue() {
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        return new Double(0);
    }
    CourseEnvironment ce = getUserCourseEnv().getCourseEnvironment();
    long time = ce.getCurrentTimeMillis();
    Date date = new Date(time);
    Date day = DateUtils.truncate(date, Calendar.DATE);
    Double dDay = new Double(day.getTime());
    return dDay;
}
Also used : CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Date(java.util.Date)

Example 35 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.

the class GetPassedFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.nodereference"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
    String childId = (String) inStack[0];
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        if (!cev.existsNode(childId)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, childId, "error.notfound.coursenodeid", "solution.copypastenodeid"));
        }
        if (!cev.isAssessable(childId)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, childId, "error.notassessable.coursenodid", "solution.takeassessablenode"));
        }
        // dependencies to parents as they create cycles.
        if (!childId.equals(cev.getCurrentCourseNodeId()) || cev.getNode(cev.getCurrentCourseNodeId()) instanceof STCourseNode) {
            cev.addSoftReference("courseNodeId", childId, true);
        }
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    /*
		 * the real function evaluation which is used during run time
		 */
    ScoreAccounting sa = getUserCourseEnv().getScoreAccounting();
    Boolean passed = sa.evalPassedOfCourseNode(childId);
    return (passed.booleanValue() ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE);
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) STCourseNode(org.olat.course.nodes.STCourseNode) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting)

Aggregations

CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)68 Identity (org.olat.core.id.Identity)32 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)10 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)8 CourseNode (org.olat.course.nodes.CourseNode)8 Date (java.util.Date)6 BusinessGroupService (org.olat.group.BusinessGroupService)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 User (org.olat.core.id.User)4 AssessmentManager (org.olat.course.assessment.AssessmentManager)4 UserCourseInformations (org.olat.course.assessment.UserCourseInformations)4 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)4 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 UserCourseInformationsManager (org.olat.course.assessment.manager.UserCourseInformationsManager)4 ConditionErrorMessage (org.olat.course.condition.interpreter.ConditionErrorMessage)4 ConditionExpression (org.olat.course.condition.interpreter.ConditionExpression)4 ENCourseNode (org.olat.course.nodes.ENCourseNode)4 STCourseNode (org.olat.course.nodes.STCourseNode)4 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)4 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)4