* Format code.
This commit is contained in:
+9
-10
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
global $lang;
|
||||
|
||||
$config->api = new stdClass();
|
||||
$config->api->createlib = new stdclass();
|
||||
$config->api = new stdClass();
|
||||
$config->api->createlib = new stdclass();
|
||||
$config->api->createlib->requiredFields = 'name';
|
||||
$config->api->editlib = new stdclass();
|
||||
$config->api->editlib->requiredFields = 'name';
|
||||
|
||||
$config->api->struct = new stdClass();
|
||||
$config->api->editlib = new stdclass();
|
||||
$config->api->editlib->requiredFields = 'name';
|
||||
|
||||
$config->api->struct = new stdClass();
|
||||
$config->api->struct->requiredFields = 'name,params';
|
||||
|
||||
$config->api->create = new stdclass();
|
||||
$config->api->create = new stdclass();
|
||||
$config->api->create->requiredFields = 'lib,title,path,method,protocol';
|
||||
|
||||
$config->api->edit = new stdclass();
|
||||
$config->api->edit = new stdclass();
|
||||
$config->api->edit->requiredFields = 'lib,title,path,method,protocol';
|
||||
|
||||
$config->api->editor = new stdclass();
|
||||
$config->api->editor = new stdclass();
|
||||
$config->api->editor->createlib = ['id' => 'desc', 'tools' => 'simpleTools'];
|
||||
$config->api->editor->create = ['id' => 'desc', 'tools' => 'simpleTools'];
|
||||
$config->api->editor->edit = ['id' => 'desc', 'tools' => 'simpleTools'];
|
||||
|
||||
+22
-46
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The control file of api of ZenTaoPMS.
|
||||
*
|
||||
@@ -15,12 +14,10 @@ class api extends control
|
||||
public function __construct($moduleName = '', $methodName = '', $appName = '')
|
||||
{
|
||||
parent::__construct($moduleName, $methodName, $appName);
|
||||
$this->group = $this->loadModel('group');
|
||||
$this->user = $this->loadModel('user');
|
||||
$this->doc = $this->loadModel('doc');
|
||||
$this->action = $this->loadModel('action');
|
||||
$this->tree = $this->loadModel('tree');
|
||||
$this->api = $this->loadModel('api');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +179,7 @@ class api extends control
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$this->view->groups = $this->group->getPairs();
|
||||
$this->view->groups = $this->loadModel('group')->getPairs();
|
||||
$this->view->users = $this->user->getPairs('nocode');
|
||||
|
||||
$this->display();
|
||||
@@ -222,7 +219,7 @@ class api extends control
|
||||
}
|
||||
|
||||
$this->view->doc = $doc;
|
||||
$this->view->groups = $this->group->getPairs();
|
||||
$this->view->groups = $this->loadModel('group')->getPairs();
|
||||
$this->view->users = $this->user->getPairs('nocode');
|
||||
|
||||
$this->display();
|
||||
@@ -363,9 +360,10 @@ class api extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiID
|
||||
* @param int $apiID
|
||||
* @param string $confirm
|
||||
* @author thanatos thanatos915@163.com
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete($apiID, $confirm = 'no')
|
||||
{
|
||||
@@ -395,8 +393,9 @@ class api extends control
|
||||
/**
|
||||
* Get params type options by scope
|
||||
*
|
||||
* @param string $scope the params position
|
||||
* @author thanatos thanatos915@163.com
|
||||
* @param string $scope the params position
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetParamsTypeOptions($scope)
|
||||
{
|
||||
@@ -416,7 +415,9 @@ class api extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ref options by ajax.
|
||||
* @param int $libID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetRefOptions($libID = 0, $structID = 0)
|
||||
@@ -435,9 +436,10 @@ class api extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ref info
|
||||
* Get ref info by ajax.
|
||||
*
|
||||
* @param int $refID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetRefInfo($refID = 0)
|
||||
@@ -449,7 +451,9 @@ class api extends control
|
||||
/**
|
||||
* Set doc menu by method name.
|
||||
*
|
||||
* @author thanatos thanatos915@163.com
|
||||
* @param int $libID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
private function setMenu($libID = 0)
|
||||
{
|
||||
@@ -497,7 +501,10 @@ class api extends control
|
||||
/**
|
||||
* Generate api doc index page dropMenu
|
||||
*
|
||||
* @author thanatos thanatos915@163.com
|
||||
* @param array $libs
|
||||
* @param int $libID
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
private function generateLibsDropMenu($libs, $libID)
|
||||
{
|
||||
@@ -531,14 +538,14 @@ EOT;
|
||||
/**
|
||||
* Show doc of api doc library
|
||||
*
|
||||
* @author thanatos thanatos915@163.com
|
||||
* @param int $libID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function showLibs($libID = 0)
|
||||
{
|
||||
$lib = $this->doc->getLibById($libID);
|
||||
if(!empty($lib) and $lib->deleted == '1') $appendLib = $libID;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -649,35 +656,4 @@ EOT;
|
||||
$this->output = json_encode($output);
|
||||
die($this->output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var groupModel
|
||||
*/
|
||||
public $group;
|
||||
|
||||
/**
|
||||
* @var userModel
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @var docModel
|
||||
*/
|
||||
public $doc;
|
||||
|
||||
/**
|
||||
* @var actionModel
|
||||
*/
|
||||
public $action;
|
||||
|
||||
/**
|
||||
* @var treeModel;
|
||||
*/
|
||||
public $tree;
|
||||
|
||||
/**
|
||||
* @var apiModel
|
||||
*/
|
||||
public $api;
|
||||
}
|
||||
|
||||
+69
-59
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The model file of api module of ZenTaoCMS.
|
||||
*
|
||||
@@ -12,26 +11,28 @@
|
||||
*/
|
||||
class apiModel extends model
|
||||
{
|
||||
|
||||
const STATUS_DOING = 'doing';
|
||||
const STATUS_DONE = 'done';
|
||||
/* Status. */
|
||||
const STATUS_DOING = 'doing';
|
||||
const STATUS_DONE = 'done';
|
||||
const STATUS_HIDDEN = 'hidden';
|
||||
|
||||
const SCOPE_QUERY = 'query';
|
||||
/* Scope. */
|
||||
const SCOPE_QUERY = 'query';
|
||||
const SCOPE_FORM_DATA = 'formData';
|
||||
const SCOPE_PATH = 'path';
|
||||
const SCOPE_BODY = 'body';
|
||||
const SCOPE_HEADER = 'header';
|
||||
const SCOPE_COOKIE = 'cookie';
|
||||
const SCOPE_PATH = 'path';
|
||||
const SCOPE_BODY = 'body';
|
||||
const SCOPE_HEADER = 'header';
|
||||
const SCOPE_COOKIE = 'cookie';
|
||||
|
||||
/* Params. */
|
||||
const PARAMS_TYPE_CUSTOM = 'custom';
|
||||
|
||||
/**
|
||||
* Create an api doc.
|
||||
*
|
||||
* @param stdClass $params
|
||||
* @param object $params
|
||||
* @access public
|
||||
* @return int
|
||||
* @author thanatos thanatos915@163.com
|
||||
*/
|
||||
public function create($params)
|
||||
{
|
||||
@@ -40,15 +41,13 @@ class apiModel extends model
|
||||
->batchCheck($this->config->api->create->requiredFields, 'notempty')
|
||||
->exec();
|
||||
|
||||
if(dao::isError()) return false;
|
||||
|
||||
return $this->dao->lastInsertID();
|
||||
return dao::isError() ? false : $this->dao->lastInsertID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a global struct
|
||||
*
|
||||
* @param $data
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
@@ -65,8 +64,9 @@ class apiModel extends model
|
||||
/**
|
||||
* Update a struct.
|
||||
*
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @param int $id
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function updateStruct($id, $data)
|
||||
@@ -90,9 +90,10 @@ class apiModel extends model
|
||||
/**
|
||||
* Update an api doc.
|
||||
*
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @author thanatos thanatos915@163.com
|
||||
* @param int $id
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function update($id, $data)
|
||||
{
|
||||
@@ -111,13 +112,12 @@ class apiModel extends model
|
||||
->batchCheck($this->config->api->edit->requiredFields, 'notempty')
|
||||
->where('id')->eq($id)
|
||||
->exec();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get struct list by api doc id.
|
||||
*
|
||||
* @param $id
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
@@ -128,7 +128,8 @@ class apiModel extends model
|
||||
->where('lib')->eq($id)
|
||||
->fetchAll();
|
||||
|
||||
array_map(function ($item) {
|
||||
array_map(function ($item)
|
||||
{
|
||||
$item->attribute = json_decode(htmlspecialchars_decode($item->attribute), true);
|
||||
return $item;
|
||||
}, $res);
|
||||
@@ -138,9 +139,9 @@ class apiModel extends model
|
||||
/**
|
||||
* Get a struct info.
|
||||
*
|
||||
* @param $id
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return stdClass
|
||||
* @return object
|
||||
*/
|
||||
public function getStructByID($id)
|
||||
{
|
||||
@@ -149,8 +150,7 @@ class apiModel extends model
|
||||
->where('id')->eq($id)
|
||||
->fetch();
|
||||
|
||||
if($model)
|
||||
$model->attribute = json_decode(htmlspecialchars_decode($model->attribute), true);
|
||||
if($model) $model->attribute = json_decode(htmlspecialchars_decode($model->attribute), true);
|
||||
|
||||
return $model;
|
||||
}
|
||||
@@ -227,9 +227,9 @@ class apiModel extends model
|
||||
/**
|
||||
* Get status text by status.
|
||||
*
|
||||
* @param $status
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return string
|
||||
* @author thanatos thanatos915@163.com
|
||||
*/
|
||||
public static function getApiStatusText($status)
|
||||
{
|
||||
@@ -237,9 +237,13 @@ class apiModel extends model
|
||||
switch($status)
|
||||
{
|
||||
case static::STATUS_DOING:
|
||||
{
|
||||
return $lang->api->doing;
|
||||
}
|
||||
case static::STATUS_DONE:
|
||||
{
|
||||
return $lang->api->done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,8 +252,8 @@ class apiModel extends model
|
||||
*
|
||||
* @param int $libID
|
||||
* @param int $structID
|
||||
* @return string
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getStructTreeByLib($libID = 0, $structID = 0)
|
||||
{
|
||||
@@ -258,17 +262,22 @@ class apiModel extends model
|
||||
$html = "<ul id='modules' class='tree' data-ride='tree' data-name='tree-lib'>";
|
||||
foreach($list as $item)
|
||||
{
|
||||
$class = ['catalog'];
|
||||
$class = array('catalog');
|
||||
if($structID && $structID == $item->id)
|
||||
array_push($class, 'active');
|
||||
{
|
||||
$class[] = 'active';
|
||||
}
|
||||
else
|
||||
array_push($class, 'doc');
|
||||
{
|
||||
$class[] = 'doc';
|
||||
}
|
||||
|
||||
$html .= '<li class="' . implode(' ', $class) . '">';
|
||||
$html .= html::a(helper::createLink('api', 'struct', "libID=$libID&structID=$item->id"), "<i class='icon icon-file-text text-muted'></i> " . $item->name, '', "data-app='{$this->app->tab}' class='doc-title' title='{$item->name}'");
|
||||
$html .= "</li>";
|
||||
}
|
||||
$html .= "</ul>";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
@@ -379,42 +388,43 @@ class apiModel extends model
|
||||
$result['message'] = $this->lang->api->error->onlySelect;
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
$stmt = $this->dbh->query($sql);
|
||||
$stmt = $this->dbh->query($sql);
|
||||
|
||||
$rows = array();
|
||||
if(empty($keyField))
|
||||
{
|
||||
$rows = $stmt->fetchAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
while($row = $stmt->fetch()) $rows[$row->$keyField] = $row;
|
||||
}
|
||||
|
||||
$result['status'] = 'success';
|
||||
$result['data'] = $rows;
|
||||
} catch(PDOException $e)
|
||||
$rows = array();
|
||||
if(empty($keyField))
|
||||
{
|
||||
$result['status'] = 'fail';
|
||||
$result['message'] = $e->getMessage();
|
||||
$rows = $stmt->fetchAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
while($row = $stmt->fetch()) $rows[$row->$keyField] = $row;
|
||||
}
|
||||
|
||||
return $result;
|
||||
$result['status'] = 'success';
|
||||
$result['data'] = $rows;
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
$result['status'] = 'fail';
|
||||
$result['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author thanatos thanatos915@163.com
|
||||
* Get spec of api.
|
||||
*
|
||||
* @param object $data
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function getApiSpecByData($data)
|
||||
{
|
||||
|
||||
$now = helper::now();
|
||||
return [
|
||||
return array(
|
||||
'doc' => $data->id,
|
||||
'module' => $data->module,
|
||||
'title' => $data->title,
|
||||
@@ -430,7 +440,7 @@ class apiModel extends model
|
||||
'params' => $data->params,
|
||||
'response' => $data->response,
|
||||
'addedBy' => $this->app->user->account,
|
||||
'addedDate' => $now,
|
||||
];
|
||||
'addedDate' => helper::now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user