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