Search in sources :

Example 6 with Post

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;
}
Also used : Post(com.erudika.scoold.core.Post) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) Question(com.erudika.scoold.core.Question) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl)

Example 7 with Post

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";
}
Also used : Feedback(com.erudika.scoold.core.Feedback) Post(com.erudika.scoold.core.Post) Pager(com.erudika.para.utils.Pager) ArrayList(java.util.ArrayList) Reply(com.erudika.scoold.core.Reply) Question(com.erudika.scoold.core.Question) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with Post

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);
}
Also used : Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) IOException(java.io.IOException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 9 with Post

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";
}
Also used : Comment(com.erudika.scoold.core.Comment) Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 10 with Post

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";
}
Also used : Comment(com.erudika.scoold.core.Comment) Post(com.erudika.scoold.core.Post) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Post (com.erudika.scoold.core.Post)20 Profile (com.erudika.scoold.core.Profile)12 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 Pager (com.erudika.para.utils.Pager)6 Reply (com.erudika.scoold.core.Reply)5 Comment (com.erudika.scoold.core.Comment)4 Feedback (com.erudika.scoold.core.Feedback)4 ArrayList (java.util.ArrayList)4 ParaObject (com.erudika.para.core.ParaObject)3 Question (com.erudika.scoold.core.Question)3 HashMap (java.util.HashMap)3 Revision (com.erudika.scoold.core.Revision)2 LinkedList (java.util.LinkedList)2 Report (com.erudika.scoold.core.Report)1 SyndContent (com.sun.syndication.feed.synd.SyndContent)1 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1