/** 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); }
private User checkUser(User u) { if (u == null) { u = new User(); u.setUserName("Guest"); u.setUserId(-1); return u; } else { return u; } }
public boolean isPrepareTeamMember(User u) { if (u != null) { return PrepareTeamMateDao.isPrepareTeamMemberByUser(u.getUserId()) > 0; } else { return false; } }
/** Check whether current user is a school manager. */ public boolean isSchoolManager(User u) { if (u != null) { return schoolManagerDao.getSchoolManager(u.getUserId()) != null; } else { return false; } }
/** Get unread mail count. */ public int getUnreadMailCount(User u) { if (u != null) { return mailDao.getUnreadMailCount(u.getUserId()); } else { return 0; } }
/** Check whether the user is in QUESTION_ADMIN role. */ public boolean checkUserQuestionAdmin(User u) { if (u != null) { return userRoleDao.isUserInRole(u.getUserId(), "QUESTION_ADMIN"); } else { return false; } }
/** Check whether the user is in SYSETM_ADMIN role. */ public boolean checkUserAdmin(User u) { if (u != null) { return userRoleDao.isUserInRole(u.getUserId(), "SYSTEM_ADMIN"); } else { return false; } }
/** Returns number of requests from other users. */ public int getFriendRequestCount(User u) { if (u != null) { return userFriendDao.listToApproveFriends(u.getUserId()).size(); } else { return 0; } }
/** Returns number of invitations from group managers. */ public int getGroupInvitationCount(User u) { if (u != null) { return userGroupDao.getInvitationCount(u.getUserId()); } else { return 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); }