Search in sources :

Example 11 with ICourse

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

the class CourseAssessmentManagerImpl method saveScoreEvaluation.

@Override
public void saveScoreEvaluation(AssessableCourseNode courseNode, Identity identity, Identity assessedIdentity, ScoreEvaluation scoreEvaluation, UserCourseEnvironment userCourseEnv, boolean incrementUserAttempts, Role by) {
    final ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    final CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment();
    Float score = scoreEvaluation.getScore();
    Boolean passed = scoreEvaluation.getPassed();
    Long assessmentId = scoreEvaluation.getAssessmentID();
    String subIdent = courseNode.getIdent();
    RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
    AssessmentEntry assessmentEntry = getOrCreate(assessedIdentity, subIdent, referenceEntry);
    if (referenceEntry != null && !referenceEntry.equals(assessmentEntry.getReferenceEntry())) {
        assessmentEntry.setReferenceEntry(referenceEntry);
    }
    if (by == Role.coach) {
        assessmentEntry.setLastCoachModified(new Date());
    } else if (by == Role.user) {
        assessmentEntry.setLastUserModified(new Date());
    }
    if (score == null) {
        assessmentEntry.setScore(null);
    } else {
        assessmentEntry.setScore(new BigDecimal(Float.toString(score)));
    }
    assessmentEntry.setPassed(passed);
    assessmentEntry.setFullyAssessed(scoreEvaluation.getFullyAssessed());
    if (assessmentId != null) {
        assessmentEntry.setAssessmentId(assessmentId);
    }
    if (scoreEvaluation.getAssessmentStatus() != null) {
        assessmentEntry.setAssessmentStatus(scoreEvaluation.getAssessmentStatus());
    }
    if (scoreEvaluation.getUserVisible() != null) {
        assessmentEntry.setUserVisibility(scoreEvaluation.getUserVisible());
    }
    if (scoreEvaluation.getCurrentRunCompletion() != null) {
        assessmentEntry.setCurrentRunCompletion(scoreEvaluation.getCurrentRunCompletion());
    }
    if (scoreEvaluation.getCurrentRunStatus() != null) {
        assessmentEntry.setCurrentRunStatus(scoreEvaluation.getCurrentRunStatus());
    }
    Integer attempts = null;
    if (incrementUserAttempts) {
        attempts = assessmentEntry.getAttempts() == null ? 1 : assessmentEntry.getAttempts().intValue() + 1;
        assessmentEntry.setAttempts(attempts);
    }
    assessmentEntry = assessmentService.updateAssessmentEntry(assessmentEntry);
    // commit before sending events
    DBFactory.getInstance().commit();
    // reevalute the tree
    ScoreAccounting scoreAccounting = userCourseEnv.getScoreAccounting();
    scoreAccounting.evaluateAll(true);
    // commit before sending events
    DBFactory.getInstance().commit();
    // node log
    UserNodeAuditManager am = courseEnv.getAuditManager();
    am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "score set to: " + String.valueOf(scoreEvaluation.getScore()));
    if (scoreEvaluation.getPassed() != null) {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "passed set to: " + scoreEvaluation.getPassed().toString());
    } else {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "passed set to \"undefined\"");
    }
    if (scoreEvaluation.getAssessmentID() != null) {
        am.appendToUserNodeLog(courseNode, assessedIdentity, assessedIdentity, "assessmentId set to: " + scoreEvaluation.getAssessmentID().toString());
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_SCORE_EVAL_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    if (scoreEvaluation.getScore() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_SCORE_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiScore, "", String.valueOf(scoreEvaluation.getScore())));
    }
    if (scoreEvaluation.getPassed() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", String.valueOf(scoreEvaluation.getPassed())));
    } else {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", "undefined"));
    }
    if (incrementUserAttempts && attempts != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
    }
    // write only when enabled for this course
    if (courseEnv.getCourseConfig().isEfficencyStatementEnabled()) {
        List<AssessmentNodeData> data = new ArrayList<AssessmentNodeData>(50);
        AssessmentNodesLastModified lastModifications = new AssessmentNodesLastModified();
        AssessmentHelper.getAssessmentNodeDataList(0, courseEnv.getRunStructure().getRootNode(), scoreAccounting, userCourseEnv, true, true, true, data, lastModifications);
        efficiencyStatementManager.updateUserEfficiencyStatement(assessedIdentity, courseEnv, data, lastModifications, cgm.getCourseEntry());
    }
    if (course.getCourseConfig().isAutomaticCertificationEnabled()) {
        CourseNode rootNode = courseEnv.getRunStructure().getRootNode();
        ScoreEvaluation rootEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
        if (rootEval != null && rootEval.getPassed() != null && rootEval.getPassed().booleanValue() && certificatesManager.isCertificationAllowed(assessedIdentity, cgm.getCourseEntry())) {
            CertificateTemplate template = null;
            Long templateId = course.getCourseConfig().getCertificateTemplate();
            if (templateId != null) {
                template = certificatesManager.getTemplateById(templateId);
            }
            CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, rootEval.getScore(), rootEval.getPassed());
            certificatesManager.generateCertificate(certificateInfos, cgm.getCourseEntry(), template, true);
        }
    }
}
Also used : AssessmentNodesLastModified(org.olat.course.assessment.model.AssessmentNodesLastModified) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssessmentNodeData(org.olat.course.assessment.model.AssessmentNodeData) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode)

