Search in sources :

Example 26 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class BCCourseNode method getSecurisedNodeFolderContainer.

public static OlatNamedContainerImpl getSecurisedNodeFolderContainer(BCCourseNode node, CourseEnvironment courseEnv, IdentityEnvironment ienv) {
    boolean isOlatAdmin = ienv.getRoles().isOLATAdmin();
    boolean isGuestOnly = ienv.getRoles().isGuestOnly();
    UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ienv, courseEnv);
    NodeEvaluation ne = node.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
    OlatNamedContainerImpl container = getNodeFolderContainer(node, courseEnv);
    VFSSecurityCallback secCallback = new FolderNodeCallback(container.getRelPath(), ne, isOlatAdmin, isGuestOnly, null);
    container.setLocalSecurityCallback(secCallback);
    return container;
}
Also used : OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) FolderNodeCallback(org.olat.course.nodes.bc.FolderNodeCallback) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 27 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class CheckListCourseNode method updateScorePassedOnPublish.

private void updateScorePassedOnPublish(Identity assessedIdentity, Identity coachIdentity, CheckboxManager checkboxManager, ICourse course) {
    AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
    Float currentScore = am.getNodeScore(this, assessedIdentity);
    Boolean currentPassed = am.getNodePassed(this, assessedIdentity);
    Float updatedScore = null;
    Boolean updatedPassed = null;
    ModuleConfiguration config = getModuleConfiguration();
    Boolean scoreGrantedBool = (Boolean) config.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD);
    if (scoreGrantedBool != null && scoreGrantedBool.booleanValue()) {
        updatedScore = checkboxManager.calculateScore(assessedIdentity, course, getIdent());
    } else {
        updatedScore = null;
    }
    Boolean passedBool = (Boolean) config.get(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD);
    if (passedBool != null && passedBool.booleanValue()) {
        Float cutValue = (Float) config.get(MSCourseNode.CONFIG_KEY_PASSED_CUT_VALUE);
        Boolean sumCheckbox = (Boolean) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_SUM_CHECKBOX);
        if (sumCheckbox != null && sumCheckbox.booleanValue()) {
            Integer minValue = (Integer) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_SUM_CUTVALUE);
            int checkedBox = checkboxManager.countChecked(assessedIdentity, course, getIdent());
            if (minValue != null && minValue.intValue() <= checkedBox) {
                updatedPassed = Boolean.TRUE;
            } else {
                updatedPassed = Boolean.FALSE;
            }
        } else if (cutValue != null) {
            if (updatedScore == null) {
                updatedScore = checkboxManager.calculateScore(assessedIdentity, course, getIdent());
            }
            if (updatedScore != null && cutValue.floatValue() <= updatedScore.floatValue()) {
                updatedPassed = Boolean.TRUE;
            } else {
                updatedPassed = Boolean.FALSE;
            }
        }
    } else {
        updatedPassed = null;
    }
    boolean needUpdate = false;
    Boolean manualCorrection = (Boolean) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_MANUAL_CORRECTION);
    if (manualCorrection == null || !manualCorrection.booleanValue()) {
        // update passed
        if ((currentPassed == null && updatedPassed != null && updatedScore != null && updatedScore.floatValue() > 0f) || (currentPassed != null && updatedPassed == null) || (currentPassed != null && !currentPassed.equals(updatedPassed))) {
            needUpdate = true;
        }
    }
    if ((currentScore == null && updatedScore != null && updatedScore.floatValue() > 0f) || (currentScore != null && updatedScore == null) || (currentScore != null && !currentScore.equals(updatedScore))) {
        needUpdate = true;
    }
    if (needUpdate) {
        ScoreEvaluation scoreEval = new ScoreEvaluation(updatedScore, updatedPassed);
        IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, null);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
        am.saveScoreEvaluation(this, coachIdentity, assessedIdentity, scoreEval, uce, false, Role.coach);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentManager(org.olat.course.assessment.AssessmentManager) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 28 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project openolat by klemens.

the class CheckListAssessmentController method loadDatas.

