Search in sources :

Example 11 with Question

use of com.erudika.scoold.core.Question in project scoold by Erudika.

the class ProfileController method getQuestions.

public List<? extends Post> getQuestions(Profile authUser, Profile showUser, boolean isMyProfile, Pager itemcount) {
    if (utils.postsNeedApproval() && (isMyProfile || utils.isMod(authUser))) {
        List<Question> qlist = new ArrayList<>();
        Pager p = new Pager(itemcount.getPage(), itemcount.getLimit());
        qlist.addAll(showUser.getAllQuestions(itemcount));
        qlist.addAll(showUser.getAllUnapprovedQuestions(p));
        itemcount.setCount(itemcount.getCount() + p.getCount());
        return qlist;
    } else {
        return showUser.getAllQuestions(itemcount);
    }
}
Also used : Pager(com.erudika.para.core.utils.Pager) ArrayList(java.util.ArrayList) Question(com.erudika.scoold.core.Question)

Example 12 with Question

use of com.erudika.scoold.core.Question in project scoold by Erudika.

the class QuestionsController method getTagged.

@GetMapping("/questions/tag/{tag}")
public String getTagged(@PathVariable String tag, HttpServletRequest req, Model model) {
    if (!utils.isDefaultSpacePublic() && !utils.isAuthenticated(req)) {
        return "redirect:" + SIGNINLINK + "?returnto=" + req.getRequestURI();
    }
    Pager itemcount = utils.getPager("page", req);
    List<Question> questionslist = Collections.emptyList();
    String type = Utils.type(Question.class);
    String qf = utils.getSpaceFilteredQuery(req);
    if (!qf.isEmpty()) {
        if (qf.equals("*")) {
            questionslist = pc.findTagged(type, new String[] { tag }, itemcount);
        } else {
            questionslist = pc.findQuery(type, qf + " AND " + Config._TAGS + ":" + tag + "*", itemcount);
        }
    }
    int c = (int) itemcount.getCount();
    Tag t = pc.read(new Tag(tag).getId());
    if (t != null && t.getCount() != c && utils.isMod(utils.getAuthUser(req))) {
        t.setCount(c);
        pc.update(t);
    }
    utils.fetchProfiles(questionslist);
    model.addAttribute("path", "questions.vm");
    model.addAttribute("title", utils.getLang(req).get("posts.tagged") + " - " + tag);
    model.addAttribute("questionsSelected", "navbtn-hover");
    model.addAttribute("tag", tag);
    model.addAttribute("itemcount", itemcount);
    model.addAttribute("questionslist", questionslist);
    return "base";
}
Also used : Pager(com.erudika.para.core.utils.Pager) Question(com.erudika.scoold.core.Question) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Tag(com.erudika.para.core.Tag) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 13 with Question

use of com.erudika.scoold.core.Question in project scoold by Erudika.

the class QuestionsController method getSimilarAjax.

@GetMapping("/questions/similar/{like}")
public void getSimilarAjax(@PathVariable String like, HttpServletRequest req, HttpServletResponse res) throws IOException {
    if (!utils.isDefaultSpacePublic() && !utils.isAuthenticated(req)) {
        res.setStatus(401);
        return;
    }
    Pager pager = new Pager(1, "votes", true, Config.getConfigInt("max_similar_posts", 7));
    Profile authUser = utils.getAuthUser(req);
    StringBuilder sb = new StringBuilder();
    Question q = new Question();
    q.setTitle(like);
    q.setBody("");
    q.setTags(Arrays.asList(""));
    for (Post similarPost : utils.getSimilarPosts(q, pager)) {
        if (utils.isMod(authUser) || utils.canAccessSpace(authUser, similarPost.getSpace())) {
            boolean hasAnswer = !StringUtils.isBlank(similarPost.getAnswerid());
            sb.append("<span class=\"lightborder phm").append(hasAnswer ? " light-green white-text" : "").append("\">");
            sb.append(similarPost.getVotes());
            sb.append("</span> <a href=\"").append(similarPost.getPostLink(false, false)).append("\">");
            sb.append(HtmlUtils.htmlEscape(similarPost.getTitle())).append("</a><br>");
        }
    }
    res.setCharacterEncoding("UTF-8");
    res.getWriter().print(sb.toString());
    res.setStatus(200);
}
Also used : Post(com.erudika.scoold.core.Post) Pager(com.erudika.para.core.utils.Pager) Question(com.erudika.scoold.core.Question) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Question (com.erudika.scoold.core.Question)13 Pager (com.erudika.para.core.utils.Pager)9 Profile (com.erudika.scoold.core.Profile)9 UnapprovedQuestion (com.erudika.scoold.core.UnapprovedQuestion)7 Tag (com.erudika.para.core.Tag)6 Post (com.erudika.scoold.core.Post)6 IOException (java.io.IOException)6 ParaClient (com.erudika.para.client.ParaClient)5 Config (com.erudika.para.core.utils.Config)5 Utils (com.erudika.para.core.utils.Utils)5 Collections (java.util.Collections)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Address (com.erudika.para.core.Address)4 ParaObject (com.erudika.para.core.ParaObject)4 ArrayList (java.util.ArrayList)4