コード例 #1
0
 @Override
 @SuppressWarnings("unchecked")
 public void onCloseCourse(Course course) throws SystemException {
   for (CourseResult courseResult :
       (List<CourseResult>)
           CourseResultLocalServiceUtil.dynamicQuery(
               CourseResultLocalServiceUtil.dynamicQuery()
                   .add(PropertyFactoryUtil.forName("courseId").eq(course.getCourseId()))
                   .add(PropertyFactoryUtil.forName("passedDate").isNull()))) {
     courseResult.setPassedDate(course.getModifiedDate());
     CourseResultLocalServiceUtil.update(courseResult);
   }
 }
コード例 #2
0
  @Override
  public boolean updateCourse(Course course, long userId) throws SystemException {

    CourseResult courseResult =
        CourseResultLocalServiceUtil.getByUserAndCourse(course.getCourseId(), userId);
    // .fetchByuc(mresult.getUserId(), course.getCourseId());
    if (courseResult == null) {
      courseResult = CourseResultLocalServiceUtil.create(course.getCourseId(), userId);
    }

    if (courseResult.getStartDate() == null) {
      courseResult.setStartDate(new Date());
    }

    try {
      java.util.Map<Long, Long> weights = PonderatedCourseEval.getActivitiesWeight(course);
      long score = PonderatedCourseEval.getScore(course);

      boolean passed = true;
      long result = 0;
      long weight = 0;
      List<LearningActivity> learningActivities =
          LearningActivityLocalServiceUtil.getMandatoryLearningActivitiesOfGroup(
              course.getGroupCreatedId());

      // Guardo los resultados de las actividades del usuario en el curso en un hashmap para no
      // tener que acceder a bbdd por cada uno de ellos
      List<LearningActivityResult> lresult =
          LearningActivityResultLocalServiceUtil.getMandatoryByGroupIdUserId(
              course.getGroupCreatedId(), userId);
      HashMap<Long, LearningActivityResult> results = new HashMap<Long, LearningActivityResult>();
      for (LearningActivityResult ar : lresult) {
        results.put(ar.getActId(), ar);
      }

      boolean isFailed = false;
      LearningActivityResult learningActivityResult = null;

      for (LearningActivity act : learningActivities) {

        if (!weights.containsKey(
            act
                .getActId())) { // Solo se tienen en cuenta las actividades obligatorias que tienen
                                // peso definido
          continue;
        }

        if (results.containsKey(act.getActId())) {
          learningActivityResult = results.get(act.getActId());
        } else {
          learningActivityResult = null;
        }

        if (learningActivityResult != null) {
          if (learningActivityResult.getEndDate() != null) {
            if (!learningActivityResult.isPassed()) {
              passed = false;
              if (act.getTries() > 0) {
                long userTries =
                    LearningActivityTryLocalServiceUtil.getLearningActivityTryByActUserCount(
                        act.getActId(), userId);
                if (userTries >= act.getTries()) {
                  isFailed = true;
                }
              }
            }
            result = result + (learningActivityResult.getResult() * weights.get(act.getActId()));

          } else {
            passed = false;
          }
        } else {
          passed = false;
        }
        weight += weights.get(act.getActId());
      }

      if (result > 0 && weight > 0) {
        result = result / weight;
      }

      if (result < score) {
        passed = false;
      }

      // Si el usuario se ha marcado como isFailed es porque lo tiene suspenso. Se le asigna un
      // passed a false y se marca la fecha de finalización del curso (passedDate).
      courseResult.setPassed(passed && !isFailed);
      // Se almacena el result del resultado del usuario en el curso.
      courseResult.setResult(result);
      if ((passed || isFailed) && courseResult.getPassedDate() == null) {
        courseResult.setPassedDate(new Date());
      }
      CourseResultLocalServiceUtil.update(courseResult);
      return true;

    } catch (PortalException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (DocumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return true;
  }