super-forum 获取评论楼层


发表于:7 月前 | {{user.city}}

super-forum 获取评论楼层

代码:

<?php

if(!function_exists("get_topic_comment_floor")){
	/**
	 * 获取评论楼层
	 * @param  int $comment_id
	 * @return  int
	 */
	function get_topic_comment_floor(int $comment_id): ?int
	{
		$floor = null;
		if(!\App\Plugins\Comment\src\Model\TopicComment::query()->where('id',$comment_id)->exists()){
			$floor = null;
		}
		// 所在帖子ID
		$topic_id = \App\Plugins\Comment\src\Model\TopicComment::query()->where('id',$comment_id)->value('topic_id');
		// 每页加载的评论数量
		$comment_num = get_options("comment_page_count",15);
		$comment_page = get_topic_comment_page($comment_id);
		// ($key + 1)+(($comment->currentPage()-1)*get_options('comment_page_count',15))
		$page = TopicComment::query()
			->where(['topic_id' => $topic_id,'status' => 'publish'])
			->paginate($comment_num,['*'],'page',$comment_page);
		foreach($page as $k => $v){
			if((int)$v->id===$comment_id){
				$floor = ($k + 1)+(($comment_page-1)*get_options('comment_page_count',15));
			}
		}
		return $floor;
	}
}
评论

zhuchunshu 共 14 位粉丝

开发 暂无描述
查看此标签