Search in sources :

Example 1 with Paginator

use of com.blade.jdbc.model.Paginator in project tale by otale.

the class Theme method comments.

/**
     * 获取当前文章/页面的评论
     * @param limit
     * @return
     */
public static Paginator<Comment> comments(int limit) {
    Contents contents = current_article();
    if (null == contents) {
        return new Paginator<>(0, limit);
    }
    InterpretContext ctx = InterpretContext.current();
    Object value = ctx.getValueStack().getValue("cp");
    int page = 1;
    if (null != value) {
        page = (int) value;
    }
    return siteService.getComments(contents.getCid(), page, limit);
}
Also used : Contents(com.tale.model.Contents) InterpretContext(jetbrick.template.runtime.InterpretContext) Paginator(com.blade.jdbc.model.Paginator)

Example 2 with Paginator

use of com.blade.jdbc.model.Paginator in project tale by otale.

the class ContentsServiceImpl method getArticles.

@Override
public Paginator<Contents> getArticles(Integer mid, int page, int limit) {
    String countSql = "select count(0) from t_contents a left join t_relationships b on a.cid = b.cid " + "where b.mid = ? and a.status = 'publish' and a.type = 'post'";
    int total = activeRecord.one(Integer.class, countSql, mid);
    PageRow pageRow = new PageRow(page, limit);
    Paginator<Contents> paginator = new Paginator<>(total, pageRow.getPage(), pageRow.getLimit());
    String sql = "select a.* from t_contents a left join t_relationships b on a.cid = b.cid " + "where b.mid = ? and a.status = 'publish' and a.type = 'post' order by a.created desc limit " + pageRow.getOffSet() + "," + limit;
    List<Contents> list = activeRecord.list(Contents.class, sql, mid);
    if (null != list) {
        paginator.setList(list);
    }
    return paginator;
}
Also used : Contents(com.tale.model.Contents) PageRow(com.blade.jdbc.model.PageRow) Paginator(com.blade.jdbc.model.Paginator)

Example 3 with Paginator

use of com.blade.jdbc.model.Paginator in project tale by otale.

the class CommentsServiceImpl method getComments.

@Override
public Paginator<Comment> getComments(Integer cid, int page, int limit) {
    if (null != cid) {
        Take take = new Take(Comments.class);
        take.eq("cid", cid).eq("parent", 0);
        take.page(page, limit, "coid desc");
        Paginator<Comments> cp = activeRecord.page(take);
        Paginator<Comment> commentPaginator = new Paginator<>(cp.getTotal(), page, limit);
        if (null != cp.getList()) {
            List<Comments> parents = cp.getList();
            List<Comment> comments = new ArrayList<>(parents.size());
            parents.forEach(parent -> {
                Comment comment = new Comment(parent);
                List<Comments> children = new ArrayList<>();
                getChildren(children, comment.getCoid());
                comment.setChildren(children);
                if (CollectionKit.isNotEmpty(children)) {
                    comment.setLevels(1);
                }
                comments.add(comment);
            });
            commentPaginator.setList(comments);
        }
        return commentPaginator;
    }
    return null;
}
Also used : Take(com.blade.jdbc.core.Take) Comment(com.tale.dto.Comment) Comments(com.tale.model.Comments) ArrayList(java.util.ArrayList) Paginator(com.blade.jdbc.model.Paginator)

Aggregations

Paginator (com.blade.jdbc.model.Paginator)3 Contents (com.tale.model.Contents)2 Take (com.blade.jdbc.core.Take)1 PageRow (com.blade.jdbc.model.PageRow)1 Comment (com.tale.dto.Comment)1 Comments (com.tale.model.Comments)1 ArrayList (java.util.ArrayList)1 InterpretContext (jetbrick.template.runtime.InterpretContext)1