app/models/Comment.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
require_once __DIR__ . '/../../core/BaseModel.php';
class Comment extends BaseModel {
protected $table = 'comments';
protected $fillable = ['post_id', 'user_id', 'parent_id', 'author_name', 'author_email', 'author_url', 'author_ip', 'content', 'status', 'agent'];
public function getApprovedByPost($postId) {
$sql = "SELECT c.*, u.username, u.avatar, u.nickname
FROM {$this->table} c
LEFT JOIN users u ON c.user_id = u.id
WHERE c.post_id = ? AND c.status = 'approved'
ORDER BY c.created_at ASC";
return $this->db->fetchAll($sql, [$postId]);
}
public function getCommentTree($postId) {
$comments = $this->getApprovedByPost($postId);
return $this->buildTree($comments);
}
private function buildTree($comments, $parentId = 0) {
$tree = [];
foreach ($comments as $comment) {
if ($comment['parent_id'] == $parentId) {
$children = $this->buildTree($comments, $comment['id']);
if ($children) {
$comment['children'] = $children;
}
$tree[] = $comment;
}
}
return $tree;
}
public function getRecentComments($limit = 10) {
$sql = "SELECT c.*, p.title as post_title, p.slug as post_slug
FROM {$this->table} c
INNER JOIN posts p ON c.post_id = p.id
WHERE c.status = 'approved'
ORDER BY c.created_at DESC
LIMIT ?";
return $this->db->fetchAll($sql, [$limit]);
}
public function getPendingComments($page = 1, $perPage = PER_PAGE) {
return $this->paginate($page, $perPage, "status = 'pending'", [], 'created_at', 'DESC');
}
public function approve($id) {
return $this->update($id, ['status' => 'approved']);
}
public function markAsSpam($id) {
return $this->update($id, ['status' => 'spam']);
}
public function moveToTrash($id) {
return $this->update($id, ['status' => 'trash']);
}
后面还有 9 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
