Search in sources :

Example 76 with AssessableCourseNode

use of org.olat.course.nodes.AssessableCourseNode in project OpenOLAT by OpenOLAT.

the class IdentityCertificatesController method doGenerateCertificate.

private void doGenerateCertificate(UserRequest ureq) {
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    Roles roles = securityManager.getRoles(assessedIdentity);
    IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, roles);
    UserCourseEnvironment assessedUserCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
    ScoreAccounting scoreAccounting = assessedUserCourseEnv.getScoreAccounting();
    scoreAccounting.evaluateAll();
    ScoreEvaluation scoreEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
    CertificateTemplate template = null;
    Long templateKey = course.getCourseConfig().getCertificateTemplate();
    if (templateKey != null) {
        template = certificatesManager.getTemplateById(templateKey);
    }
    Float score = scoreEval == null ? null : scoreEval.getScore();
    Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
    loadList();
    showInfo("msg.certificate.pending");
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 77 with AssessableCourseNode

use of org.olat.course.nodes.AssessableCourseNode in project OpenOLAT by OpenOLAT.

the class DropboxController method getConfirmation.

private String getConfirmation(UserRequest ureq, String filename) {
    // grab confirmation-text from bb-config
    String confirmation = config.getStringValue(TACourseNode.CONF_DROPBOX_CONFIRMATION);
    Context c = new VelocityContext();
    Identity identity = ureq.getIdentity();
    c.put("login", identity.getName());
    c.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
    c.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
    c.put("email", UserManager.getInstance().getUserDisplayEmail(identity, getLocale()));
    c.put("filename", filename);
    Date now = new Date();
    Formatter f = Formatter.getInstance(ureq.getLocale());
    c.put("date", f.formatDate(now));
    c.put("time", f.formatTime(now));
    // update attempts counter for this user: one file - one attempts
    AssessableCourseNode acn = (AssessableCourseNode) node;
    acn.incrementUserAttempts(userCourseEnv, Role.user);
    // log entry for this file
    UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
    am.appendToUserNodeLog(node, identity, identity, "FILE UPLOADED: " + filename);
    return VelocityHelper.getInstance().evaluateVTL(confirmation, c);
}
Also used : Context(org.apache.velocity.context.Context) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VelocityContext(org.apache.velocity.VelocityContext) MailContext(org.olat.core.util.mail.MailContext) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) VelocityContext(org.apache.velocity.VelocityContext) Formatter(org.olat.core.util.Formatter) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 78 with AssessableCourseNode

use of org.olat.course.nodes.AssessableCourseNode in project OpenOLAT by OpenOLAT.

the class AssessmentNotificationsHandler method createSubscriptionInfo.

