diff --git a/module/api/control.php b/module/api/control.php index 754eb1f2d5..47f9ff8373 100755 --- a/module/api/control.php +++ b/module/api/control.php @@ -237,7 +237,7 @@ class api extends control if($releaseID) { $release = $this->api->getRelease($libID, 'byID', $releaseID); - $structs = $this->api->getStructListByRelease($release, '1 = 1 ', $sort); + $structs = $this->api->getStructListByRelease($release, '1 = 1 ', $pager, $sort); } else { @@ -498,7 +498,7 @@ class api extends control */ public function edit(int $apiID) { - $api = $this->api->getLibByID($apiID); + $api = $this->api->getByID($apiID); if(!empty($_POST)) { $formData = form::data($this->config->api->form->edit)->add('id', $apiID)->add('version', $api->version)->add('editedBy', $this->app->user->account)->get(); diff --git a/module/api/model.php b/module/api/model.php index 8e8f207f74..cbb5285d0b 100644 --- a/module/api/model.php +++ b/module/api/model.php @@ -395,6 +395,7 @@ class apiModel extends model $where = "1 = 1 and lib = $libID "; if($moduleID > 0 && isset($release->snap['modules'])) { + /* 根据发布中的modules生成查询条件。 */ $sub = array(); foreach($release->snap['modules'] as $module) { @@ -407,6 +408,7 @@ class apiModel extends model } else { + /* 根据模块ID获取发布信息。 */ if($moduleID > 0) { $sub = $this->dao->select('id')->from(TABLE_MODULE)->where('FIND_IN_SET(' . $moduleID . ', path)')->processSQL(); @@ -414,6 +416,7 @@ class apiModel extends model } else { + /* 没有模块ID的根据libID来获取发布信息。 */ $where = 'lib = ' . $libID; } $apiList = $this->dao->select('*')->from(TABLE_API)->where($where)->andWhere('deleted')->eq(0)->page($pager)->fetchAll(); @@ -438,6 +441,7 @@ class apiModel extends model public static function getApiStatusText(string $status): string { global $lang; + switch($status) { case static::STATUS_DOING: @@ -453,13 +457,16 @@ class apiModel extends model } /** - * @param int $libID - * @param string $pager - * @param string $orderBy + * 获取指定文档库下的数据结构列表。 + * Get struct list by lib id. + * + * @param int $libID + * @param object $pager + * @param string $orderBy * @access public * @return array */ - public function getStructByQuery($libID, $pager = '', $orderBy = '') + public function getStructByQuery(int $libID, object $pager = null, string $orderBy = ''): array { return $this->dao->select('t1.*,t2.realname as addedName')->from(TABLE_APISTRUCT)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t2.account = t1.addedBy') @@ -475,29 +482,32 @@ class apiModel extends model * * @param object $release * @param string $where + * @param object $pager * @param string $orderBy * @access public * @return array */ - public function getStructListByRelease($release, $where = '1 = 1 ', $orderBy = 'id') + public function getStructListByRelease(object $release, string $where = '1 = 1 ', $pager = null, string $orderBy = 'id'): array { $strJoin = array(); if(isset($release->snap['structs'])) { + /* 根据发布中的structs生成查询条件。 */ foreach($release->snap['structs'] as $struct) { $strJoin[] = "(object.id = {$struct['id']} and spec.version = {$struct['version']} )"; } } - if($strJoin) $where .= 'and (' . implode(' or ', $strJoin) . ')'; - $list = $this->dao->select('object.lib,spec.name,spec.type,spec.desc,spec.attribute,spec.version,spec.addedBy,spec.addedDate,object.id,user.realname as addedName')->from(TABLE_APISTRUCT)->alias('object') + + return $this->dao->select('object.id,object.lib,spec.name,spec.type,spec.desc,spec.attribute,spec.version,spec.addedBy,spec.addedDate,user.realname as addedName') + ->from(TABLE_APISTRUCT)->alias('object') ->leftJoin(TABLE_APISTRUCT_SPEC)->alias('spec')->on('object.name = spec.name') ->leftJoin(TABLE_USER)->alias('user')->on('user.account = spec.addedBy') ->where($where) ->orderBy($orderBy) + ->page($pager) ->fetchAll(); - return $list; } /** diff --git a/module/api/test/model/getstructbyquery.php b/module/api/test/model/getstructbyquery.php new file mode 100755 index 0000000000..b1640d0dcb --- /dev/null +++ b/module/api/test/model/getstructbyquery.php @@ -0,0 +1,29 @@ +#!/usr/bin/env php +gen(10); + +/** + +title=测试 apiModel->getStructByQuery(); +timeout=0 +cid=1 + +- 获取文档目录ID为1的数据结构列表。 + - 第0条的id属性 @1 + - 第0条的name属性 @数据接口1 + - 第0条的type属性 @formData +- 获取文档目录ID为2的数据结构列表。 + - 第0条的id属性 @2 + - 第0条的name属性 @数据接口2 + - 第0条的type属性 @json + +*/ + +global $tester; +$tester->loadModel('api'); + +r($tester->api->getStructByQuery(1)) && p('0:id,name,type') && e('1,数据接口1,formData'); //获取文档目录ID为1的数据结构列表。 +r($tester->api->getStructByQuery(2)) && p('0:id,name,type') && e('2,数据接口2,json'); //获取文档目录ID为2的数据结构列表。 diff --git a/module/api/ui/index.html.php b/module/api/ui/index.html.php index bd907312fe..945709aa4b 100644 --- a/module/api/ui/index.html.php +++ b/module/api/ui/index.html.php @@ -82,7 +82,7 @@ foreach($apiList as $api) setClass("heading {$api->method}"), a ( - set::href(createLink('api', 'index', "libID={$api->lib}&moduleID=0&apiID={$api->id}&version=0")), + set::href(createLink('api', 'index', "libID={$api->lib}&moduleID=0&apiID={$api->id}&version={$api->version}")), span ( setClass('method'), diff --git a/module/api/ui/view.html.php b/module/api/ui/view.html.php index 2ba4b62cb5..419f5c3503 100644 --- a/module/api/ui/view.html.php +++ b/module/api/ui/view.html.php @@ -48,7 +48,7 @@ $parseTree = function($data, $typeList, $level = 0) use(&$parseTree) return $tbody; }; -if($api->params['header']) +if(!empty($api->params['header'])) { $tbody = array(); foreach($api->params['header'] as $param) @@ -77,7 +77,7 @@ if($api->params['header']) ); } -if($api->params['query']) +if(!empty($api->params['query'])) { $tbody = array(); foreach($api->params['query'] as $param) @@ -106,7 +106,7 @@ if($api->params['query']) ); } -if($api->params['params']) +if(!empty($api->params['params'])) { $tbody = array(); foreach($api->params['params'] as $param) $tbody = array_merge($tbody, $parseTree($param, $typeList));