super-forum 获取评论楼层

发表:2年前 更新:1年前

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;
	}
}
signature
保持理智
评论

无权限

请登录后评论

RunPod公众号

赞助商

联系我们

QQ群:798695907

邮箱:laravel@88.com