private List<CheckListAssessmentRow> loadDatas() {
    if (!(coachCourseEnv instanceof UserCourseEnvironmentImpl)) {
        return Collections.emptyList();
    }
    UserCourseEnvironmentImpl env = (UserCourseEnvironmentImpl) coachCourseEnv;
    List<Checkbox> checkboxColl = checkboxList.getList();
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    boolean courseAdmin = env.isAdmin();
    RepositoryEntry re = env.getCourseRepositoryEntry();
    boolean courseTutor = repositoryService.hasRole(getIdentity(), re, GroupRoles.coach.name());
    Set<Long> missingIdentityKeys = new HashSet<>();
    if (courseTutor || courseAdmin) {
        List<RepositoryEntryMembership> repoMemberships = repositoryManager.getRepositoryEntryMembership(re);
        for (RepositoryEntryMembership repoMembership : repoMemberships) {
            if (repoMembership.isParticipant()) {
                missingIdentityKeys.add(repoMembership.getIdentityKey());
            }
        }
    }
    List<BusinessGroup> coachedGroups = courseAdmin ? coachCourseEnv.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups() : env.getCoachedGroups();
    List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(courseOres, courseNode.getIdent(), courseTutor || courseAdmin ? re : null, coachedGroups);
    List<CheckListAssessmentRow> boxList = getAssessmentDataViews(dataList, checkboxColl);
    Map<Long, CheckListAssessmentRow> identityToView = new HashMap<>();
    for (CheckListAssessmentRow box : boxList) {
        identityToView.put(box.getIdentityKey(), box);
        missingIdentityKeys.remove(box.getIdentityKey());
    }
    List<BusinessGroupMembership> memberships = businessGroupService.getBusinessGroupsMembership(coachedGroups);
    for (BusinessGroupMembership membership : memberships) {
        if (!membership.isParticipant())
            continue;
        Long identityKey = membership.getIdentityKey();
        if (!identityToView.containsKey(identityKey)) {
            missingIdentityKeys.add(identityKey);
        }
    }
    List<Identity> missingIdentities = securityManager.loadIdentityByKeys(missingIdentityKeys);
    for (Identity missingIdentity : missingIdentities) {
        Boolean[] checked = new Boolean[numOfCheckbox];
        Float[] scores = new Float[numOfCheckbox];
        CheckListAssessmentRow view = new CheckListAssessmentRow(missingIdentity, checked, scores, null, userPropertyHandlers, getLocale());
        identityToView.put(missingIdentity.getKey(), view);
    }
    for (BusinessGroupMembership membership : memberships) {
        if (!membership.isParticipant())
            continue;
        CheckListAssessmentRow view = identityToView.get(membership.getIdentityKey());
        if (view != null) {
            view.addGroupKey(membership.getGroupKey());
        }
    }
    List<CheckListAssessmentRow> views = new ArrayList<>();
    views.addAll(identityToView.values());
    return views;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Example 29 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project openolat by klemens.

the class CourseTemplateSearchController method loadModel.

private void loadModel(UserRequest ureq) {
    IdentityEnvironment identityEnv = ureq.getUserSession().getIdentityEnvironment();
    List<Binder> currentBinders = portfolioService.searchOwnedBindersFromCourseTemplate(getIdentity());
    Set<CurrentBinder> currentSet = new HashSet<>();
    for (Binder currentBinder : currentBinders) {
        Long courseEntryKey = currentBinder.getEntry().getKey();
        String nodeIdent = currentBinder.getSubIdent();
        currentSet.add(new CurrentBinder(courseEntryKey, nodeIdent));
    }
    List<RepositoryEntry> entries = portfolioService.searchCourseWithBinderTemplates(getIdentity());
    List<CourseTemplateRow> rows = new ArrayList<>(entries.size());
    for (RepositoryEntry entry : entries) {
        ICourse course = CourseFactory.loadCourse(entry);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
        uce.getScoreAccounting().evaluateAll();
        CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode();
        loadCourseModel(rootNode, uce, rows, currentSet);
    }
    model.setObjects(rows);
    tableEl.reset();
    tableEl.reloadData();
}
Also used : UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseTemplateRow(org.olat.modules.portfolio.ui.model.CourseTemplateRow) Binder(org.olat.modules.portfolio.Binder) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) CourseNode(org.olat.course.nodes.CourseNode) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) HashSet(java.util.HashSet)

Example 30 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project openolat by klemens.

the class FeedMediaDispatcher method hasAccess.

/**
 * Verifies the access of an identity to a course node.
 *
 * @param identity
 * @param token
 * @param course
 * @param node
 * @return True if the identity has access to the node in the given course.
 *         False otherwise.
 */
private boolean hasAccess(Identity identity, String token, ICourse course, CourseNode node) {
    boolean hasAccess = false;
    final RepositoryManager resMgr = RepositoryManager.getInstance();
    final RepositoryEntry repoEntry = resMgr.lookupRepositoryEntry(course, false);
    if (allowsGuestAccess(repoEntry)) {
        hasAccess = true;
    } else {
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(identity);
        Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
        ienv.setRoles(roles);
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // Build an evaluation tree
        TreeEvaluation treeEval = new TreeEvaluation();
        NodeEvaluation nodeEval = node.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        if (nodeEval.isVisible() && validAuthentication(identity, token)) {
            hasAccess = true;
        }
    }
    return hasAccess;
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Aggregations

UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)84 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)60 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)58 ICourse (org.olat.course.ICourse)40 Identity (org.olat.core.id.Identity)32 RepositoryEntry (org.olat.repository.RepositoryEntry)28 CourseNode (org.olat.course.nodes.CourseNode)24 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)22 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)22 Roles (org.olat.core.id.Roles)14 ArrayList (java.util.ArrayList)12 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)10 BusinessGroup (org.olat.group.BusinessGroup)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)8 Test (org.junit.Test)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)6