/**
 * @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
 *      java.util.Locale, java.util.Date)
 */
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    if (!NotificationsUpgradeHelper.checkCourse(p)) {
        // course don't exist anymore
        notificationsManager.deactivate(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
    try {
        Date latestNews = p.getLatestNewsDate();
        Identity identity = subscriber.getIdentity();
        // can't be loaded when already deleted
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            Long courseId = new Long(p.getData());
            final ICourse course = loadCourseFromId(courseId);
            if (courseStatus(course)) {
                // course admins or users with the course right to have full access to
                // the assessment tool will have full access to user tests
                CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
                final boolean hasFullAccess = (cgm.isIdentityCourseAdministrator(identity) ? true : cgm.hasRight(identity, CourseRights.RIGHT_ASSESSMENT));
                final Set<Identity> coachedUsers = new HashSet<Identity>();
                if (!hasFullAccess) {
                    // initialize list of users, only when user has not full access
                    List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
                    List<Identity> coachedIdentites = businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
                    coachedUsers.addAll(coachedIdentites);
                }
                List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
                Translator translator = Util.createPackageTranslator(AssessmentManager.class, locale);
                for (AssessableCourseNode test : testNodes) {
                    List<AssessmentEntry> assessments = courseNodeAssessmentDao.loadAssessmentEntryBySubIdent(cgm.getCourseEntry(), test.getIdent());
                    for (AssessmentEntry assessment : assessments) {
                        Date modDate = assessment.getLastModified();
                        Identity assessedIdentity = assessment.getIdentity();
                        if (modDate.after(compareDate) && (hasFullAccess || coachedUsers.contains(assessedIdentity))) {
                            BigDecimal score = assessment.getScore();
                            if (test instanceof ScormCourseNode) {
                                ScormCourseNode scormTest = (ScormCourseNode) test;
                                // check if completed or passed
                                String status = ScormAssessmentManager.getInstance().getLastLessonStatus(assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
                                if (!"passed".equals(status) && !"completed".equals(status)) {
                                    continue;
                                }
                            }
                            String desc;
                            String type = translator.translate("notifications.entry." + test.getType());
                            if (score == null) {
                                desc = translator.translate("notifications.entry.attempt", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), type });
                            } else {
                                String scoreStr = AssessmentHelper.getRoundedScore(score);
                                desc = translator.translate("notifications.entry", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), scoreStr, type });
                            }
                            String urlToSend = null;
                            String businessPath = null;
                            if (p.getBusinessPath() != null) {
                                businessPath = p.getBusinessPath() + "[Users:0][Node:" + test.getIdent() + "][Identity:" + assessedIdentity.getKey() + "]";
                                urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                            }
                            SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_USER_ICON);
                            if (si == null) {
                                String title = translator.translate("notifications.header", new String[] { course.getCourseTitle() });
                                String css = CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(test.getType()).getIconCSSClass();
                                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, css), null);
                            }
                            si.addSubscriptionListItem(subListItem);
                        }
                    }
                }
            }
        }
        if (si == null) {
            si = notificationsManager.getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Error while creating assessment notifications", e);
        checkPublisher(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssertException(org.olat.core.logging.AssertException) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 79 with AssessableCourseNode

use of org.olat.course.nodes.AssessableCourseNode in project OpenOLAT by OpenOLAT.

the class BulkAssessmentTask method doProcess.

private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
    final DB dbInstance = DBFactory.getInstance();
    final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
    final ICourse course = CourseFactory.loadCourse(courseRes);
    final AssessableCourseNode courseNode = getCourseNode();
    final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);
    final boolean hasUserComment = courseNode.hasCommentConfigured();
    final boolean hasScore = courseNode.hasScoreConfigured();
    final boolean hasPassed = courseNode.hasPassedConfigured();
    final boolean hasReturnFiles = (StringHelper.containsNonWhitespace(datas.getReturnFiles()) && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));
    if (hasReturnFiles) {
        try {
            OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
            String tmp = FolderConfig.getCanonicalTmpDir();
            unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
            unzipped.mkdirs();
            ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
        } catch (Exception e) {
            log.error("Cannot unzip the return files during bulk assessment", e);
        }
    }
    Float min = null;
    Float max = null;
    Float cut = null;
    if (hasScore) {
        min = courseNode.getMinScoreConfiguration();
        max = courseNode.getMaxScoreConfiguration();
    }
    if (hasPassed) {
        cut = courseNode.getCutValueConfiguration();
    }
    int count = 0;
    List<BulkAssessmentRow> rows = datas.getRows();
    for (BulkAssessmentRow row : rows) {
        Long identityKey = row.getIdentityKey();
        if (identityKey == null) {
            feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
            // nothing to do
            continue;
        }
        Identity identity = securityManager.loadIdentityByKey(identityKey);
        IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // update comment, empty string will reset comment
        String userComment = row.getComment();
        if (hasUserComment && userComment != null) {
            // Update userComment in db
            courseNode.updateUserUserComment(userComment, uce, coachIdentity);
        // LD: why do we have to update the efficiency statement?
        // EfficiencyStatementManager esm =	EfficiencyStatementManager.getInstance();
        // esm.updateUserEfficiencyStatement(uce);
        }
        // update score
        Float score = row.getScore();
        if (hasScore && score != null) {
            // score < minimum score
            if ((min != null && score.floatValue() < min.floatValue()) || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
            // "bulk.action.lessThanMin";
            } else // score > maximum score
            if ((max != null && score.floatValue() > max.floatValue()) || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
            // "bulk.action.greaterThanMax";
            } else {
                // score between minimum and maximum score
                ScoreEvaluation se;
                if (hasPassed && cut != null) {
                    Boolean passed = (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
                    se = new ScoreEvaluation(score, passed);
                } else {
                    se = new ScoreEvaluation(score, null);
                }
                // Update score,passed properties in db, and the user's efficiency statement
                courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false, Role.auto);
            }
        }
        Boolean passed = row.getPassed();
        if (hasPassed && passed != null && cut == null) {
            // Configuration of manual assessment --> Display passed/not passed: yes, Type of display: Manual by tutor
            ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
            Float oldScore = seOld.getScore();
            ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
            // Update score,passed properties in db, and the user's efficiency statement
            boolean incrementAttempts = false;
            courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts, Role.auto);
        }
        boolean identityHasReturnFile = false;
        if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
            String assessedId = row.getAssessedId();
            File assessedFolder = new File(unzipped, assessedId);
            identityHasReturnFile = assessedFolder.exists();
            if (identityHasReturnFile) {
                processReturnFile(courseNode, row, uce, assessedFolder);
            }
        }
        if (courseNode instanceof GTACourseNode) {
            // push the state further
            GTACourseNode gtaNode = (GTACourseNode) courseNode;
            if ((hasScore && score != null) || (hasPassed && passed != null)) {
                // pushed to graded
                updateTasksState(gtaNode, uce, TaskProcess.grading);
            } else if (hasReturnFiles) {
                // push to revised
                updateTasksState(gtaNode, uce, TaskProcess.correction);
            }
        }
        if (count++ % 5 == 0) {
            dbInstance.commitAndCloseSession();
        } else {
            dbInstance.commit();
        }
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow) FileNotFoundException(java.io.FileNotFoundException) BaseSecurity(org.olat.basesecurity.BaseSecurity) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BulkAssessmentFeedback(org.olat.course.assessment.model.BulkAssessmentFeedback) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) DB(org.olat.core.commons.persistence.DB)

