From adcb36c393ee61b11453aec5cd14ede5b2e85a98 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Thu, 23 Sep 2021 10:31:52 +0800 Subject: [PATCH] * Adjust code style. --- db/update15.5.sql | 164 +++++++++++++++++---------------- module/api/control.php | 108 +++++++++------------- module/api/view/index.html.php | 142 ++++++++++++++-------------- module/doc/model.php | 11 +-- 4 files changed, 202 insertions(+), 223 deletions(-) diff --git a/db/update15.5.sql b/db/update15.5.sql index ae9e11ef01..13f0c51c76 100644 --- a/db/update15.5.sql +++ b/db/update15.5.sql @@ -1,97 +1,101 @@ -ALTER TABLE `zt_doclib` - ADD COLUMN `desc` text NULL AFTER `collector`; +ALTER TABLE `zt_doclib` ADD COLUMN `desc` text NULL AFTER `collector`; +-- DROP TABLE IF EXISTS `zt_api_lib_release`; CREATE TABLE `zt_api_lib_release` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `doclib` int UNSIGNED NOT NULL DEFAULT 0, - `version` varchar(255) NOT NULL DEFAULT '', - `snap` mediumtext NOT NULL, - `addedBy` varchar(30) NOT NULL DEFAULT 0, - `addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - PRIMARY KEY (`id`) -) + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `doclib` int UNSIGNED NOT NULL DEFAULT 0, + `version` varchar(255) NOT NULL DEFAULT '', + `snap` mediumtext NOT NULL, + `addedBy` varchar(30) NOT NULL DEFAULT 0, + `addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`id`) +); +-- DROP TABLE IF EXISTS `zt_api`; CREATE TABLE `zt_api` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `product` varchar(255) NOT NULL DEFAULT '', - `lib` int UNSIGNED NOT NULL DEFAULT 0, - `module` int UNSIGNED NOT NULL DEFAULT 0, - `title` varchar(100) NOT NULL DEFAULT '', - `path` varchar(255) NOT NULL DEFAULT '', - `protocol` varchar(10) NOT NULL DEFAULT '', - `method` varchar(10) NOT NULL DEFAULT '', - `requestType` varchar(100) NOT NULL DEFAULT '', - `responseType` varchar(100) NOT NULL DEFAULT '', - `status` varchar(20) NOT NULL DEFAULT '', - `owner` int UNSIGNED NOT NULl DEFAULT 0, - `desc` varchar(255) NOT NULL DEFAULT '', - `version` smallint UNSIGNED NOT NULL DEFAULT 0, - `params` text NULL, - `response` text NULL, - `commonParams` text NULL, - `addedBy` varchar(30) NOT NULL DEFAULT 0, - `addedDate` datetime NOT NULL, - `editEdBy` varchar(30) NOT NULL DEFAULT 0, - `editedDate` datetime NOT NULL, - `deleted` enum('0', '1') NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `product` varchar(255) NOT NULL DEFAULT '', + `lib` int UNSIGNED NOT NULL DEFAULT 0, + `module` int UNSIGNED NOT NULL DEFAULT 0, + `title` varchar(100) NOT NULL DEFAULT '', + `path` varchar(255) NOT NULL DEFAULT '', + `protocol` varchar(10) NOT NULL DEFAULT '', + `method` varchar(10) NOT NULL DEFAULT '', + `requestType` varchar(100) NOT NULL DEFAULT '', + `responseType` varchar(100) NOT NULL DEFAULT '', + `status` varchar(20) NOT NULL DEFAULT '', + `owner` int UNSIGNED NOT NULl DEFAULT 0, + `desc` varchar(255) NOT NULL DEFAULT '', + `version` smallint UNSIGNED NOT NULL DEFAULT 0, + `params` text NULL, + `response` text NULL, + `commonParams` text NULL, + `addedBy` varchar(30) NOT NULL DEFAULT 0, + `addedDate` datetime NOT NULL, + `editEdBy` varchar(30) NOT NULL DEFAULT 0, + `editedDate` datetime NOT NULL, + `deleted` enum('0', '1') NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) ); +-- DROP TABLE IF EXISTS `zt_apispec`; CREATE TABLE `zt_apispec` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `doc` int UNSIGNED NOT NULL DEFAULT 0, - `module` int UNSIGNED NOT NULL DEFAULT 0, - `title` varchar(100) NOT NULL DEFAULT '', - `path` varchar(255) NOT NULL DEFAULT '', - `protocol` varchar(10) NOT NULL DEFAULT '', - `method` varchar(10) NOT NULL DEFAULT '', - `requestType` varchar(100) NOT NULL DEFAULT '', - `responseType` varchar(100) NOT NULL DEFAULT '', - `status` tinyint UNSIGNED NOT NULL DEFAULT 0, - `owner` varchar(255) NOT NULl DEFAULT 0, - `desc` varchar(255) NOT NULL DEFAULT '', - `version` smallint UNSIGNED NOT NULL DEFAULT 0, - `params` text NULL, - `response` text NULL, - `addedBy` varchar(30) NOT NULL DEFAULT 0, - `addedDate` datetime NULL, - PRIMARY KEY (`id`) + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `doc` int UNSIGNED NOT NULL DEFAULT 0, + `module` int UNSIGNED NOT NULL DEFAULT 0, + `title` varchar(100) NOT NULL DEFAULT '', + `path` varchar(255) NOT NULL DEFAULT '', + `protocol` varchar(10) NOT NULL DEFAULT '', + `method` varchar(10) NOT NULL DEFAULT '', + `requestType` varchar(100) NOT NULL DEFAULT '', + `responseType` varchar(100) NOT NULL DEFAULT '', + `status` tinyint UNSIGNED NOT NULL DEFAULT 0, + `owner` varchar(255) NOT NULl DEFAULT 0, + `desc` varchar(255) NOT NULL DEFAULT '', + `version` smallint UNSIGNED NOT NULL DEFAULT 0, + `params` text NULL, + `response` text NULL, + `addedBy` varchar(30) NOT NULL DEFAULT 0, + `addedDate` datetime NULL, + PRIMARY KEY (`id`) ); +-- DROP TABLE IF EXISTS `zt_api_const`; create table `zt_api_const` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `doclib` int UNSIGNED NOT NULL DEFAULT 0, - `field` varchar(50) NOT NULL DEFAULT '', - `scope` varchar(50) NOT NULL DEFAULT '', - `type` varchar(20) NOT NULL DEFAULT '', - `default` varchar(1000) NOT NULL DEFAULT '', - `required` tinyint UNSIGNED NOT NULL DEFAULT 0, - `desc` varchar(255) NOT NULL DEFAULT 0, - `version` smallint UNSIGNED NOT NULL DEFAULT 0, - `addedBy` varchar(30) NOT NULL DEFAULT 0, - `addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - `editEdBy` varchar(30) NOT NULL DEFAULT 0, - `editedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - `deletedDate` datetime NULL, - PRIMARY KEY (`id`) -) + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `doclib` int UNSIGNED NOT NULL DEFAULT 0, + `field` varchar(50) NOT NULL DEFAULT '', + `scope` varchar(50) NOT NULL DEFAULT '', + `type` varchar(20) NOT NULL DEFAULT '', + `default` varchar(1000) NOT NULL DEFAULT '', + `required` tinyint UNSIGNED NOT NULL DEFAULT 0, + `desc` varchar(255) NOT NULL DEFAULT 0, + `version` smallint UNSIGNED NOT NULL DEFAULT 0, + `addedBy` varchar(30) NOT NULL DEFAULT 0, + `addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `editEdBy` varchar(30) NOT NULL DEFAULT 0, + `editedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `deletedDate` datetime NULL, + PRIMARY KEY (`id`) +); +-- DROP TABLE IF EXISTS `zt_api_const_spec`; create table `zt_api_const_spec` ( - `id` int UNSIGNED NOT NULL AUTO_INCREMENT, - `doclib` int UNSIGNED NOT NULL DEFAULT 0, - `field` varchar(50) NOT NULL DEFAULT '', - `scope` varchar(50) NOT NULL DEFAULT '', - `type` varchar(20) NOT NULL DEFAULT '', - `default` varchar(1000) NOT NULL DEFAULT '', - `required` tinyint UNSIGNED NOT NULL DEFAULT 0, - `desc` varchar(255) NOT NULL DEFAULT 0, - `version` smallint UNSIGNED NOT NULL DEFAULT 0, - `addedBy` varchar(30) NOT NULL DEFAULT 0, - `addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - PRIMARY KEY (`id`) -) + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `doclib` int UNSIGNED NOT NULL DEFAULT 0, + `field` varchar(50) NOT NULL DEFAULT '', + `scope` varchar(50) NOT NULL DEFAULT '', + `type` varchar(20) NOT NULL DEFAULT '', + `default` varchar(1000) NOT NULL DEFAULT '', + `required` tinyint UNSIGNED NOT NULL DEFAULT 0, + `desc` varchar(255) NOT NULL DEFAULT 0, + `version` smallint UNSIGNED NOT NULL DEFAULT 0, + `addedBy` varchar(30) NOT NULL DEFAULT 0, + `addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`id`) +); diff --git a/module/api/control.php b/module/api/control.php index d284ce6337..9dedd4e9dd 100644 --- a/module/api/control.php +++ b/module/api/control.php @@ -7,7 +7,7 @@ * @license ZPL (http://zpl.pub/page/zplv12.html) * @author Chunsheng Wang * @package api - * @version $Id: control.php 5143 2013-07-15 06:11:59Z zhujinyonging@gmail.com $ + * @version $Id: control.php 5143 2013-07-15 06:11:59Z thanatos thanatos915@163.com $ * @link http://www.zentao.net */ class api extends control @@ -25,39 +25,35 @@ class api extends control /** * Api doc index page. + * + * @param int $libID + * @param int $moduleID + * @param int $apiID + * @access public * @return void - * @author thanatos thanatos915@163.com */ - public function index() + public function index($libID = 0, $moduleID = 0, $apiID = 0, $version = 1) { - $params = $_GET; - $libID = $params['libID']; - $module = $params['module']; - $apiID = $params['apiID']; - $version = $params['version']; - - /* Get all api doc libraries */ + /* Get all api doc libraries. */ $libs = $this->doc->getApiLibs(); - /* generate bread crumbs dropMenu */ + /* Generate bread crumbs dropMenu. */ if($libs) { if($libID == 0) $libID = key($libs); $this->lang->modulePageNav = $this->generateLibsDropMenu($libs, $libID); - $this->view->libID = $libID; } $this->setMenu($libID); - - /* Get an api doc */ + /* Get an api doc. */ if($apiID > 0) { $api = $this->api->getLibById($apiID, $version); if($api) { - $module = $api->module; - $_GET['module'] = $module; - $libID = $api->lib; + $moduleID = $api->module; + $libID = $api->lib; + $this->view->api = $api; $this->view->apiID = $apiID; $this->view->version = $version; @@ -66,36 +62,27 @@ class api extends control } else { - /* Get module api list */ - $apiList = $this->api->getListByModuleId($libID, $module); + /* Get module api list. */ + $apiList = $this->api->getListByModuleId($libID, $moduleID); + $this->view->apiList = $apiList; - $this->view->moudle = $module; } - /* Get module tree */ - $moduleTree = $this->doc->getApiModuleTree($libID, $apiID); - $this->view->title = $this->lang->api->title; + $this->view->libID = $libID; + $this->view->apiID = $apiID; $this->view->libs = $libs; - $this->view->moduleTree = $moduleTree; + $this->view->moduleTree = $libID ? $this->doc->getApiModuleTree($libID, $apiID) : ''; $this->view->users = $this->user->getPairs('noclosed,noletter'); $this->display(); } - /** - * Show an Api doc - * @param $id - * @author thanatos thanatos915@163.com - */ - public function detail($id) - { - - } - /** * Create a api doc library. - * @author thanatos thanatos915@163.com + * + * @access public + * @return void */ public function createLib() { @@ -129,9 +116,15 @@ class api extends control $this->display(); } - public function edit() + /** + * Edit library. + * + * @param int $apiID + * @access public + * @return void + */ + public function edit($apiID) { - $apiID = $_GET['apiID']; if(helper::isAjaxRequest() && !empty($_POST)) { $this->loadModel('api'); @@ -169,16 +162,15 @@ class api extends control $this->view->edit = true; } - $example = [ - 'example' => 'type,description' - ]; - $this->view->example = json_encode($example, JSON_PRETTY_PRINT); + $example = array('example' => 'type,description'); + $example = json_encode($example, JSON_PRETTY_PRINT); $allUsers = $this->loadModel('user')->getPairs('devfirst|noclosed'); $this->view->user = $this->app->user->account; $this->view->allUsers = $allUsers; $this->view->moduleOptionMenu = $this->tree->getOptionMenu($api->lib, 'api', $startModuleID = 0); $this->view->moduleID = $api->module ? (int)$api->module : (int)$this->cookie->lastDocModule; + $this->view->example = $example; $this->view->title = $api->title . $this->lang->api->edit; $this->display(); @@ -187,16 +179,16 @@ class api extends control /** * Create an api doc. - * @author thanatos thanatos915@163.com + * + * @param int $libID + * @param int $moduleID + * @access public + * @return void */ - public function create() + public function create($libID, $moduleID = 0) { - $libID = $_GET['libID']; - $moduleID = $_GET['moduleID']; - if(helper::isAjaxRequest() && !empty($_POST)) + if(!empty($_POST)) { - $this->loadModel('api'); - $now = helper::now(); $userId = $this->app->user->account; $params = fixer::input('post') @@ -211,17 +203,10 @@ class api extends control ->get(); $apiID = $this->api->create($params); - if(empty($apiID)) - { - $this->sendError(dao::getError()); - exit; - } + if(empty($apiID)) return $this->sendError(dao::getError()); $this->action->create('api', $apiID, 'Created'); - $this->sendSuccess([ - 'locate' => helper::createLink('api', 'index', "apiID=$apiID"), - ]); - exit; + return $this->sendSuccess(array('locate' => helper::createLink('api', 'index', "apiID=$apiID"))); } $libs = $this->doc->getLibs('api', '', $libID); @@ -230,10 +215,8 @@ class api extends control $lib = $this->doc->getLibByID($libID); $libName = isset($lib->name) ? $lib->name . $this->lang->colon : ''; - $example = [ - 'example' => 'type,description' - ]; - $this->view->example = json_encode($example, JSON_PRETTY_PRINT); + $example = array('example' => 'type,description'); + $example = json_encode($example, JSON_PRETTY_PRINT); $allUsers = $this->loadModel('user')->getPairs('devfirst|noclosed'); $this->view->user = $this->app->user->account; @@ -243,10 +226,11 @@ class api extends control $this->view->moduleOptionMenu = $this->tree->getOptionMenu($libID, 'api', $startModuleID = 0); $this->view->moduleID = $moduleID ? (int)$moduleID : (int)$this->cookie->lastDocModule; $this->view->libs = $libs; + $this->view->example = $example; $this->view->title = $libName . $this->lang->api->create; $this->view->users = $this->user->getPairs('nocode'); - $this->display('api', 'create'); + $this->display(); } /** diff --git a/module/api/view/index.html.php b/module/api/view/index.html.php index deb2b9d749..6a061e86d4 100644 --- a/module/api/view/index.html.php +++ b/module/api/view/index.html.php @@ -13,83 +13,79 @@ api->confirmDelete);?>
- -
-
-
- - "; - echo html::a('javascript:;', "", '', "data-toggle='dropdown' class='btn btn-link'"); - echo "
'; - ?> -
- -
-
- api->noModule; ?> -
- - + + +
+
+
+ + "; + echo html::a('javascript:;', "", '', "data-toggle='dropdown' class='btn btn-link'"); + echo "
'; + ?> +
+ +
+
api->noModule; ?>
+ + +
+
+ + + + + + +
+
+
  • 0 ? $lang->api->module : $lang->api->title; ?>
  • +
    +
    +
    +
    api->noLib : $lang->api->noApi; ?>
    +
    + ' . $lang->api->createApi, '', 'class="btn btn-info btn-wide"'); + } + else + { + $html = html::a(helper::createLink('api', 'createLib'), ' ' . $lang->api->createLib, '', 'class="btn btn-info btn-wide iframe"'); + } + echo $html; + ?>
    +
    - - - - - +
    -
    -
  • 0 ? $lang->api->module : $lang->api->title; ?>
  • -
    -
    -
    -
    api->noLib : $lang->api->noApi; ?>
    -
    - ' . $lang->api->createApi, '', 'class="btn btn-info btn-wide"'); - } - else - { - $html = html::a(helper::createLink('api', 'createLib'), ' ' . $lang->api->createLib, '', 'class="btn btn-info btn-wide iframe"'); - } - echo $html; - ?> -
    +
    - - - - - + +
    diff --git a/module/doc/model.php b/module/doc/model.php index f37902441d..89c36f9443 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -2145,17 +2145,12 @@ EOT; $startModulePath = ''; $currentMethod = $this->app->getMethodName(); $users = $this->loadModel('user')->getPairs('noletter'); - if($startModule > 0) - { - $startModule = $this->tree->getById($startModule); - if($startModule) $startModulePath = $startModule->path . '%'; - } - $docs = $this->dao->select('*')->from(TABLE_API) + $docs = $this->dao->select('*')->from(TABLE_API) ->where('lib')->eq($rootID) ->andWhere('deleted')->eq(0) ->fetchAll(); - $moduleDocs = []; + $moduleDocs = array(); foreach($docs as $doc) { if(!$this->checkPrivDoc($doc)) continue; @@ -2163,7 +2158,7 @@ EOT; $moduleDocs[$doc->module][] = $doc; } - $treeMenu = []; + $treeMenu = array(); $query = $this->dao->select('*')->from(TABLE_MODULE) ->where('root')->eq((int)$rootID) ->andWhere('type')->eq('api')