tao.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /**
  3. * The tao file of doc module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Shujie Tian <tianshujie@easycorp.ltd>
  8. * @package doc
  9. * @link https://www.zentao.net
  10. */
  11. class docTao extends docModel
  12. {
  13. /**
  14. * 获取编辑过的文档ID列表。
  15. * Get the list of doc id list that have been edited.
  16. *
  17. * @access protected
  18. * @return array
  19. */
  20. protected function getEditedDocIdList()
  21. {
  22. return $this->dao->select('objectID')->from(TABLE_ACTION)
  23. ->where('objectType')->eq('doc')
  24. ->andWhere('action')->in('edited')
  25. ->andWhere('actor')->eq($this->app->user->account)
  26. ->andWhere('vision')->eq($this->config->vision)
  27. ->fetchPairs();
  28. }
  29. /**
  30. * 获取已排序的执行数据。
  31. * Get ordered executions.
  32. *
  33. * @param int $append
  34. * @access protected
  35. * @return array
  36. */
  37. protected function getOrderedExecutions($append = 0)
  38. {
  39. $myObjects = $normalObjects = $closedObjects = array();
  40. $projectPairs = $this->dao->select('id,name')->from(TABLE_PROJECT)->where('type')->eq('project')->fetchPairs('id');
  41. $executions = $this->dao->select('*')->from(TABLE_EXECUTION)
  42. ->where('deleted')->eq(0)
  43. ->andWhere('type')->in('sprint,stage')
  44. ->andWhere('multiple')->eq('1')
  45. ->andWhere('vision')->eq($this->config->vision)
  46. ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->sprints)->fi()
  47. ->beginIF($append)->orWhere('id')->eq($append)->fi()
  48. ->orderBy('order_asc')
  49. ->fetchAll('id');
  50. foreach($executions as $id => $execution)
  51. {
  52. if($execution->type == 'stage' && $execution->grade != 1)
  53. {
  54. $parentExecutions = $this->dao->select('id,name')->from(TABLE_EXECUTION)->where('id')->in(trim($execution->path, ','))->andWhere('type')->in('stage,sprint')->orderBy('grade')->fetchPairs();
  55. $execution->name = implode('/', $parentExecutions);
  56. }
  57. $execution->name = zget($projectPairs, $execution->project) . ' / ' . $execution->name;
  58. if($execution->status != 'done' && $execution->status != 'closed' && $execution->PM == $this->app->user->account)
  59. {
  60. $myObjects[$id] = $execution->name;
  61. }
  62. elseif($execution->status != 'done' && $execution->status != 'closed' && !($execution->PM == $this->app->user->account))
  63. {
  64. $normalObjects[$id] = $execution->name;
  65. }
  66. elseif(in_array($execution->status, array('done', 'closed')))
  67. {
  68. $closedObjects[$id] = $execution->name;
  69. }
  70. }
  71. return array($myObjects, $normalObjects, $closedObjects);
  72. }
  73. /**
  74. * 获取关联产品的数据。
  75. * Get the data of the linked product.
  76. *
  77. * @param int $productID
  78. * @param string $userView
  79. * @access protected
  80. * @return array
  81. */
  82. protected function getLinkedProductData($productID, $userView = '')
  83. {
  84. $storyIdList = $this->dao->select('id')->from(TABLE_STORY)
  85. ->where('product')->eq($productID)
  86. ->andWhere('deleted')->eq('0')
  87. ->beginIF(!$this->app->user->admin)->andWhere('product')->in($userView)->fi()
  88. ->get();
  89. $epicIdList = $this->dao->select('id')->from(TABLE_STORY)
  90. ->where('product')->eq($productID)
  91. ->andWhere('deleted')->eq('0')
  92. ->andWhere('type')->eq('epic')
  93. ->beginIF(!$this->app->user->admin)->andWhere('product')->in($userView)->fi()
  94. ->fetchPairs();
  95. $requirementIdList = $this->dao->select('id')->from(TABLE_STORY)
  96. ->where('product')->eq($productID)
  97. ->andWhere('deleted')->eq('0')
  98. ->andWhere('type')->eq('requirement')
  99. ->beginIF(!$this->app->user->admin)->andWhere('product')->in($userView)->fi()
  100. ->fetchPairs();
  101. $planIdList = $this->dao->select('id')->from(TABLE_PRODUCTPLAN)
  102. ->where('product')->eq($productID)
  103. ->andWhere('deleted')->eq('0')
  104. ->beginIF(!$this->app->user->admin)->andWhere('product')->in($userView)->fi()
  105. ->get();
  106. $releasePairs = $this->dao->select('id')->from(TABLE_RELEASE)
  107. ->where('product')->eq($productID)
  108. ->andWhere('deleted')->eq('0')
  109. ->beginIF(!$this->app->user->admin)->andWhere('product')->in($userView)->fi()
  110. ->fetchPairs('id');
  111. $casePairs = $this->dao->select('id')->from(TABLE_CASE)
  112. ->where('product')->eq($productID)
  113. ->andWhere('deleted')->eq('0')
  114. ->beginIF(!$this->app->user->admin)->andWhere('product')->in($userView)->fi()
  115. ->fetchPairs('id');
  116. $resultPairs = $this->dao->select('id')->from(TABLE_TESTRESULT)->where('case')->in($casePairs)->fetchPairs('id', 'id');
  117. return array($storyIdList, $epicIdList, $requirementIdList, $planIdList, $releasePairs, $casePairs, $resultPairs);
  118. }
  119. /**
  120. * 获取我创建的文档。
  121. * Get docs created by me.
  122. *
  123. * @param array $hasPrivDocIdList
  124. * @param string $sort
  125. * @param object $pager
  126. * @access protected
  127. * @return array
  128. */
  129. protected function getOpenedDocs($hasPrivDocIdList, $sort, $pager = null)
  130. {
  131. return $this->dao->select('t1.*, t2.name as libName, t2.type as objectType')->from(TABLE_DOC)->alias('t1')
  132. ->leftJoin(TABLE_DOCLIB)->alias('t2')->on("t1.lib=t2.id")
  133. ->where('t1.deleted')->eq(0)
  134. ->andWhere('t1.lib')->ne(0)
  135. ->andWhere('t1.id')->in($hasPrivDocIdList)
  136. ->beginIF($this->config->doc->notArticleType)->andWhere('t1.type')->notIN($this->config->doc->notArticleType)->fi()
  137. ->andWhere('t1.addedBy')->eq($this->app->user->account)
  138. ->andWhere('t1.vision')->in($this->config->vision)
  139. ->andWhere('t1.templateType')->eq('')
  140. ->orderBy($sort)
  141. ->page($pager)
  142. ->fetchAll('id');
  143. }
  144. /**
  145. * 获取我编辑过的文档。
  146. * Get the docs that I have edited.
  147. *
  148. * @param string $sort
  149. * @param object $pager
  150. * @access protected
  151. * @return array
  152. */
  153. protected function getEditedDocs($sort, $pager = null)
  154. {
  155. $docIdList = $this->dao->select('objectID')->from(TABLE_ACTION)
  156. ->where('objectType')->eq('doc')
  157. ->andWhere('actor')->eq($this->app->user->account)
  158. ->andWhere('action')->eq('edited')
  159. ->andWhere('vision')->eq($this->config->vision)
  160. ->fetchAll('objectID');
  161. return $this->dao->select('t1.*, t2.name as libName, t2.type as objectType')->from(TABLE_DOC)->alias('t1')
  162. ->leftJoin(TABLE_DOCLIB)->alias('t2')->on("t1.lib=t2.id")
  163. ->where('t1.deleted')->eq(0)
  164. ->andWhere('t1.id')->in(array_keys($docIdList))
  165. ->andWhere('t1.lib')->ne(0)
  166. ->andWhere('t1.vision')->in($this->config->vision)
  167. ->beginIF($this->config->doc->notArticleType)->andWhere('t1.type')->notIN($this->config->doc->notArticleType)->fi()
  168. ->orderBy($sort)
  169. ->page($pager)
  170. ->fetchAll('id');
  171. }
  172. /**
  173. * 获取按照编辑时间倒序排序的文档。
  174. * Get the docs ordered by edited date.
  175. *
  176. * @param array $hasPrivDocIdList
  177. * @param array $allLibIDList
  178. * @param object $pager
  179. * @access protected
  180. * @return array
  181. */
  182. protected function getOrderedDocsByEditedDate($hasPrivDocIdList, $allLibIDList, $pager = null)
  183. {
  184. return $this->dao->select('*')->from(TABLE_DOC)
  185. ->where('deleted')->eq(0)
  186. ->andWhere('id')->in($hasPrivDocIdList)
  187. ->andWhere('templateType')->eq('')
  188. ->beginIF($this->config->doc->notArticleType)->andWhere('type')->notIN($this->config->doc->notArticleType)->fi()
  189. ->andWhere('lib')->in($allLibIDList)
  190. ->andWhere('vision')->in($this->config->vision)
  191. ->orderBy('editedDate_desc')
  192. ->page($pager)
  193. ->fetchAll('id');
  194. }
  195. /**
  196. * 获取我收藏的文档。
  197. * Get the docs that I have collected.
  198. *
  199. * @param array $hasPrivDocIdList
  200. * @param string $sort
  201. * @param object $pager
  202. * @access protected
  203. * @return array
  204. */
  205. protected function getCollectedDocs($hasPrivDocIdList, $sort, $pager = null)
  206. {
  207. return $this->dao->select('t1.*')->from(TABLE_DOC)->alias('t1')
  208. ->leftJoin(TABLE_DOCACTION)->alias('t2')->on("t1.id=t2.doc AND t2.action='collect'")
  209. ->where('t1.deleted')->eq(0)
  210. ->andWhere('t1.lib')->ne(0)
  211. ->andWhere('t1.templateType')->eq('')
  212. ->andWhere('t1.id')->in($hasPrivDocIdList)
  213. ->beginIF($this->config->doc->notArticleType)->andWhere('t1.type')->notIN($this->config->doc->notArticleType)->fi()
  214. ->andWhere('t2.actor')->eq($this->app->user->account)
  215. ->andWhere('t1.vision')->in($this->config->vision)
  216. ->orderBy($sort)
  217. ->page($pager)
  218. ->fetchAll('id');
  219. }
  220. /**
  221. * 获取空间。
  222. * Get space pairs.
  223. *
  224. * @param string $type
  225. * @access protected
  226. * @return array
  227. */
  228. protected function getSpacePairs($type)
  229. {
  230. $objectLibs = $this->dao->select('*')->from(TABLE_DOCLIB)
  231. ->where('type')->eq($type)
  232. ->andWhere('deleted')->eq(0)
  233. ->andWhere('parent')->eq(0)
  234. ->andWhere('vision')->eq($this->config->vision)
  235. ->fetchAll();
  236. $pairs = array();
  237. foreach($objectLibs as $lib)
  238. {
  239. if($this->checkPrivLib($lib)) $pairs[$lib->id] = $lib->name;
  240. }
  241. return $pairs;
  242. }
  243. /**
  244. * 更新文档。
  245. * Update document.
  246. *
  247. * @param int $docID
  248. * @param object $doc
  249. * @param bool $basicInfoChanged
  250. * @access protected
  251. * @return void
  252. */
  253. public function doUpdateDoc($docID, $doc, $basicInfoChanged = false)
  254. {
  255. $this->dao->update(TABLE_DOC)->data($doc)->autoCheck()->where('id')->eq($docID)->exec();
  256. if(empty($doc->parent) && $basicInfoChanged)
  257. {
  258. $childData = new stdclass();
  259. $childData->module = $doc->module;
  260. $childData->lib = $doc->lib;
  261. $childData->acl = $doc->acl;
  262. if(isset($doc->groups)) $childData->groups = $doc->groups;
  263. if(isset($doc->users)) $childData->users = $doc->users;
  264. $this->dao->update(TABLE_DOC)->data($childData)->where("FIND_IN_SET('{$docID}', `path`)")->exec();
  265. }
  266. }
  267. /**
  268. * 插入文档库。
  269. * Insert doclib.
  270. *
  271. * @param object $lib
  272. * @param string $requiredFields
  273. * @access protected
  274. * @return int|false
  275. */
  276. protected function doInsertLib($lib, $requiredFields = '')
  277. {
  278. $this->dao->insert(TABLE_DOCLIB)->data($lib, 'spaceName')->autoCheck()
  279. ->batchCheck($requiredFields, 'notempty')
  280. ->exec();
  281. if(dao::isError()) return false;
  282. return $this->dao->lastInsertID();
  283. }
  284. /**
  285. * Filter deleted documents.
  286. *
  287. * @param array $docs
  288. * @access protected
  289. * @return array
  290. */
  291. protected function filterDeletedDocs($docs)
  292. {
  293. $deletedDocs = array();
  294. foreach($docs as $docID => $doc)
  295. {
  296. if($doc->deleted == '0') continue;
  297. unset($docs[$docID]);
  298. $docPath = trim($doc->path, ',');
  299. if(empty($docPath))
  300. {
  301. $docPath = $docID;
  302. if(!empty($doc->parent)) $docPath = $doc->parent . ',' . $docPath;
  303. }
  304. $doc->path = ',' . $docPath . ',';
  305. $deletedDocs[$doc->id] = $doc->path;
  306. }
  307. foreach($deletedDocs as $deletedPath)
  308. {
  309. foreach($docs as $docID => $doc)
  310. {
  311. if($deletedPath && strpos($doc->path, $deletedPath) !== false) unset($docs[$docID]);
  312. }
  313. }
  314. return $docs;
  315. }
  316. }