Example 80 with AssessableCourseNode

use of org.olat.course.nodes.AssessableCourseNode in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method updateLastModifications.

@Override
public void updateLastModifications(CourseNode courseNode, Identity assessedIdentity, UserCourseEnvironment userCourseEnv, Role by) {
    AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
    if (by == Role.coach) {
        nodeAssessment.setLastCoachModified(new Date());
    } else if (by == Role.user) {
        nodeAssessment.setLastUserModified(new Date());
    }
    assessmentService.updateAssessmentEntry(nodeAssessment);
    DBFactory.getInstance().commit();
    userCourseEnv.getScoreAccounting().evaluateAll(true);
    if (courseNode instanceof AssessableCourseNode) {
        // Update users efficiency statement
        efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
    }
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date)

Aggregations

AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)118 CourseNode (org.olat.course.nodes.CourseNode)48 ICourse (org.olat.course.ICourse)40 Identity (org.olat.core.id.Identity)32 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)28 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)26 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)22 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)22 Date (java.util.Date)20 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)18 STCourseNode (org.olat.course.nodes.STCourseNode)18 ArrayList (java.util.ArrayList)16 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)16 CalculatedAssessableCourseNode (org.olat.course.nodes.CalculatedAssessableCourseNode)14 GTACourseNode (org.olat.course.nodes.GTACourseNode)12 File (java.io.File)10 IOException (java.io.IOException)10 WindowControl (org.olat.core.gui.control.WindowControl)10 MSCourseNode (org.olat.course.nodes.MSCourseNode)10 PersistentAssessableCourseNode (org.olat.course.nodes.PersistentAssessableCourseNode)10