Search in sources :

Example 1 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class InitialAttemptsRuleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/initial_attempts.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    Translator trans = formLayout.getTranslator();
    FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
    ruleCont.setRootForm(formLayout.getRootForm());
    formLayout.add(ruleCont);
    ruleCont.getFormItemComponent().contextPut("id", id);
    ICourse course = CourseFactory.loadCourse(entry);
    String currentValue = null;
    String currentUnit = null;
    String currentCourseNode = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentUnit = r.getRightUnit();
        currentValue = r.getRightOperand();
        currentCourseNode = r.getLeftOperand();
    }
    List<CourseNode> attemptableNodes = new ArrayList<>();
    searchAttemptableNodes(course.getRunStructure().getRootNode(), attemptableNodes);
    String[] nodeKeys = new String[attemptableNodes.size()];
    String[] nodeValues = new String[attemptableNodes.size()];
    for (int i = 0; i < attemptableNodes.size(); i++) {
        CourseNode attemptableNode = attemptableNodes.get(i);
        nodeKeys[i] = attemptableNode.getIdent();
        nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
    }
    courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
    courseNodeEl.setDomReplacementWrapperRequired(false);
    boolean nodeSelected = false;
    if (currentCourseNode != null) {
        for (String nodeKey : nodeKeys) {
            if (currentCourseNode.equals(nodeKey)) {
                courseNodeEl.select(nodeKey, true);
                nodeSelected = true;
            }
        }
    }
    if (!nodeSelected && nodeKeys.length > 0) {
        courseNodeEl.select(nodeKeys[0], true);
    }
    if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
        courseNodeEl.setErrorKey("error.course.node.found", null);
    }
    valueEl = uifactory.addTextElement("attemptvalue.".concat(id), null, 128, currentValue, ruleCont);
    valueEl.setDomReplacementWrapperRequired(false);
    valueEl.setDisplaySize(3);
    String[] unitValues = new String[] { trans.translate(LaunchUnit.day.name()), trans.translate(LaunchUnit.week.name()), trans.translate(LaunchUnit.month.name()), trans.translate(LaunchUnit.year.name()) };
    unitEl = uifactory.addDropdownSingleselect("attemptunit.".concat(id), null, ruleCont, unitKeys, unitValues, null);
    unitEl.setDomReplacementWrapperRequired(false);
    boolean selected = false;
    if (currentUnit != null) {
        for (String unitKey : unitKeys) {
            if (currentUnit.equals(unitKey)) {
                unitEl.select(unitKey, true);
                selected = true;
            }
        }
    }
    if (!selected) {
        unitEl.select(unitKeys[1], true);
    }
    return ruleCont;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 2 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class CourseSite method createController.

@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
    if (entry == null) {
        return getAlternativeController(ureq, wControl, config);
    }
    MainLayoutController c;
    ICourse course = CourseFactory.loadCourse(entry);
    UserSession usess = ureq.getUserSession();
    // course-launch-state depending course-settings
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
    boolean isAllowedToLaunch = reSecurity.canLaunch();
    boolean hasAccess = false;
    if (isAllowedToLaunch) {
        // either check with securityCallback or use access-settings from course-nodes
        if (siteSecCallback != null) {
            hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
        } else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
            hasAccess = false;
        } else {
            // check within course: accessibility of course root node
            CourseNode rootNode = course.getRunStructure().getRootNode();
            UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
            NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
            boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
            hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
        }
    }
    // load course (admins always see content) or alternative controller if course is not launchable
    if (hasAccess || usess.getRoles().isOLATAdmin()) {
        rs.incrementLaunchCounter(entry);
        // build up the context path for linked course
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
        CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {

            @Override
            public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
                return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
            }
        }, false, true);
        // Configure run controller
        // a: don't show close link, is opened as site not tab
        runCtr.setCourseCloseEnabled(false);
        // b: don't show toolbar
        if (!showToolController) {
            runCtr.setToolControllerEnabled(false);
        }
        c = runCtr;
    } else {
        // access restricted (not in group / author) -> show controller
        // defined in olat_extensions (type autoCreator)
        c = getAlternativeController(ureq, wControl, config);
    }
    return c;
}
Also used : TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) AssessmentMode(org.olat.course.assessment.AssessmentMode) StateSite(org.olat.core.id.context.StateSite) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) RunMainController(org.olat.course.run.RunMainController) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RunMainController(org.olat.course.run.RunMainController) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) Controller(org.olat.core.gui.control.Controller) RuntimeControllerCreator(org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) UserSession(org.olat.core.util.UserSession) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RepositoryManager(org.olat.repository.RepositoryManager) CourseNode(org.olat.course.nodes.CourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService)

