57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ywxapp<admin@ywxapp.cn>
|
|
// +----------------------------------------------------------------------
|
|
declare (strict_types = 1);
|
|
|
|
namespace addon\docs\controller;
|
|
|
|
use addon\docs\model\DocsDoc;
|
|
use addon\docs\model\DocsProject;
|
|
use addon\docs\model\DocsVersion;
|
|
|
|
/**
|
|
* 文档中心首页:项目卡片墙
|
|
*
|
|
* @author ywxapp <admin@ywxapp.cn>
|
|
*/
|
|
class Index extends DocsFrontend
|
|
{
|
|
/**
|
|
* 首页
|
|
*/
|
|
public function index()
|
|
{
|
|
$projects = DocsProject::enabledList()->toArray();
|
|
|
|
foreach ($projects as &$project) {
|
|
$projectId = (int) $project['id'];
|
|
|
|
$project['doc_count'] = DocsDoc::where('project_id', $projectId)
|
|
->where('status', 1)->where('is_dir', 0)->count();
|
|
|
|
$version = DocsVersion::resolve($projectId, (string) ($project['default_version'] ?? ''));
|
|
$project['version_name'] = $version ? $version->name : '';
|
|
|
|
// 取该项目最近更新的几篇,作为卡片上的快捷入口
|
|
$project['recent'] = DocsDoc::field('id,name,title,update_at')
|
|
->where('project_id', $projectId)
|
|
->where('status', 1)
|
|
->where('is_dir', 0)
|
|
->order('update_at', 'desc')
|
|
->limit(4)
|
|
->select()
|
|
->toArray();
|
|
}
|
|
unset($project);
|
|
|
|
$this->assign('projects', $projects);
|
|
$this->assign('totalDocs', DocsDoc::where('status', 1)->where('is_dir', 0)->count());
|
|
return $this->fetch('index/index');
|
|
}
|
|
}
|