Example #1
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    UsersComponent usersComponent = new UsersComponent();
    User currentUser = usersComponent.getCurrentUser(request);

    if (!usersComponent.isCurrentUser(currentUser)) {
      response.sendRedirect(Constants.LOGIN_SERVLET);
    } else {
      /** User group */
      SQLGroupComponent sqlGroupComponent = new SQLGroupComponent();
      Map<Long, Map<String, String>> groups = sqlGroupComponent.getGroups(currentUser.getId());
      request.setAttribute("groups", groups);

      Long idGroup = null;
      if (request.getParameter("group") != null && !request.getParameter("group").equals("all")) {
        idGroup = Long.parseLong((request.getParameter("group")));
        request.setAttribute("currentGroupId", idGroup);
      }

      int index = 1;
      int indexFound = 0;
      for (Long id : groups.keySet()) {
        if (id == idGroup) {
          indexFound = index;
        }
        index++;
      }

      if (indexFound == 0) {
        request.setAttribute("currentGroupIndex", "general");
        request.setAttribute("currentGroupId", "-1");
      } else {
        request.setAttribute("currentGroupIndex", String.valueOf(indexFound - 1));
      }

      /** User info */
      SQLUsersComponent sqlUserComponent = new SQLUsersComponent();
      User user = sqlUserComponent.getUser(currentUser.getId());
      request.setAttribute("userPoint", user.getCoins());
      request.setAttribute("userRank", user.getRank());

      int rankUser = user.getRank();
      int pageNumber = 1;
      if (rankUser % nbUserByPage == 0) {
        pageNumber = rankUser / nbUserByPage;
      } else {
        pageNumber = (int) (Math.floor(rankUser / nbUserByPage) + 1);
      }

      /** Classement */
      setRankRequest(request, currentUser, idGroup, pageNumber, nbUserByPage);

      this.getServletContext()
          .getRequestDispatcher("/WEB-INF/jsp/rank.jsp")
          .forward(request, response);
    }
  }
Example #2
0
  protected void setRankRequest(
      HttpServletRequest request, User currentUser, Long groupId, int page, int nbUser) {
    if (groupId == null) {
      request.setAttribute("groupName", "General");
    } else {
      SQLGroupComponent sqlGroupComponent = new SQLGroupComponent();
      request.setAttribute("groupName", sqlGroupComponent.getGroup(groupId).getName());
    }

    RankComponent rankComponent = new RankComponent();
    Map<String, Map<String, String>> rank =
        rankComponent.getRank(groupId, currentUser.getUsername(), page, nbUser);
    request.setAttribute("rank", rank);
    request.setAttribute("page", page);

    int totalUser = rankComponent.getSize(groupId);
    int nbPage = (int) Math.round(Math.ceil((float) totalUser / nbUser));
    request.setAttribute("totalUser", totalUser);
    request.setAttribute("totalPage", nbPage);
    request.setAttribute("pagination", getPagination(page, nbPage));
  }