DocumentController.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class DocumentController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'document');
  22. //用户ID
  23. private $user_id;
  24. /**
  25. * Checkout login status
  26. * 验证登录状态
  27. */
  28. public function __construct()
  29. {
  30. // identity authentication
  31. // 身份验证
  32. $server = new GuestModule;
  33. if (!$server->checkLogin()) {
  34. $this->returnJson['statusCode'] = '120005';
  35. exitOutput($this->returnJson);
  36. } else {
  37. $this->user_id = $_SESSION['userID'];
  38. }
  39. }
  40. /**
  41. * 添加文档
  42. */
  43. public function addDocument()
  44. {
  45. //分组ID
  46. $group_id = securelyInput('groupID');
  47. //题目
  48. $title = securelyInput('title');
  49. $content = quickInput('content');
  50. $content_raw = quickInput('contentRaw', '');
  51. $content_type = quickInput('contentType');
  52. if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  53. //分组ID格式不合法
  54. $this->returnJson['statusCode'] = '230001';
  55. } elseif ($content_type != 0 && $content_type != 1) {
  56. //文档描述格式不合法
  57. $this->returnJson['statusCode'] = '230002';
  58. } else {
  59. $group_module = new DocumentGroupModule();
  60. $user_type = $group_module->getUserType($group_id);
  61. if ($user_type < 0 || $user_type > 2) {
  62. $this->returnJson['statusCode'] = '120007';
  63. } else {
  64. $service = new DocumentModule();
  65. $result = $service->addDocument($this->user_id, $group_id, $content_type, $content, $content_raw, $title);
  66. if ($result) {
  67. $this->returnJson['statusCode'] = '000000';
  68. $this->returnJson['documentID'] = $result;
  69. } else {
  70. $this->returnJson['statusCode'] = '230000';
  71. }
  72. }
  73. }
  74. exitOutput($this->returnJson);
  75. }
  76. /**
  77. * 修改文档
  78. */
  79. public function editDocument()
  80. {
  81. $document_id = securelyInput('documentID');
  82. $title = securelyInput('title');
  83. $group_id = securelyInput('groupID');
  84. $content = quickInput('content');
  85. $content_raw = quickInput('contentRaw', '');
  86. $content_type = securelyInput('contentType');
  87. if (!preg_match('/^[0-9]{1,11}$/', $document_id)) {
  88. //文档ID格式非法
  89. $this->returnJson['statusCode'] = '230003';
  90. } elseif (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  91. //分组ID格式非法
  92. $this->returnJson['statusCode'] = '230001';
  93. } else {
  94. $service = new DocumentModule();
  95. $user_type = $service->getUserType($document_id);
  96. if ($user_type < 0 || $user_type > 2) {
  97. $this->returnJson['statusCode'] = '120007';
  98. } else {
  99. $result = $service->editDocument($this->user_id, $group_id, $document_id, $content_type, $content, $content_raw, $title);
  100. if ($result) {
  101. //成功
  102. $this->returnJson['statusCode'] = '000000';
  103. } else {
  104. //失败
  105. $this->returnJson['statusCode'] = '230000';
  106. }
  107. }
  108. }
  109. exitOutput($this->returnJson);
  110. }
  111. /**
  112. * 获取文档列表
  113. */
  114. public function getDocumentList()
  115. {
  116. $group_id = securelyInput('groupID');
  117. if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  118. //分组ID格式不合法
  119. $this->returnJson['statusCode'] = '230001';
  120. } else {
  121. $service = new DocumentModule();
  122. $result = $service->getDocumentList($group_id, $this->user_id);
  123. if ($result) {
  124. //成功
  125. $this->returnJson['statusCode'] = '000000';
  126. $this->returnJson['documentList'] = $result;
  127. } else {
  128. //失败
  129. $this->returnJson['statusCode'] = '230000';
  130. }
  131. }
  132. exitOutput($this->returnJson);
  133. }
  134. /**
  135. * 获取所有文档列表
  136. */
  137. public function getAllDocumentList()
  138. {
  139. $project_id = securelyInput('projectID');
  140. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  141. //项目ID格式不合法
  142. $this->returnJson['statusCode'] = '230004';
  143. } else {
  144. $service = new DocumentModule();
  145. $result = $service->getAllDocumentList($project_id, $this->user_id);
  146. //验证结果
  147. if ($result) {
  148. //成功
  149. $this->returnJson['statusCode'] = '000000';
  150. $this->returnJson['documentList'] = $result;
  151. } else {
  152. //失败
  153. $this->returnJson['statusCode'] = '230000';
  154. }
  155. }
  156. exitOutput($this->returnJson);
  157. }
  158. /**
  159. * 搜索文档
  160. */
  161. public function searchDocument()
  162. {
  163. $tips_length = mb_strlen(quickInput('tips'), 'utf8');
  164. $tips = securelyInput('tips');
  165. $project_id = securelyInput('projectID');
  166. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  167. //项目ID格式不合法
  168. $this->returnJson['statusCode'] = '230004';
  169. } elseif ($tips_length < 1 || $tips_length > 255) {
  170. //判断关键字长度是否合法
  171. $this->returnJson['statusCode'] = '230005';
  172. } else {
  173. $service = new DocumentModule();
  174. $result = $service->searchDocument($project_id, $tips, $this->user_id);
  175. //验证结果
  176. if ($result) {
  177. //成功
  178. $this->returnJson['statusCode'] = '000000';
  179. $this->returnJson['documentList'] = $result;
  180. } else {
  181. //失败
  182. $this->returnJson['statusCode'] = '230000';
  183. }
  184. }
  185. exitOutput($this->returnJson);
  186. }
  187. /**
  188. * 获取文档详情
  189. */
  190. public function getDocument()
  191. {
  192. $document_id = securelyInput('documentID');
  193. if (!preg_match('/^[0-9]{1,11}$/', $document_id)) {
  194. //文档ID格式不合法
  195. $this->returnJson['statusCode'] = '230003';
  196. } else {
  197. $service = new DocumentModule();
  198. $result = $service->getDocument($document_id, $this->user_id);
  199. if ($result) {
  200. //成功
  201. $this->returnJson['statusCode'] = '000000';
  202. $this->returnJson['documentInfo'] = $result;
  203. } else {
  204. //失败
  205. $this->returnJson['statusCode'] = '230000';
  206. }
  207. }
  208. exitOutput($this->returnJson);
  209. }
  210. /**
  211. * 批量删除文档
  212. */
  213. public function deleteDocuments()
  214. {
  215. $ids = quickInput('documentID');
  216. $arr = json_decode($ids);
  217. $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
  218. $project_id = securelyInput('projectID');
  219. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  220. //项目ID格式不合法
  221. $this->returnJson['statusCode'] = '230004';
  222. } elseif (empty($arr)) {
  223. //文档ID格式不合法
  224. $this->returnJson['statusCode'] = '230003';
  225. } else {
  226. $project_module = new ProjectModule();
  227. $user_type = $project_module->getUserType($project_id);
  228. if ($user_type < 0 || $user_type > 2) {
  229. $this->returnJson['statusCode'] = '120007';
  230. } else {
  231. $document_ids = implode(',', $arr);
  232. $service = new DocumentModule();
  233. $result = $service->deleteDocuments($project_id, $this->user_id, $document_ids);
  234. //验证结果
  235. if ($result) {
  236. //成功
  237. $this->returnJson['statusCode'] = '000000';
  238. } else {
  239. //失败
  240. $this->returnJson['statusCode'] = '230000';
  241. }
  242. }
  243. }
  244. exitOutput($this->returnJson);
  245. }
  246. }