Search in sources :

Example 41 with CourseEditorEnv

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

the class IsAssessmentModeFunction 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();
    }
    WindowControl wControl = getUserCourseEnv().getWindowControl();
    if (wControl == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    ChiefController chiefController = wControl.getWindowBackOffice().getChiefController();
    if (chiefController == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    OLATResourceable lockedResource = chiefController.getLockResource();
    if (lockedResource == null) {
        return ConditionInterpreter.INT_FALSE;
    }
    Long resourceableId = getUserCourseEnv().getCourseEnvironment().getCourseResourceableId();
    if (lockedResource.getResourceableId().equals(resourceableId)) {
        RepositoryEntry entry = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        AssessmentModeManager assessmentModeMgr = CoreSpringFactory.getImpl(AssessmentModeManager.class);
        boolean inAssessment = assessmentModeMgr.isInAssessmentMode(entry, new Date());
        return inAssessment ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    } else {
        return ConditionInterpreter.INT_FALSE;
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ChiefController(org.olat.core.gui.control.ChiefController) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) AssessmentModeManager(org.olat.course.assessment.AssessmentModeManager) Date(java.util.Date)

Example 42 with CourseEditorEnv

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

the class IsGlobalAuthorFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
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 isGlobalAuthor = getUserCourseEnv().getIdentityEnvironment().getRoles().isAuthor();
    return isGlobalAuthor ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv)

Example 43 with CourseEditorEnv

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

the class EvalAttributeFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
@Override
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 2) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
    } else if (inStack.length < 2) {
        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"));
    if (!(inStack[1] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.name.infunction"));
    String attributeId = (String) inStack[0];
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // remember the reference to the attribute for this condtion
        cev.addSoftReference("attribute", attributeId, false);
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    /*
		 * the real function evaluation which is used during run time
		 */
    String attName = (String) inStack[0];
    String attValue = (String) inStack[1];
    IdentityEnvironment ienv = getUserCourseEnv().getIdentityEnvironment();
    Identity ident = ienv.getIdentity();
    Map<String, String> attributes = ienv.getAttributes();
    if (attributes == null)
        return ConditionInterpreter.INT_FALSE;
    String value = attributes.get(attName);
    boolean match = false;
    boolean debug = log.isDebug();
    if (debug) {
        log.debug("value    : " + value);
        log.debug("attrValue: " + attValue);
        log.debug("fT       :  " + functionType);
    }
    if (value != null) {
        if (functionType <= FUNCTION_TYPE_IS_NOT_IN_ATTRIBUTE) {
            match = findExpressionInMultiValue(attValue, value, functionType);
        } else if (functionType == FUNCTION_TYPE_HAS_NOT_ATTRIBUTE) {
            match = !findExpressionInMultiValue(attValue, value, FUNCTION_TYPE_HAS_ATTRIBUTE);
        }
    }
    if (debug) {
        log.debug("identity '" + ident.getName() + "' tested on attribute '" + attName + "' to have value '" + attValue + "' user's value was '" + value + "', match=" + match);
    }
    return match ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 44 with CourseEditorEnv

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

the class GetInitialEnrollmentDateFunction 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 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"));
        }
        if (!cev.isEnrollmentNode(nodeId)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, nodeId, "error.notenrollment.coursenodeid", "solution.chooseenrollment"));
        }
        // 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);
    // invalid node id's return still a valid double
    // TODO fg: check with editor tree model DONE: the above checks ensure only
    // valid node references
    // if (node == null) return new Double(Double.NEGATIVE_INFINITY);
    CoursePropertyManager pm = getUserCourseEnv().getCourseEnvironment().getCoursePropertyManager();
    Identity identity = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    Property firstTime = pm.findCourseNodeProperty(node, identity, null, ENCourseNode.PROPERTY_INITIAL_ENROLLMENT_DATE);
    if (firstTime != null) {
        String firstTimeMillis = firstTime.getStringValue();
        return Double.valueOf(firstTimeMillis);
    } 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) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 45 with CourseEditorEnv

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

the class GetRecentCourseLaunchDateFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        return defaultValue();
    }
    UserCourseInformationsManager mgr = CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
    UserCourseInformations infos = mgr.getUserCourseInformations(getUserCourseEnv().getCourseEnvironment().getCourseGroupManager().getCourseResource(), getUserCourseEnv().getIdentityEnvironment().getIdentity());
    if (infos != null) {
        return Double.valueOf(infos.getRecentLaunch().getTime());
    } 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) UserCourseInformationsManager(org.olat.course.assessment.manager.UserCourseInformationsManager) UserCourseInformations(org.olat.course.assessment.UserCourseInformations)

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