Example 3 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class AttemptsRuleSPI method filter.

@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        String nodeIdent = r.getLeftOperand();
        String operator = r.getOperator();
        int value = Integer.parseInt(r.getRightOperand());
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
        if (courseNode == null) {
            identities.clear();
            log.error("Attempts rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
            return;
        }
        Map<Long, Integer> attempts = helperDao.getAttempts(entry, courseNode, identities);
        for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
            Identity identity = identityIt.next();
            Integer attempt = attempts.get(identity.getKey());
            if (attempt == null) {
                attempt = 0;
            }
            if (!evaluateAttempt(attempt.intValue(), operator, value)) {
                identityIt.remove();
            }
        }
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 4 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class QTI21ArchiveFormat method exportCourseElement.

/**
 * @param exportStream
 */
public void exportCourseElement(ZipOutputStream exportStream) {
    ICourse course = CourseFactory.loadCourse(searchParams.getCourseEntry());
    courseNode = course.getRunStructure().getNode(searchParams.getNodeIdent());
    String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeWithMinutes(new Date()) + ".xlsx";
    exportCourseElement(label, exportStream);
}
Also used : ICourse(org.olat.course.ICourse) Date(java.util.Date)

Example 5 with ICourse

use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.

the class PortfolioServiceImpl method getAssessmentStatus.

@Override
public AssessmentEntryStatus getAssessmentStatus(Identity assessedIdentity, BinderRef binderRef) {
    Binder binder = binderDao.loadByKey(binderRef.getKey());
    RepositoryEntry entry = binder.getEntry();
    AssessmentEntryStatus status = null;
    if ("CourseModule".equals(entry.getOlatResource().getResourceableTypeName())) {
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode courseNode = course.getRunStructure().getNode(binder.getSubIdent());
        if (courseNode instanceof PortfolioCourseNode) {
            PortfolioCourseNode pfNode = (PortfolioCourseNode) courseNode;
            UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            AssessmentEvaluation eval = pfNode.getUserScoreEvaluation(userCourseEnv);
            status = eval.getAssessmentStatus();
        }
    } else {
        OLATResource resource = ((BinderImpl) binder.getTemplate()).getOlatResource();
        RepositoryEntry referenceEntry = repositoryService.loadByResourceKey(resource.getKey());
        AssessmentEntry assessmentEntry = assessmentService.getOrCreateAssessmentEntry(assessedIdentity, null, binder.getEntry(), binder.getSubIdent(), referenceEntry);
        status = assessmentEntry.getAssessmentStatus();
    }
    return status;
}
Also used : Binder(org.olat.modules.portfolio.Binder) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) SynchedBinder(org.olat.modules.portfolio.model.SynchedBinder) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) AssessmentEvaluation(org.olat.course.run.scoring.AssessmentEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseNode(org.olat.course.nodes.CourseNode) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) AssessmentEntryStatus(org.olat.modules.assessment.model.AssessmentEntryStatus) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Aggregations

ICourse (org.olat.course.ICourse)674 Identity (org.olat.core.id.Identity)262 RepositoryEntry (org.olat.repository.RepositoryEntry)246 CourseNode (org.olat.course.nodes.CourseNode)182 Test (org.junit.Test)158 ArrayList (java.util.ArrayList)102 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)90 Date (java.util.Date)84 URI (java.net.URI)76 HttpResponse (org.apache.http.HttpResponse)76 OLATResource (org.olat.resource.OLATResource)64 File (java.io.File)62 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)52 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)52 Produces (javax.ws.rs.Produces)48 Roles (org.olat.core.id.Roles)44 Path (javax.ws.rs.Path)42 UserRequest (org.olat.core.gui.UserRequest)42 INode (org.olat.core.util.nodes.INode)40 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)40