use of com.erudika.scoold.core.Post in project scoold by Erudika.
the class SearchController method getFeed.
private SyndFeed getFeed() throws IOException, FeedException {
List<Post> questions = pc.findQuery(Utils.type(Question.class), "*");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
String baseurl = Config.getConfigParam("base_url", "https://scoold.com");
baseurl = baseurl.endsWith("/") ? baseurl : baseurl + "/";
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("atom_1.0");
feed.setTitle("Scoold - Recent questions");
feed.setLink(baseurl);
feed.setDescription("A summary of the most recent questions asked on Scoold.");
for (Post post : questions) {
SyndEntry entry;
SyndContent description;
String baselink = baseurl.concat("question/").concat(post.getId());
entry = new SyndEntryImpl();
entry.setTitle(post.getTitle());
entry.setLink(baselink);
entry.setPublishedDate(new Date(post.getTimestamp()));
entry.setAuthor(baseurl.concat("profile/").concat(post.getCreatorid()));
entry.setUri(baselink.concat("/").concat(Utils.stripAndTrim(post.getTitle()).replaceAll("\\p{Z}+", "-").toLowerCase()));
description = new SyndContentImpl();
description.setType("text/html");
description.setValue(Utils.markdownToHtml(post.getBody()));
entry.setDescription(description);
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
use of com.erudika.scoold.core.Post in project scoold by Erudika.
the class SearchController method get.
@GetMapping({ "/search/{type}/{query}", "/search" })
public String get(@PathVariable(required = false) String type, @PathVariable(required = false) String query, @RequestParam(required = false) String q, HttpServletRequest req, Model model) {
List<Profile> userlist = new ArrayList<Profile>();
List<Post> questionlist = new ArrayList<Post>();
List<Post> answerlist = new ArrayList<Post>();
List<Post> feedbacklist = new ArrayList<Post>();
Pager itemcount = utils.getPager("page", req);
String queryString = StringUtils.isBlank(q) ? query : q;
if ("questions".equals(type)) {
questionlist = pc.findQuery(Utils.type(Question.class), queryString, itemcount);
} else if ("answers".equals(type)) {
answerlist = pc.findQuery(Utils.type(Reply.class), queryString, itemcount);
} else if ("feedback".equals(type)) {
feedbacklist = pc.findQuery(Utils.type(Feedback.class), queryString, itemcount);
} else if ("people".equals(type)) {
userlist = pc.findQuery(Utils.type(Profile.class), queryString, itemcount);
} else {
questionlist = pc.findQuery(Utils.type(Question.class), queryString);
answerlist = pc.findQuery(Utils.type(Reply.class), queryString);
feedbacklist = pc.findQuery(Utils.type(Feedback.class), queryString);
userlist = pc.findQuery(Utils.type(Profile.class), queryString);
}
ArrayList<Post> list = new ArrayList<Post>();
list.addAll(questionlist);
list.addAll(answerlist);
list.addAll(feedbacklist);
utils.fetchProfiles(list);
model.addAttribute("path", "search.vm");
model.addAttribute("title", utils.getLang(req).get("search.title"));
model.addAttribute("searchSelected", "navbtn-hover");
model.addAttribute("showParam", type);
model.addAttribute("searchQuery", queryString);
model.addAttribute("itemcount", itemcount);
model.addAttribute("userlist", userlist);
model.addAttribute("questionlist", questionlist);
model.addAttribute("answerlist", answerlist);
model.addAttribute("feedbacklist", feedbacklist);
return "base";
}
use of com.erudika.scoold.core.Post in project scoold by Erudika.
the class QuestionController method edit.
@PostMapping("/{id}/edit")
public String edit(@PathVariable String id, @RequestParam(required = false) String title, @RequestParam(required = false) String body, @RequestParam(required = false) String tags, HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
Post beforeUpdate = null;
try {
beforeUpdate = (Post) BeanUtils.cloneBean(showPost);
} catch (Exception ex) {
logger.error(null, ex);
}
if (!StringUtils.isBlank(title) && title.length() > 10) {
showPost.setTitle(title);
}
if (!StringUtils.isBlank(body)) {
showPost.setBody(body);
}
if (!StringUtils.isBlank(tags) && showPost.isQuestion()) {
showPost.setTags(Arrays.asList(StringUtils.split(tags, ",")));
}
showPost.setLasteditby(authUser.getId());
//note: update only happens if something has changed
if (!showPost.equals(beforeUpdate)) {
showPost.update();
utils.addBadgeOnceAndUpdate(authUser, Badge.EDITOR, true);
}
return "redirect:" + showPost.getPostLink(false, false);
}
use of com.erudika.scoold.core.Post in project scoold by Erudika.
the class CommentController method createAjax.
@PostMapping
public String createAjax(@RequestParam String comment, @RequestParam String parentid, HttpServletRequest req, Model model) {
Profile authUser = utils.getAuthUser(req);
if (utils.canComment(authUser, req) && !StringUtils.isBlank(comment) && !StringUtils.isBlank(parentid)) {
Comment showComment = utils.populate(req, new Comment(), "comment");
showComment.setCreatorid(authUser.getId());
Map<String, String> error = utils.validate(showComment);
if (error.isEmpty()) {
showComment.setComment(comment);
showComment.setParentid(parentid);
showComment.setAuthorName(authUser.getName());
if (showComment.create() != null) {
long commentCount = authUser.getComments();
utils.addBadgeOnce(authUser, COMMENTATOR, commentCount >= COMMENTATOR_IFHAS);
authUser.setComments(commentCount + 1);
authUser.update();
model.addAttribute("showComment", showComment);
// send email to the author of parent post
Post parentPost = pc.read(parentid);
if (parentPost != null) {
parentPost.addCommentId(showComment.getId());
parentPost.update();
}
sendCommentNotification(parentPost, showComment, authUser);
}
}
}
return "comment";
}
use of com.erudika.scoold.core.Post in project scoold by Erudika.
the class CommentController method getAjax.
@GetMapping(params = { Config._PARENTID, "getcomments" })
public String getAjax(@RequestParam String parentid, @RequestParam Boolean getcomments, @RequestParam(required = false, defaultValue = "1") Integer page, HttpServletRequest req, Model model) {
Post parent = pc.read(parentid);
if (parent != null) {
parent.getItemcount().setPage(page);
List<Comment> commentslist = pc.getChildren(parent, Utils.type(Comment.class), parent.getItemcount());
parent.setComments(commentslist);
model.addAttribute("showpost", parent);
model.addAttribute("itemcount", parent.getItemcount());
}
return "comment";
}
Aggregations