2019-08-18 15:51:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models;
|
2020-07-12 14:59:15 +00:00
|
|
|
use Parsedown;
|
|
|
|
|
2019-08-18 15:51:59 +00:00
|
|
|
class Doc extends \Core\Controller
|
|
|
|
{
|
2020-07-12 07:59:34 +00:00
|
|
|
function docTypeAction()
|
|
|
|
{
|
2019-08-18 15:51:59 +00:00
|
|
|
$docModel = new Models\Doc();
|
|
|
|
$types = $docModel->getTypes();
|
2020-07-12 07:59:34 +00:00
|
|
|
$type = json_encode($types, JSON_FORCE_OBJECT);
|
|
|
|
$this->JsonResp(200, $type, "ok");
|
2019-08-18 15:51:59 +00:00
|
|
|
}
|
2020-07-12 07:59:34 +00:00
|
|
|
|
|
|
|
public function docsAction()
|
|
|
|
{
|
|
|
|
if (isset($this->input->id)) {
|
2019-08-23 09:16:40 +00:00
|
|
|
$docs = new Models\Doc();
|
|
|
|
$ret = $docs->docs($this->input->id);
|
2020-07-12 07:59:34 +00:00
|
|
|
$this->JsonResp(200, $ret, "OK");
|
|
|
|
} else {
|
|
|
|
$this->JsonResp(200, null, "error");
|
2019-08-23 09:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-12 07:59:34 +00:00
|
|
|
|
|
|
|
public function docAction()
|
|
|
|
{
|
|
|
|
if (isset($this->input->id)) {
|
2019-08-25 16:49:16 +00:00
|
|
|
$docs = new Models\Doc();
|
|
|
|
$ret = $docs->doc($this->input->id);
|
2020-07-12 07:59:34 +00:00
|
|
|
$this->JsonResp(200, $ret, "OK");
|
|
|
|
} else {
|
|
|
|
$this->JsonResp(200, null, "error");
|
2019-08-25 16:49:16 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-12 07:59:34 +00:00
|
|
|
|
|
|
|
public function docTitleAction()
|
|
|
|
{
|
2020-06-17 06:51:50 +00:00
|
|
|
$docs = new Models\Doc();
|
|
|
|
$ret = $docs->AllTitle();
|
2020-07-12 07:59:34 +00:00
|
|
|
$this->JsonResp(200, $ret, "OK");
|
2020-06-17 06:51:50 +00:00
|
|
|
}
|
2020-07-12 07:59:34 +00:00
|
|
|
|
|
|
|
public function countAction()
|
|
|
|
{
|
|
|
|
$docs = new Models\Doc();
|
|
|
|
$ret = $docs->Count();
|
|
|
|
$this->JsonResp(200, $ret, "OK");
|
2020-02-23 14:59:08 +00:00
|
|
|
}
|
2020-07-12 07:59:34 +00:00
|
|
|
|
2020-06-17 05:17:15 +00:00
|
|
|
// 查找文件名字
|
2020-07-12 07:59:34 +00:00
|
|
|
function articleSearchAction()
|
|
|
|
{
|
|
|
|
if (isset($this->input->title)) {
|
2020-06-17 05:17:15 +00:00
|
|
|
$docModel = new Models\Doc();
|
|
|
|
$titles = $docModel->titleLikeDoc($this->input->title);
|
2020-07-12 07:59:34 +00:00
|
|
|
$this->JsonResp(0, $titles, "OK");
|
|
|
|
} else {
|
2020-07-12 14:59:15 +00:00
|
|
|
$this->JsonResp(200, null, "OK");
|
2020-07-12 07:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function typedocAction()
|
|
|
|
{
|
|
|
|
$limit = 5;
|
|
|
|
$type = 0;
|
|
|
|
$offset = 0;
|
2020-07-12 14:59:15 +00:00
|
|
|
if (sizeof($this->params) == 3) {
|
2020-07-12 07:59:34 +00:00
|
|
|
$limit = $this->params[0];
|
|
|
|
$offset = $this->params[1];
|
2020-07-12 15:57:38 +00:00
|
|
|
$type = $this->params[2];
|
2020-06-17 05:17:15 +00:00
|
|
|
}
|
2020-07-12 07:59:34 +00:00
|
|
|
$docModel = new Models\Doc();
|
|
|
|
$typedoc = $docModel->pageDoc($limit, $offset, $type);
|
2020-07-12 14:59:15 +00:00
|
|
|
$ret = [];
|
|
|
|
foreach ($typedoc as $key => $value) {
|
|
|
|
$obj['title'] = $value['title'];
|
|
|
|
$obj['id'] = $value['id'];
|
|
|
|
$obj['content'] = $value['content'];
|
|
|
|
$obj['type'] = $value['type'];
|
|
|
|
//数据加工
|
|
|
|
$markdown = new Parsedown;
|
|
|
|
$content = $markdown->text($value['content']);
|
|
|
|
$obj['content'] = $content;
|
|
|
|
array_push($ret,$obj);
|
|
|
|
}
|
|
|
|
$this->JsonResp(200, $ret, "OK");
|
2020-07-12 07:59:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function typeCountAction()
|
|
|
|
{
|
|
|
|
$type = $this->params[0];
|
|
|
|
$docModel = new Models\Doc();
|
|
|
|
$count = $docModel->typeCounts($type);
|
2020-07-12 14:59:15 +00:00
|
|
|
$this->JsonResp(200, $count, "OK");
|
2020-06-17 05:17:15 +00:00
|
|
|
}
|
2019-08-18 15:51:59 +00:00
|
|
|
}
|