コード例 #1
0
 /**
  * @see org.olat.course.nodes.CourseNode#informOnDelete(org.olat.core.gui.UserRequest,
  *     org.olat.course.ICourse)
  */
 @Override
 public String informOnDelete(final Locale locale, final ICourse course) {
   final CoursePropertyManager cpm = PersistingCoursePropertyManager.getInstance(course);
   final List list = cpm.listCourseNodeProperties(this, null, null, null);
   if (list.size() == 0) {
     return null; // no properties created yet
   }
   final Translator trans = new PackageTranslator(PACKAGE_MS, locale);
   return trans.translate("warn.nodedelete");
 }
コード例 #2
0
 /** @see org.olat.course.nodes.CourseNode#cleanupOnDelete(org.olat.course.ICourse) */
 @Override
 public void cleanupOnDelete(final ICourse course) {
   final CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
   // Delete all properties: score, passed, log, comment, coach_comment
   pm.deleteNodeProperties(this, null);
 }
コード例 #3
0
  /**
   * @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.getInstance().deactivate(p);
      return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }

    try {
      Date latestNews = p.getLatestNewsDate();
      Identity identity = subscriber.getIdentity();

      // do not try to create a subscription info if state is deleted - results in
      // exceptions, course
      // can't be loaded when already deleted
      if (NotificationsManager.getInstance().isPublisherValid(p)
          && compareDate.before(latestNews)) {
        Long courseId = new Long(p.getData());
        final ICourse course = loadCourseFromId(courseId);
        if (course != null) {
          // 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 List<Identity> coachedUsers = new ArrayList<Identity>();
          if (!hasFullAccess) {
            // initialize list of users, only when user has not full access
            List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
            BusinessGroupService businessGroupService =
                CoreSpringFactory.getImpl(BusinessGroupService.class);
            List<Identity> coachedIdentites =
                businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
            coachedUsers.addAll(coachedIdentites);
          }

          List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
          Translator translator =
              Util.createPackageTranslator(AssessmentNotificationsHandler.class, locale);

          for (AssessableCourseNode test : testNodes) {
            final CoursePropertyManager cpm =
                course.getCourseEnvironment().getCoursePropertyManager();

            List<Property> scoreProperties =
                cpm.listCourseNodeProperties(test, null, null, AssessmentManager.SCORE);
            List<Property> attemptProperties =
                cpm.listCourseNodeProperties(test, null, null, AssessmentManager.ATTEMPTS);

            for (Property attemptProperty : attemptProperties) {
              Date modDate = attemptProperty.getLastModified();
              Identity assessedIdentity = attemptProperty.getIdentity();
              if (modDate.after(compareDate)
                  && (hasFullAccess
                      || PersistenceHelper.listContainsObjectByKey(
                          coachedUsers, assessedIdentity))) {
                String score = null;
                for (Property scoreProperty : scoreProperties) {
                  if (scoreProperty.getIdentity().equalsByPersistableKey(assessedIdentity)) {
                    score = scoreProperty.getFloatValue().toString();
                    break;
                  }
                }

                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 {
                  desc =
                      translator.translate(
                          "notifications.entry",
                          new String[] {
                            test.getShortTitle(),
                            NotificationHelper.getFormatedName(assessedIdentity),
                            score,
                            type
                          });
                }

                String urlToSend = null;
                String businessPath = null;
                if (p.getBusinessPath() != null) {
                  businessPath =
                      p.getBusinessPath()
                          + "[assessmentTool:0][Identity:"
                          + assessedIdentity.getKey()
                          + "][CourseNode:"
                          + test.getIdent()
                          + "]";
                  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.getInstance().getNoSubscriptionInfo();
      }
      return si;
    } catch (Exception e) {
      log.error("Error while creating assessment notifications", e);
      checkPublisher(p);
      return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
  }