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);
}
}
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";
}
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);
}
Aggregations