Search in sources :

Example 11 with CourseEditorEnv

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

the class InLearningAreaFunction 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.areaname"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.areaname"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.areanameexpected", "solution.example.name.infunction"));
    String areaName = (String) inStack[0];
    areaName = areaName != null ? areaName.trim() : areaName;
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        if (!cev.existsArea(areaName)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, areaName, "error.notfound.name", "solution.checkgroupmanagement"));
        }
        // remember the reference to the node id for this condtion
        cev.addSoftReference("areaId", areaName, false);
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    // The real function evaluation which is used during run time
    Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
    if (StringHelper.isLong(areaName)) {
        Long areaKey = new Long(areaName);
        return cgm.isIdentityInLearningArea(ident, areaKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    }
    List<Long> areaKeys = CoreSpringFactory.getImpl(BGAreaManager.class).toAreaKeys(areaName, cgm.getCourseResource());
    if (!areaKeys.isEmpty()) {
        return cgm.isIdentityInLearningArea(ident, areaKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    }
    return ConditionInterpreter.INT_FALSE;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity) BGAreaManager(org.olat.group.area.BGAreaManager)

Example 12 with CourseEditorEnv

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

the class IsCourseAdministratorFunction 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 isCourseAdmin;
    if (inStack != null && inStack.length > 0 && inStack[0] instanceof String && AnyCourseVariable.name.equalsIgnoreCase((String) inStack[0])) {
        // administrator of any course
        isCourseAdmin = getUserCourseEnv().isAdminOfAnyCourse();
    } else {
        isCourseAdmin = getUserCourseEnv().isAdmin();
    }
    if (log.isDebug()) {
        Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
        log.debug("identity " + ident.getName() + ", courseadministrator:" + isCourseAdmin + ", in course " + getUserCourseEnv().getCourseEnvironment().getCourseResourceableId());
    }
    return isCourseAdmin ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Example 13 with CourseEditorEnv

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

the class IsCourseParticipantFunction 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 isParticipant;
    if (inStack != null && inStack.length > 0 && inStack[0] instanceof String && AnyCourseVariable.name.equalsIgnoreCase((String) inStack[0])) {
        // administrator of any course
        isParticipant = getUserCourseEnv().isParticipantOfAnyCourse();
    } else {
        isParticipant = getUserCourseEnv().isParticipant();
    }
    if (log.isDebug()) {
        Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
        log.debug("identity " + ident.getName() + ", coursecoach:" + isParticipant + ", in course " + getUserCourseEnv().getCourseEnvironment().getCourseResourceableId());
    }
    return isParticipant ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Example 14 with CourseEditorEnv

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

the class IsLearningGroupFullFunction 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.groupname"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.groupname"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String))
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.groupnameexpected", "solution.example.name.infunction"));
    String groupName = (String) inStack[0];
    groupName = groupName != null ? groupName.trim() : null;
    /*
		 * check reference integrity
		 */
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        if (!cev.existsGroup(groupName)) {
            return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, groupName, "error.notfound.name", "solution.checkgroupmanagement"));
        }
        // remember the reference to the node id for this condition
        cev.addSoftReference("groupId", groupName, false);
        // return a valid value to continue with condition evaluation test
        return defaultValue();
    }
    /*
		 * the real function evaluation which is used during run time
		 */
    CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
    if (StringHelper.isLong(groupName)) {
        Long groupKey = new Long(groupName);
        return cgm.isBusinessGroupFull(groupKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    }
    List<Long> groupKeys = CoreSpringFactory.getImpl(BusinessGroupService.class).toGroupKeys(groupName, cgm.getCourseEntry());
    if (!groupKeys.isEmpty()) {
        return cgm.isBusinessGroupFull(groupKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
    }
    return ConditionInterpreter.INT_FALSE;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroupService(org.olat.group.BusinessGroupService) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv)

Example 15 with CourseEditorEnv

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

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)

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