Search in sources :

Example 6 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class ConditionConfigExpertForm method validateFormLogic.

@Override
public boolean validateFormLogic(UserRequest ureq) {
    if (tprecond.isEmpty()) {
        // the precondition
        return true;
    }
    /*
		 *  not empty, nowOLAT - Demo Course_1264602504362 test precondition syntax and for existing soft references
		 */
    CourseEditorEnv cev = euce.getCourseEditorEnv();
    ConditionExpression ce = new ConditionExpression(conditionId, tprecond.getValue());
    ConditionErrorMessage[] cerrmsg = cev.validateConditionExpression(ce);
    /*
		 * display any error detected in the condition expression testing.
		 */
    if (cerrmsg != null && cerrmsg.length > 0) {
        // the error messOLAT - Demo Course_1264602504362age
        tprecond.setErrorKey(cerrmsg[0].errorKey, cerrmsg[0].errorKeyParams);
        if (cerrmsg[0].solutionMsgKey != null && !"".equals(cerrmsg[0].solutionMsgKey)) {
            // and a hint or example to clarify the error message
            tprecond.setExampleKey(cerrmsg[0].solutionMsgKey, cerrmsg[0].errorKeyParams);
        }
        return false;
    }
    // reset HINTS
    tprecond.setExampleKey("xx", new String[] { "" });
    return true;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression) ConditionErrorMessage(org.olat.course.condition.interpreter.ConditionErrorMessage)

Example 7 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class IsCourseCoachFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
public Object call(Object[] inStack) {
    /*
		 * expression check only if cev != null
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    boolean isCourseCoach;
    if (inStack != null && inStack.length > 0 && inStack[0] instanceof String && AnyCourseVariable.name.equalsIgnoreCase((String) inStack[0])) {
        // administrator of any course
        isCourseCoach = getUserCourseEnv().isCoachOfAnyCourse();
    } else {
        isCourseCoach = getUserCourseEnv().isCoach();
    }
    if (log.isDebug()) {
        Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
        log.debug("identity " + ident.getName() + ", coursecoach:" + isCourseCoach + ", in course " + getUserCourseEnv().getCourseEnvironment().getCourseResourceableId());
    }
    return isCourseCoach ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Example 8 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class GetAttemptsFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
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 nodeId = (String) inStack[0];
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        if (!cev.existsNode(nodeId)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, nodeId, "error.notfound.coursenodeid", "solution.copypastenodeid"));
        }
        // Allow self-referencing but do not allow dependencies to parents as they create cycles.
        if (!nodeId.equals(cev.getCurrentCourseNodeId())) {
            cev.addSoftReference("courseNodeId", nodeId, false);
        }
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    /*
		 * the real function evaluation which is used during run time
		 */
    CourseNode node = getUserCourseEnv().getCourseEnvironment().getRunStructure().getNode(nodeId);
    AssessmentManager am = getUserCourseEnv().getCourseEnvironment().getAssessmentManager();
    Identity identity = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    return am.getNodeAttempts(node, identity);
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) AssessmentManager(org.olat.course.assessment.AssessmentManager) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 9 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class GetCourseEndDateFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
public Object call(Object[] inStack) {
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        return defaultValue();
    }
    RepositoryEntryLifecycle lifecycle = getUserCourseEnv().getLifecycle();
    if (lifecycle != null && lifecycle.getValidTo() != null) {
        Double end = Double.valueOf(lifecycle.getValidTo().getTime());
        return end;
    } else {
        // what to do in case of no date available??? -> return date in the future
        return new Double(Double.POSITIVE_INFINITY);
    }
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle)

Example 10 with CourseEditorEnv

use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.

the class GetUserPropertyFunction method call.

/**
 * @see org.olat.course.condition.interpreter.AbstractFunction#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.providetwo.attrvalue"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String)) {
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
    }
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return emtyp string to continue with condition evaluation test
        return defaultValue();
    }
    Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    if (ident == null) {
        return defaultValue();
    }
    User user = ident.getUser();
    String propertyName = (String) inStack[0];
    // always use default locale
    String propertyValue = user.getProperty(propertyName, null);
    // case that we just ignore it.
    return (propertyValue == null ? defaultValue() : propertyValue);
}
Also used : User(org.olat.core.id.User) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

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