Example 12 with ICourse

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

the class CourseAssessmentManagerImpl method saveNodeCoachComment.

@Override
public void saveNodeCoachComment(CourseNode courseNode, Identity assessedIdentity, String comment) {
    ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
    nodeAssessment.setCoachComment(comment);
    assessmentService.updateAssessmentEntry(nodeAssessment);
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_COACH_COMMENT_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_COACHCOMMENT_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiCoachComment, "", StringHelper.stripLineBreaks(comment)));
}
Also used : AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 13 with ICourse

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

the class AssessmentModeEditController method doChooseGroups.

private void doChooseGroups(UserRequest ureq) {
    if (groupChooseCtrl != null)
        return;
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseGroupManager groupManager = course.getCourseEnvironment().getCourseGroupManager();
    groupChooseCtrl = new GroupSelectionController(ureq, getWindowControl(), true, groupManager, groupKeys);
    listenTo(groupChooseCtrl);
    cmc = new CloseableModalController(getWindowControl(), null, groupChooseCtrl.getInitialComponent(), true, translate("popup.choosegroups"), false);
    listenTo(cmc);
    cmc.activate();
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) GroupSelectionController(org.olat.course.condition.GroupSelectionController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ICourse(org.olat.course.ICourse)

Example 14 with ICourse

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

the class AssessmentModeEditController method doChooseAreas.

private void doChooseAreas(UserRequest ureq) {
    if (areaChooseCtrl != null)
        return;
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseGroupManager groupManager = course.getCourseEnvironment().getCourseGroupManager();
    areaChooseCtrl = new AreaSelectionController(ureq, getWindowControl(), true, groupManager, areaKeys);
    listenTo(areaChooseCtrl);
    cmc = new CloseableModalController(getWindowControl(), null, areaChooseCtrl.getInitialComponent(), true, translate("popup.chooseareas"), false);
    listenTo(cmc);
    cmc.activate();
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ICourse(org.olat.course.ICourse) AreaSelectionController(org.olat.course.condition.AreaSelectionController)

Example 15 with ICourse

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

the class AssessmentModeEditController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_assessment_mode_edit_form");
    setFormContextHelp("Assessment mode");
    if (StringHelper.containsNonWhitespace(assessmentMode.getName())) {
        setFormTitle("form.mode.title", new String[] { assessmentMode.getName() });
    } else {
        setFormTitle("form.mode.title.add");
    }
    setFormDescription("form.mode.description");
    ICourse course = CourseFactory.loadCourse(courseOres);
    if (StringHelper.containsNonWhitespace(assessmentMode.getStartElement())) {
        CourseNode startElement = course.getRunStructure().getNode(assessmentMode.getStartElement());
        if (startElement == null) {
            setFormWarning("warning.missing.start.element");
        }
    }
    if (StringHelper.containsNonWhitespace(assessmentMode.getElementList())) {
        String elements = assessmentMode.getElementList();
        for (String element : elements.split(",")) {
            CourseNode node = course.getRunStructure().getNode(element);
            if (node == null) {
                setFormWarning("warning.missing.element");
            }
        }
    }
    Status status = assessmentMode.getStatus();
    String name = assessmentMode.getName();
    nameEl = uifactory.addTextElement("mode.name", "mode.name", 255, name, formLayout);
    nameEl.setElementCssClass("o_sel_assessment_mode_name");
    nameEl.setMandatory(true);
    nameEl.setEnabled(status != Status.followup && status != Status.end);
    String desc = assessmentMode.getDescription();
    descriptionEl = uifactory.addRichTextElementForStringData("mode.description", "mode.description", desc, 6, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    descriptionEl.setEnabled(status != Status.followup && status != Status.end);
    beginEl = uifactory.addDateChooser("mode.begin", assessmentMode.getBegin(), formLayout);
    beginEl.setElementCssClass("o_sel_assessment_mode_begin");
    beginEl.setDateChooserTimeEnabled(true);
    beginEl.setMandatory(true);
    beginEl.setEnabled(status == Status.none || status == Status.leadtime);
    int leadTime = assessmentMode.getLeadTime();
    if (leadTime < 0) {
        leadTime = 0;
    }
    leadTimeEl = uifactory.addIntegerElement("mode.leadTime", leadTime, formLayout);
    leadTimeEl.setElementCssClass("o_sel_assessment_mode_leadtime");
    leadTimeEl.setDisplaySize(3);
    leadTimeEl.setEnabled(status == Status.none || status == Status.leadtime);
    endEl = uifactory.addDateChooser("mode.end", assessmentMode.getEnd(), formLayout);
    endEl.setElementCssClass("o_sel_assessment_mode_end");
    endEl.setDateChooserTimeEnabled(true);
    endEl.setDefaultValue(beginEl);
    endEl.setMandatory(true);
    endEl.setEnabled(status != Status.end);
    int followupTime = assessmentMode.getFollowupTime();
    if (followupTime < 0) {
        followupTime = 0;
    }
    followupTimeEl = uifactory.addIntegerElement("mode.followupTime", followupTime, formLayout);
    followupTimeEl.setElementCssClass("o_sel_assessment_mode_followuptime");
    followupTimeEl.setDisplaySize(3);
    followupTimeEl.setEnabled(status != Status.end);
    String[] startModeValues = new String[] { translate("mode.beginend.automatic"), translate("mode.beginend.manual") };
    startModeEl = uifactory.addDropdownSingleselect("mode.beginend", formLayout, startModeKeys, startModeValues, null);
    startModeEl.setElementCssClass("o_sel_assessment_mode_start_mode");
    if (assessmentMode.isManualBeginEnd()) {
        startModeEl.select(startModeKeys[1], true);
    } else {
        startModeEl.select(startModeKeys[0], true);
    }
    startModeEl.setEnabled(status != Status.end);
    String[] audienceKeys = new String[] { AssessmentMode.Target.courseAndGroups.name(), AssessmentMode.Target.course.name(), AssessmentMode.Target.groups.name() };
    String[] audienceValues = new String[] { translate("target.courseAndGroups"), translate("target.course"), translate("target.groups") };
    targetEl = uifactory.addRadiosVertical("audience", "mode.target", formLayout, audienceKeys, audienceValues);
    targetEl.setElementCssClass("o_sel_assessment_mode_audience");
    targetEl.setEnabled(status != Status.end);
    Target target = assessmentMode.getTargetAudience();
    if (target != null) {
        for (String audienceKey : audienceKeys) {
            if (audienceKey.equals(target.name())) {
                targetEl.select(audienceKey, true);
            }
        }
    }
    if (!targetEl.isOneSelected()) {
        targetEl.select(audienceKeys[0], true);
    }
    // choose groups
    String groupPage = velocity_root + "/choose_groups.html";
    chooseGroupsCont = FormLayoutContainer.createCustomFormLayout("chooseGroups", getTranslator(), groupPage);
    chooseGroupsCont.setRootForm(mainForm);
    formLayout.add(chooseGroupsCont);
    chooseGroupsButton = uifactory.addFormLink("choose.groups", chooseGroupsCont, Link.BUTTON);
    chooseGroupsButton.setEnabled(status != Status.end);
    chooseAreasButton = uifactory.addFormLink("choose.areas", chooseGroupsCont, Link.BUTTON);
    chooseAreasButton.setEnabled(status != Status.end);
    groupKeys = new ArrayList<>();
    groupNames = new ArrayList<>();
    for (AssessmentModeToGroup modeToGroup : assessmentMode.getGroups()) {
        BusinessGroup group = modeToGroup.getBusinessGroup();
        groupKeys.add(group.getKey());
        groupNames.add(StringHelper.escapeHtml(group.getName()));
    }
    chooseGroupsCont.getFormItemComponent().contextPut("groupNames", groupNames);
    areaKeys = new ArrayList<>();
    areaNames = new ArrayList<>();
    for (AssessmentModeToArea modeToArea : assessmentMode.getAreas()) {
        BGArea area = modeToArea.getArea();
        areaKeys.add(area.getKey());
        areaNames.add(StringHelper.escapeHtml(area.getName()));
    }
    chooseGroupsCont.getFormItemComponent().contextPut("areaNames", areaNames);
    // course elements
    courseElementsRestrictionEl = uifactory.addCheckboxesHorizontal("cer", "mode.course.element.restriction", formLayout, onKeys, onValues);
    courseElementsRestrictionEl.addActionListener(FormEvent.ONCHANGE);
    courseElementsRestrictionEl.select(onKeys[0], assessmentMode.isRestrictAccessElements());
    courseElementsRestrictionEl.setEnabled(status != Status.end);
    String coursePage = velocity_root + "/choose_elements.html";
    chooseElementsCont = FormLayoutContainer.createCustomFormLayout("chooseElements", getTranslator(), coursePage);
    chooseElementsCont.setRootForm(mainForm);
    formLayout.add(chooseElementsCont);
    chooseElementsCont.setVisible(assessmentMode.isRestrictAccessElements());
    CourseEditorTreeModel treeModel = course.getEditorTreeModel();
    elementKeys = new ArrayList<>();
    elementNames = new ArrayList<>();
    String elements = assessmentMode.getElementList();
    if (StringHelper.containsNonWhitespace(elements)) {
        for (String element : elements.split(",")) {
            String courseNodeName = getCourseNodeName(element, treeModel);
            if (StringHelper.containsNonWhitespace(courseNodeName)) {
                elementKeys.add(element);
                elementNames.add(courseNodeName);
            }
        }
    }
    chooseElementsCont.getFormItemComponent().contextPut("elementNames", elementNames);
    chooseElementsButton = uifactory.addFormLink("choose.elements", chooseElementsCont, Link.BUTTON);
    chooseElementsButton.setEnabled(status != Status.end);
    startElementKey = assessmentMode.getStartElement();
    String startElementName = "";
    if (StringHelper.containsNonWhitespace(startElementKey)) {
        startElementName = getCourseNodeName(startElementKey, treeModel);
    }
    startElementEl = uifactory.addStaticTextElement("mode.start.element", "mode.start.element", startElementName, formLayout);
    chooseStartElementButton = uifactory.addFormLink("choose.start.element", formLayout, Link.BUTTON);
    chooseStartElementButton.setEnabled(status != Status.end);
    // ips
    ipsEl = uifactory.addCheckboxesHorizontal("ips", "mode.ips", formLayout, onKeys, onValues);
    ipsEl.select(onKeys[0], assessmentMode.isRestrictAccessIps());
    ipsEl.addActionListener(FormEvent.ONCHANGE);
    ipsEl.setEnabled(status != Status.end);
    String ipList = assessmentMode.getIpList();
    ipListEl = uifactory.addTextAreaElement("mode.ips.list", "mode.ips.list", 4096, 4, 60, false, ipList, formLayout);
    ipListEl.setVisible(assessmentMode.isRestrictAccessIps());
    ipListEl.setEnabled(status != Status.end);
    safeExamBrowserEl = uifactory.addCheckboxesHorizontal("safeexam", "mode.safeexambrowser", formLayout, onKeys, onValues);
    safeExamBrowserEl.select(onKeys[0], assessmentMode.isSafeExamBrowser());
    safeExamBrowserEl.addActionListener(FormEvent.ONCHANGE);
    safeExamBrowserEl.setEnabled(status != Status.end);
    String key = assessmentMode.getSafeExamBrowserKey();
    safeExamBrowserKeyEl = uifactory.addTextAreaElement("safeexamkey", "mode.safeexambrowser.key", 4096, 6, 60, false, key, formLayout);
    safeExamBrowserKeyEl.setVisible(assessmentMode.isSafeExamBrowser());
    safeExamBrowserKeyEl.setEnabled(status != Status.end);
    String hint = assessmentMode.getSafeExamBrowserHint();
    safeExamBrowserHintEl = uifactory.addRichTextElementForStringData("safeexamhint", "mode.safeexambrowser.hint", hint, 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    safeExamBrowserHintEl.setVisible(assessmentMode.isSafeExamBrowser());
    safeExamBrowserHintEl.setEnabled(status != Status.end);
    forCoachEl = uifactory.addCheckboxesHorizontal("forcoach", "mode.for.coach", formLayout, onKeys, onValues);
    forCoachEl.select(onKeys[0], assessmentMode.isApplySettingsForCoach());
    forCoachEl.setEnabled(status != Status.end);
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("button", getTranslator());
    formLayout.add(buttonCont);
    if (status != Status.end) {
        uifactory.addFormSubmitButton("save", buttonCont);
    }
    uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
Also used : Status(org.olat.course.assessment.AssessmentMode.Status) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) BusinessGroup(org.olat.group.BusinessGroup) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) Target(org.olat.course.assessment.AssessmentMode.Target) BGArea(org.olat.group.area.BGArea) CourseNode(org.olat.course.nodes.CourseNode)

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