app/models/Page.php

(完整代码) 1KB

<?php
require_once __DIR__ . '/../../core/BaseModel.php';

class Page extends BaseModel {
    protected $table = 'pages';
    protected $fillable = ['title', 'slug', 'content', 'user_id', 'status', 'sort_order'];
    
    public function getPublished($page = 1, $perPage = PER_PAGE) {
        return $this->paginate($page, $perPage, "status = 'published'", [], 'sort_order ASC, created_at', 'DESC');
    }
    
    public function getAllPages() {
        $sql = "SELECT p.*, u.username as author_name, u.nickname as author_nickname
                FROM {$this->table} p
                LEFT JOIN users u ON p.user_id = u.id
                ORDER BY p.sort_order ASC, p.created_at DESC";
        return $this->db->fetchAll($sql);
    }
    
    public function getPageWithAuthor($id) {
        $sql = "SELECT p.*, u.username as author_name, u.nickname as author_nickname
                FROM {$this->table} p
                LEFT JOIN users u ON p.user_id = u.id
                WHERE p.id = ?";
        return $this->db->fetchOne($sql, [$id]);
    }
    
    public function getPageBySlug($slug) {
        $sql = "SELECT p.*, u.username as author_name, u.nickname as author_nickname
                FROM {$this->table} p
                LEFT JOIN users u ON p.user_id = u.id
                WHERE p.slug = ? AND p.status = 'published'";
        return $this->db->fetchOne($sql, [$slug]);
    }
    
    public function getPublishedPages() {
        $sql = "SELECT id, title, slug, sort_order 
                FROM {$this->table} 
                WHERE status = 'published' 
                ORDER BY sort_order ASC, created_at DESC";
        return $this->db->fetchAll($sql);
    }
    
    public function countByStatus($status) {
        return $this->count("status = ?", [$status]);
    }
    
    public function moveToTrash($id) {
        return $this->update($id, ['status' => 'trash']);
    }
    
    public function restore($id) {
        return $this->update($id, ['status' => 'draft']);
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。