Ejemplo n.º 1
0
  /** @return */
  public String listHighestGameScores(String contentId, int count, User u) {
    u = checkUser(u);

    Element root = new Element("scores");
    root.setAttribute("content-id", contentId);

    List<ContentLog> list = contentLogDao.queryForHighest(contentId, count);
    list.addAll(contentLogDao.queryForUserLast(contentId, u.getUserId(), 1));
    int userOrder = contentLogDao.queryForOrder(list.get(list.size() - 1).getContentLogId());
    for (int i = 0; i < list.size(); i++) {
      Element e = new Element("user");
      if (i != list.size() - 1) {
        e.setAttribute("pm", String.valueOf(i + 1));
      } else {
        e.setAttribute("pm", String.valueOf(userOrder));
      }
      e.setAttribute("nc", list.get(i).getUserName());
      e.setAttribute("fs", String.valueOf(list.get(i).getScore()));
      root.addContent(e);
    }

    Document doc = new Document();
    doc.setRootElement(root);

    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());

    return outputter.outputString(doc);
  }
Ejemplo n.º 2
0
  /** Set a content log. */
  public void setLog(
      String contentId, int duration, int score, User user, ContentLogContentType contenttype) {
    user = checkUser(user);
    ContentLog cl = new ContentLog();
    ContentLog old = contentLogDao.queryLastLog(contentId, user.getUserId());
    if (old == null) {
      cl.setType(ContentLogType.FINISH);
    } else {
      cl.setType(ContentLogType.REVIEW);
    }

    cl.setContentId(contentId);
    cl.setContentType(contenttype);
    cl.setDuration(duration);
    cl.setEnterTime(new Date(DateUtils.getDatabaseDate().getTime() - duration));
    cl.setLeaveTime(DateUtils.getDatabaseDate());
    cl.setLessonId(-1);
    cl.setLogKey("NOT USING");
    cl.setScore(score);
    cl.setTag1("NOT USING");
    cl.setTag2("NOT USING");
    cl.setUserId(user.getUserId());
    cl.setUserName(user.getUserName());
    contentLogDao.saveContentLog(cl);
  }