zen.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. <?php
  2. /**
  3. * The zen 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 docZen extends doc
  12. {
  13. /**
  14. * Process file field for table.
  15. *
  16. * @param array $files
  17. * @param array $fileIcon
  18. * @param array $sourcePairs
  19. * @param bool $skipImageWidth
  20. * @access protected
  21. * @return array
  22. */
  23. protected function processFiles($files, $fileIcon, $sourcePairs, $skipImageWidth = false)
  24. {
  25. if(!$skipImageWidth) $this->loadModel('file');
  26. foreach($files as $fileID => $file)
  27. {
  28. if(empty($file->pathname))
  29. {
  30. unset($files[$fileID]);
  31. continue;
  32. }
  33. $file->fileIcon = isset($fileIcon[$file->id]) ? $fileIcon[$file->id] : '';
  34. $file->fileName = str_replace('.' . $file->extension, '', $file->title);
  35. $file->sourceName = isset($sourcePairs[$file->objectType][$file->objectID]) ? $sourcePairs[$file->objectType][$file->objectID] : '';
  36. $file->sizeText = number_format($file->size / 1024, 1) . 'K';
  37. if(!$skipImageWidth)
  38. {
  39. $imageSize = $this->file->getImageSize($file);
  40. $file->imageWidth = isset($imageSize[0]) ? $imageSize[0] : 0;
  41. }
  42. if($file->objectType == 'requirement')
  43. {
  44. $file->objectName = $this->lang->URCommon . ' : ';
  45. }
  46. else
  47. {
  48. if(!isset($this->lang->{$file->objectType}->common)) $this->app->loadLang($file->objectType);
  49. $file->objectName = $this->lang->{$file->objectType}->common . ' : ';
  50. }
  51. }
  52. return $files;
  53. }
  54. /**
  55. * 构造大纲的数据。
  56. * Build the data of outline.
  57. *
  58. * @param int $topLevel
  59. * @param array $content
  60. * @param array $includeHeadElement
  61. * @access protected
  62. * @return array
  63. */
  64. protected function buildOutlineList($topLevel, $content, $includeHeadElement)
  65. {
  66. $preLevel = 0;
  67. $preIndex = 0;
  68. $parentID = 0;
  69. $currentLevel = 0;
  70. $outlineList = array();
  71. foreach($content as $index => $element)
  72. {
  73. preg_match('/<(h[1-6])([\S\s]*?)>([\S\s]*?)<\/\1>/', $element, $headElement);
  74. /* The current element is existed, the element is in the includeHeadElement, and the text in the element is not null. */
  75. if(isset($headElement[1]) && in_array($headElement[1], $includeHeadElement) && strip_tags($headElement[3]) != '')
  76. {
  77. $currentLevel = (int)ltrim($headElement[1], 'h');
  78. $item = array();
  79. $item['id'] = $index;
  80. $item['title'] = array('html' => strip_tags($headElement[3]));
  81. $item['hint'] = strip_tags($headElement[3]);
  82. $item['url'] = '#anchor' . $index;
  83. $item['level'] = $currentLevel;
  84. $item['data-level'] = $item['level'];
  85. $item['data-index'] = $index;
  86. if($currentLevel == $topLevel)
  87. {
  88. $parentID = -1;
  89. }
  90. elseif($currentLevel > $preLevel)
  91. {
  92. $parentID = $preIndex;
  93. }
  94. elseif($currentLevel < $preLevel)
  95. {
  96. $parentID = $this->getOutlineParentID($outlineList, $currentLevel);
  97. }
  98. $item['parent'] = $parentID;
  99. $preIndex = $index;
  100. $preLevel = $currentLevel;
  101. $outlineList[$index] = $item;
  102. }
  103. }
  104. return $outlineList;
  105. }
  106. /**
  107. * 获取大纲的父级ID。
  108. * Get the parent ID of the outline.
  109. *
  110. * @param array $outlineList
  111. * @param int $currentLevel
  112. * @access protected
  113. * @return int
  114. */
  115. protected function getOutlineParentID($outlineList, $currentLevel)
  116. {
  117. $parentID = 0;
  118. $outlineList = array_reverse($outlineList, true);
  119. foreach($outlineList as $index => $item)
  120. {
  121. if($item['level'] < $currentLevel)
  122. {
  123. $parentID = $index;
  124. break;
  125. }
  126. }
  127. return $parentID;
  128. }
  129. /**
  130. * 构造大纲的树形结构。
  131. * Build the tree structure of the outline.
  132. *
  133. * @param array $outlineList
  134. * @param int $parentID
  135. * @access protected
  136. * @return array
  137. */
  138. protected function buildOutlineTree($outlineList, $parentID = -1)
  139. {
  140. $outlineTree = array();
  141. foreach($outlineList as $index => $item)
  142. {
  143. if($item['parent'] != $parentID) continue;
  144. unset($outlineList[$index]);
  145. $items = $this->buildOutlineTree($outlineList, $index);
  146. if(!empty($items)) $item['items'] = $items;
  147. $outlineTree[] = $item;
  148. }
  149. return $outlineTree;
  150. }
  151. /**
  152. * 展示我的空间相关变量。
  153. * Show my space related variables.
  154. *
  155. * @param string $type
  156. * @param int $objectID
  157. * @param int $libID
  158. * @param int $moduleID
  159. * @param string $browseType
  160. * @param int $param
  161. * @param string $orderBy
  162. * @param array $docs
  163. * @param object $pager
  164. * @param array $libs
  165. * @param string $objectTitle
  166. * @access protected
  167. * @return void
  168. */
  169. protected function assignVarsForMySpace($type, $objectID, $libID, $moduleID, $browseType, $param, $orderBy, $docs, $pager, $libs, $objectTitle)
  170. {
  171. $this->view->title = $this->lang->doc->common;
  172. $this->view->type = $type;
  173. $this->view->libID = $libID;
  174. $this->view->moduleID = $moduleID;
  175. $this->view->browseType = $browseType;
  176. $this->view->param = $param;
  177. $this->view->orderBy = $orderBy;
  178. $this->view->docs = $docs;
  179. $this->view->pager = $pager;
  180. $this->view->objectTitle = $objectTitle;
  181. $this->view->objectID = 0;
  182. $this->view->canUpdateOrder = common::hasPriv('doc', 'sortDoc') && $orderBy == 'order_asc';
  183. $this->view->libType = 'lib';
  184. $this->view->spaceType = 'mine';
  185. $this->view->users = $this->user->getPairs('noletter');
  186. $this->view->lib = $this->doc->getLibByID($libID);
  187. $this->view->libTree = $this->doc->getLibTree($type != 'mine' ? 0 : $libID, $libs, 'mine', $moduleID, 0, $browseType);
  188. $this->view->canExport = ($this->config->edition != 'open' && common::hasPriv('doc', 'mine2export') && $type == 'mine');
  189. $this->view->linkParams = "objectID={$objectID}&%s&browseType=&orderBy={$orderBy}&param=0";
  190. }
  191. /**
  192. * 处理创建文档库的访问控制。
  193. * Handle the access control of creating document library.
  194. *
  195. * @param string $type api|project|product|execution|custom|mine
  196. * @access protected
  197. * @return void
  198. */
  199. protected function setAclForCreateLib($type)
  200. {
  201. if($type == 'custom')
  202. {
  203. unset($this->lang->doclib->aclList['default']);
  204. }
  205. elseif($type == 'mine')
  206. {
  207. $this->lang->doclib->aclList = $this->lang->doclib->mySpaceAclList;
  208. }
  209. elseif(in_array($type, array('product', 'project', 'execution')))
  210. {
  211. $this->lang->doclib->aclList['default'] = sprintf($this->lang->doclib->aclList['default'], $this->lang->{$type}->common);
  212. $this->lang->doclib->aclList['private'] = sprintf($this->lang->doclib->privateACL, $this->lang->{$type}->common);
  213. unset($this->lang->doclib->aclList['open']);
  214. }
  215. if($type != 'mine')
  216. {
  217. $this->app->loadLang('api');
  218. $this->lang->api->aclList['default'] = sprintf($this->lang->api->aclList['default'], $this->lang->{$type}->common);
  219. }
  220. }
  221. /**
  222. * 为创建文档库构造库数据。
  223. * Build library data for creating document library.
  224. *
  225. * @access protected
  226. * @return object
  227. */
  228. protected function buildLibForCreateLib()
  229. {
  230. $this->lang->doc->name = $this->lang->doclib->name;
  231. $lib = form::data()
  232. ->setDefault('addedBy', $this->app->user->account)
  233. ->setIF($this->post->type == 'product' && !empty($_POST['product']), 'product', $this->post->product)
  234. ->setIF($this->post->type == 'project' && !empty($_POST['project']), 'project', $this->post->project)
  235. ->setIF($this->post->libType != 'api' && !empty($_POST['execution']), 'execution', $this->post->execution)
  236. ->get();
  237. return $lib;
  238. }
  239. /**
  240. * 在创建文档库后的返回。
  241. * Return after create a document library.
  242. *
  243. * @param string $type api|project|product|execution|custom|mine
  244. * @param int $objectID
  245. * @param int $libID
  246. * @access protected
  247. * @return bool|int
  248. * @param string $libName
  249. * @param string $orderBy
  250. */
  251. protected function responseAfterCreateLib($type = '', $objectID = 0, $libID = 0, $libName = '', $orderBy = '')
  252. {
  253. if($type == 'project' && $this->post->project) $objectID = $this->post->project;
  254. if($type == 'product' && $this->post->product) $objectID = $this->post->product;
  255. if($type == 'execution' && $this->post->execution)
  256. {
  257. if($this->post->execution != $objectID) $diffExecution = true;
  258. $objectID = $this->post->execution;
  259. }
  260. $type = $type == 'execution' && $this->app->tab != 'execution' ? 'project' : $type;
  261. $this->action->create('docLib', $libID, 'Created');
  262. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $libID));
  263. $lib = array('id' => $libID, 'name' => $libName, 'space' => (int)$objectID, 'orderBy' => $orderBy, 'order' => $libID);
  264. if(isset($diffExecution) && $diffExecution === true)
  265. {
  266. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true));
  267. }
  268. $docAppActions = array();
  269. $docAppActions[] = array('update', 'lib', $lib);
  270. $docAppActions[] = array('selectSpace', $objectID, $libID);
  271. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => array('name' => 'locateNewLib', 'params' => array($type, $objectID, $libID, $libName)), 'docApp' => $docAppActions));
  272. }
  273. /**
  274. * 处理编辑文档库的访问控制。
  275. * Handle the access control of editing document library.
  276. *
  277. * @param object $lib
  278. * @access protected
  279. * @return void
  280. */
  281. protected function setAclForEditLib($lib)
  282. {
  283. $libType = $lib->type;
  284. if($libType == 'custom')
  285. {
  286. unset($this->lang->doclib->aclList['default']);
  287. }
  288. elseif($libType == 'api')
  289. {
  290. $this->app->loadLang('api');
  291. $type = !empty($lib->product) ? 'product' : 'project';
  292. $this->lang->api->aclList['default'] = sprintf($this->lang->api->aclList['default'], $this->lang->{$type}->common);
  293. }
  294. elseif($libType == 'mine')
  295. {
  296. $this->lang->doclib->aclList = $this->lang->doclib->mySpaceAclList;
  297. }
  298. elseif($libType != 'custom')
  299. {
  300. $type = isset($type) ? $type : $libType;
  301. $this->lang->doclib->aclList['default'] = sprintf($this->lang->doclib->aclList['default'], $this->lang->{$type}->common);
  302. $this->lang->doclib->aclList['private'] = sprintf($this->lang->doclib->privateACL, $this->lang->{$type}->common);
  303. unset($this->lang->doclib->aclList['open']);
  304. }
  305. if(!empty($lib->main) && $libType != 'mine') unset($this->lang->doclib->aclList['private'], $this->lang->doclib->aclList['open']);
  306. }
  307. /**
  308. * 检查创建文档库的权限。
  309. * Check the privilege of creating document.
  310. *
  311. * @param object $doclib
  312. * @param string $objectType product|project|execution|custom
  313. * @access protected
  314. * @return bool
  315. */
  316. protected function checkPrivForCreate($doclib, $objectType)
  317. {
  318. $canVisit = true;
  319. if(!empty($doclib->groups)) $groupAccounts = $this->loadModel('group')->getGroupAccounts(explode(',', $doclib->groups));
  320. switch($objectType)
  321. {
  322. case 'custom':
  323. $account = (string)$this->app->user->account;
  324. if(($doclib->acl == 'custom' || $doclib->acl == 'private') && strpos($doclib->users, $account) === false && $doclib->addedBy !== $account && !(isset($groupAccounts) && in_array($account, $groupAccounts, true)) && !$this->app->user->admin) $canVisit = false;
  325. break;
  326. case 'product':
  327. $canVisit = $this->loadModel('product')->checkPriv($doclib->product);
  328. break;
  329. case 'project':
  330. $canVisit = $this->loadModel('project')->checkPriv($doclib->project);
  331. break;
  332. case 'execution':
  333. $canVisit = $this->loadModel('execution')->checkPriv($doclib->execution);
  334. break;
  335. default:
  336. break;
  337. }
  338. return $canVisit;
  339. }
  340. /**
  341. * 在创建文档后的返回。
  342. * Return after create a document.
  343. *
  344. * @param array $docResult
  345. * @access protected
  346. * @return void
  347. * @param string $objectType
  348. */
  349. protected function responseAfterCreate($docResult, $objectType = 'doc')
  350. {
  351. $docID = $docResult['id'];
  352. $files = zget($docResult, 'files', '');
  353. $fileAction = '';
  354. if(!empty($files)) $fileAction = $this->lang->addFiles . implode(',', $files) . "\n";
  355. $this->action->create($objectType, $docID, 'Created', $fileAction, '', '', false);
  356. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $docID));
  357. $response = array(
  358. 'result' => 'success',
  359. 'message' => $this->lang->saveSuccess,
  360. 'load' => $this->createLink('doc', $objectType == 'doc' ? 'view' : 'browseTemplate', "docID={$docResult['id']}"),
  361. 'id' => $docID,
  362. 'doc' => $docResult
  363. );
  364. return $this->send($response);
  365. }
  366. /**
  367. * 在移动库或文档后的返回。
  368. * Return after move lib or doc.
  369. *
  370. * @param string $space
  371. * @param int $libID
  372. * @param int $docID
  373. * @param bool $spaceTypeChanged
  374. *
  375. * @access protected
  376. * @return void
  377. */
  378. protected function responseAfterMove($space, $libID = 0, $docID = 0, $spaceTypeChanged = false)
  379. {
  380. list($spaceType, $spaceID) = explode('.', $space);
  381. if($docID)
  382. {
  383. $docAppAction = array('executeCommand', 'handleMovedDoc', array($docID, $spaceID, $libID));
  384. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'docApp' => $docAppAction));
  385. }
  386. if($spaceTypeChanged)
  387. {
  388. $method = 'mySpace';
  389. if($spaceType == 'custom') $method = 'teamSpace';
  390. if($spaceType == 'product') $method = 'productSpace';
  391. if($spaceType == 'project') $method = 'projectSpace';
  392. $locateLink = $this->createLink('doc', $method, "objectID={$spaceID}&libID={$libID}");
  393. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => $locateLink));
  394. }
  395. else
  396. {
  397. $docAppAction = array('selectSpace', $spaceID, $libID);
  398. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'docApp' => $docAppAction));
  399. }
  400. }
  401. /**
  402. * 为创建文档设置所属对象下拉值。
  403. * Set the dropdown values of object for creating document.
  404. *
  405. * @param string $linkType product|project|execution|custom
  406. * @param object|null $lib
  407. * @param string $unclosed
  408. * @param int $objectID
  409. * @access protected
  410. * @return void
  411. */
  412. protected function setObjectsForCreate($linkType, $lib, $unclosed, $objectID)
  413. {
  414. if(!empty($objectID))
  415. {
  416. $object = $this->loadModel('project')->fetchByID((int)$objectID);
  417. if(!empty($object->isTpl)) dao::$filterTpl = 'never';
  418. }
  419. $objects = array();
  420. if($linkType == 'project')
  421. {
  422. $objects = $this->project->getPairsByProgram(0, 'all', false, 'order_asc');
  423. $this->view->executions = $this->execution->getPairs($objectID, 'all', 'multiple,leaf,noprefix');
  424. if(!empty($lib) && $lib->type == 'execution')
  425. {
  426. $execution = $this->loadModel('execution')->getByID($lib->execution);
  427. $objectID = $execution->project;
  428. $libs = $this->doc->getLibs('execution', "withObject,{$unclosed}", $lib->id, $lib->execution);
  429. $this->view->execution = $execution;
  430. }
  431. }
  432. elseif($linkType == 'execution')
  433. {
  434. $execution = $this->loadModel('execution')->getById($lib->execution);
  435. $objects = $this->execution->getPairs($execution->project, 'all', "multiple,leaf,noprefix");
  436. }
  437. elseif($linkType == 'product' || $linkType == 'api')
  438. {
  439. $objects = $this->loadModel('product')->getPairs();
  440. }
  441. elseif($linkType == 'mine')
  442. {
  443. $this->lang->doc->aclList = $this->lang->doclib->mySpaceAclList;
  444. }
  445. $this->view->objects = $objects;
  446. }
  447. /**
  448. * 在上传文件后的返回。
  449. * Return after upload files.
  450. *
  451. * @param array|string $docResult
  452. * @access protected
  453. * @return bool|int
  454. */
  455. protected function responseAfterUploadDocs($docResult)
  456. {
  457. if(!$docResult || dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  458. $this->loadModel('action');
  459. if($this->post->uploadFormat == 'combinedDocs')
  460. {
  461. $docID = $docResult['id'];
  462. $files = zget($docResult, 'files', '');
  463. $fileAction = '';
  464. if(!empty($files)) $fileAction = $this->lang->addFiles . implode(',', $files) . "\n";
  465. $this->action->create('doc', $docID, 'created', $fileAction);
  466. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $docID));
  467. $params = "docID=" . $docResult['id'];
  468. $link = isInModal() ? true : $this->createLink('doc', 'view', $params);
  469. }
  470. else
  471. {
  472. $docsAction = zget($docResult, 'docsAction', '');
  473. if(!empty($docsAction))
  474. {
  475. foreach($docsAction as $docID => $fileTitle)
  476. {
  477. $fileAction = $this->lang->addFiles . $fileTitle->title . "\n";
  478. $this->action->create('doc', $docID, 'created', $fileAction);
  479. }
  480. }
  481. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
  482. $link = true;
  483. }
  484. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link, 'closeModal' => true, 'docApp' => array('load', null, null, null, array('noLoading' => true, 'picks' => 'doc'))));
  485. }
  486. /**
  487. * 展示创建文档的相关变量。
  488. * Show the related variables of create.
  489. *
  490. * @param string $objectType product|project|execution|custom
  491. * @param int $objectID
  492. * @param int $libID
  493. * @param int $moduleID
  494. * @param string $docType html|word|ppt|excel|attachment
  495. * @access protected
  496. * @return void
  497. */
  498. protected function assignVarsForCreate($objectType, $objectID, $libID, $moduleID = 0, $docType = '')
  499. {
  500. $lib = $libID ? $this->doc->getLibByID($libID) : '';
  501. if(empty($objectID) && $lib) $objectID = zget($lib, $lib->type, 0);
  502. if(empty($objectID) && $lib && $lib->type == 'custom') $objectID = $lib->parent;
  503. /* Get libs and the default lib ID. */
  504. $unclosed = strpos($this->config->doc->custom->showLibs, 'unclosed') !== false ? 'unclosedProject' : '';
  505. $libPairs = $this->doc->getLibs($objectType, "{$unclosed}", $libID, $objectID);
  506. $moduleID = $moduleID ? (int)$moduleID : (int)$this->cookie->lastDocModule;
  507. if(!$libID && !empty($libPairs)) $libID = key($libPairs);
  508. if(empty($lib) && $libID) $lib = $this->doc->getLibByID($libID);
  509. $this->setObjectsForCreate(empty($lib->type) ? '' : $lib->type, empty($lib) ? null : $lib, $unclosed, $objectID);
  510. $this->view->objectType = $objectType;
  511. $this->view->spaceType = $objectType;
  512. $this->view->type = $objectType;
  513. $this->view->libID = $libID;
  514. $this->view->lib = $lib;
  515. $this->view->objectID = $objectID;
  516. $this->view->libs = $libPairs;
  517. $this->view->libName = zget($lib, 'name', '');
  518. $this->view->moduleID = $moduleID;
  519. $this->view->docType = $docType;
  520. $this->view->groups = $this->loadModel('group')->getPairs();
  521. $this->view->users = $this->user->getPairs('nocode|noclosed|nodeleted');
  522. $this->view->optionMenu = empty($libID) ? array() : $this->loadModel('tree')->getOptionMenu($libID, 'doc', 0);
  523. }
  524. /**
  525. * 展示上传文件的相关变量。
  526. * Show the related variables of uploading files.
  527. *
  528. * @param int $docID
  529. * @param string $objectType product|project|execution|custom
  530. * @param int $objectID
  531. * @param int $libID
  532. * @param int $moduleID
  533. * @param string $docType html|word|ppt|excel|attachment
  534. * @access protected
  535. * @return object
  536. */
  537. protected function assignVarsForUploadDocs($docID, $objectType, $objectID, $libID, $moduleID = 0, $docType = '')
  538. {
  539. $doc = !empty($docID) ? $this->doc->getByID($docID) : null;
  540. if(empty($moduleID) && $doc) $moduleID = (int)$doc->module;
  541. $this->assignVarsForCreate($objectType, $objectID, $libID, $moduleID, $docType);
  542. $lib = $libID ? $this->doc->getLibByID($libID) : '';
  543. $chapterAndDocs = $this->doc->getDocsOfLibs(array($libID), $objectType, $docID);
  544. $modulePairs = empty($libID) ? array() : $this->loadModel('tree')->getOptionMenu($libID, 'doc', 0);
  545. if(isset($doc) && !empty($doc->parent) && !isset($chapterAndDocs[$doc->parent])) $chapterAndDocs[$doc->parent] = $this->doc->fetchByID($doc->parent);
  546. $chapterAndDocs = $this->doc->buildNestedDocs($chapterAndDocs, $modulePairs);
  547. $this->view->title = empty($lib) ? '' : zget($lib, 'name', '', $lib->name . $this->lang->hyphen) . $this->lang->doc->uploadDoc;
  548. $this->view->linkType = $objectType;
  549. $this->view->spaces = ($objectType == 'mine' || $objectType == 'custom') ? $this->doc->getSubSpacesByType($objectType, false) : array();
  550. $this->view->optionMenu = $chapterAndDocs;
  551. $this->view->docID = $docID;
  552. $this->view->doc = $doc;
  553. return $this->view;
  554. }
  555. /**
  556. * 为编辑文档设置所属对象下拉值。
  557. * Set the dropdown values of object for creating document.
  558. *
  559. * @param string $objectType product|project|execution|custom
  560. * @param int $objectID
  561. * @access protected
  562. * @return void
  563. */
  564. protected function setObjectsForEdit($objectType, $objectID)
  565. {
  566. $objects = array();
  567. if($objectType == 'project')
  568. {
  569. $objects = $this->project->getPairsByProgram(0, 'all', false, 'order_asc');
  570. }
  571. elseif($objectType == 'execution')
  572. {
  573. $execution = $this->loadModel('execution')->getByID($objectID);
  574. $objects = $this->execution->getPairs($execution->project, 'all', "multiple,leaf,noprefix");
  575. $parentExecutions = $childExecutions = array();
  576. $executions = $this->execution->fetchExecutionList($execution->project, 'all', 0, 0, 'order_asc');
  577. foreach($executions as $execution)
  578. {
  579. if($execution->grade == 1) $parentExecutions[$execution->id] = $execution;
  580. if($execution->grade > 1 && $execution->parent) $childExecutions[$execution->parent][$execution->id] = $execution;
  581. }
  582. $objects = $this->execution->resetExecutionSorts($objects, $parentExecutions, $childExecutions);
  583. }
  584. elseif($objectType == 'product')
  585. {
  586. $objects = $this->loadModel('product')->getPairs();
  587. }
  588. elseif($objectType == 'mine')
  589. {
  590. $this->lang->doc->aclList = $this->lang->doclib->mySpaceAclList;
  591. }
  592. $this->view->objects = $objects;
  593. }
  594. /**
  595. * 在编辑文档后的返回。
  596. * Return after edit a document.
  597. *
  598. * @param object $doc
  599. * @param array $changes
  600. * @param array $files
  601. * @param array $deletedFiles
  602. * @access protected
  603. * @return array
  604. */
  605. protected function responseAfterEdit($doc, $changes = array(), $files = array(), $deletedFiles = array())
  606. {
  607. if($this->post->comment != '' || !empty($changes) || !empty($files) || !empty($deletedFiles))
  608. {
  609. $action = 'Commented';
  610. if(!empty($changes))
  611. {
  612. $newType = $_POST['status'];
  613. if($doc->status == 'draft' && $newType == 'normal') $action = 'releasedDoc';
  614. if($changes || $doc->status == $newType || $newType == 'normal') $action = 'Edited';
  615. }
  616. if(!empty($deletedFiles)) $deletedFiles = $this->dao->select('id,title')->from(TABLE_FILE)->where('id')->in($deletedFiles)->fetchPairs();
  617. $fileAction = '';
  618. if(!empty($files)) $fileAction .= $this->lang->addFiles . implode(',', $files) . "\n";
  619. if(!empty($deletedFiles)) $fileAction .= $this->lang->delFiles . implode(',', $deletedFiles) . "\n";
  620. if(!empty($changes))
  621. {
  622. $actionID = $this->action->create('doc', $doc->id, $action, $fileAction . $this->post->comment, '', '', false);
  623. $this->action->logHistory($actionID, $changes);
  624. }
  625. }
  626. $link = $this->createLink('doc', 'view', "docID={$doc->id}");
  627. $doc = $this->doc->getByID($doc->id);
  628. $lib = $this->doc->getLibByID((int)$doc->lib);
  629. $objectID = zget($lib, $lib->type, 0);
  630. if(!$this->doc->checkPrivDoc($doc))
  631. {
  632. $moduleName = 'doc';
  633. if($this->app->tab == 'execution')
  634. {
  635. $moduleName = 'execution';
  636. $methodName = 'doc';
  637. }
  638. else
  639. {
  640. $methodName = zget($this->config->doc->spaceMethod, $lib->type);
  641. }
  642. $params = "objectID={$objectID}&libID={$doc->lib}";
  643. $link = $this->createLink($moduleName, $methodName, $params);
  644. }
  645. if(isInModal()) return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link);
  646. $doc->isCollector = strpos($doc->collector, ',' . $this->app->user->account . ',') !== false;
  647. return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link, 'doc' => $doc);
  648. }
  649. /**
  650. * 在编辑文档后的返回。
  651. * Return after edit a document.
  652. *
  653. * @param object $doc
  654. * @param array $changes
  655. * @param array $files
  656. * @access protected
  657. * @return void
  658. */
  659. protected function responseAfterEditTemplate($doc, $changes = array(), $files = array())
  660. {
  661. if($this->post->comment != '' || !empty($changes) || !empty($files))
  662. {
  663. $action = 'Commented';
  664. if(!empty($changes))
  665. {
  666. $newType = $_POST['status'];
  667. if($doc->status == 'draft' && $newType == 'normal') $action = 'releasedDoc';
  668. if($doc->status == 'normal' && $newType == 'draft') $action = 'savedDraft';
  669. if($doc->status == $newType) $action = 'Edited';
  670. }
  671. $fileAction = '';
  672. if(!empty($files)) $fileAction = $this->lang->addFiles . implode(',', $files) . "\n";
  673. $actionID = $this->action->create('docTemplate', $doc->id, $action, $fileAction . $this->post->comment);
  674. if(!empty($changes) && !empty($actionID)) $this->action->logHistory($actionID, $changes);
  675. }
  676. $link = $this->createLink('doc', 'view', "docID={$doc->id}");
  677. $doc = $this->doc->getByID($doc->id);
  678. if(isInModal()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  679. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link, 'doc' => $doc));
  680. }
  681. /**
  682. * 处理文档大纲。
  683. *
  684. * @param object $doc
  685. * @access protected
  686. * @return object
  687. */
  688. protected function processOutline($doc)
  689. {
  690. /* Split content into an array. */
  691. $content = preg_replace('/(<(h[1-6])[\S\s]*?\>[\S\s]*?<\/\2>)/', "\$1\n", $doc->content);
  692. $content = explode("\n", $content);
  693. /* Get the head element, for example h1,h2,etc. */
  694. $includeHeadElement = array();
  695. foreach($content as $index => $element)
  696. {
  697. preg_match('/<(h[1-6])([\S\s]*?)>([\S\s]*?)<\/\1>/', $element, $headElement);
  698. if(isset($headElement[1]) && !in_array($headElement[1], $includeHeadElement) && strip_tags($headElement[3]) != '') $includeHeadElement[] = $headElement[1];
  699. }
  700. /* Get the two elements with the highest rank. */
  701. sort($includeHeadElement);
  702. if($includeHeadElement)
  703. {
  704. $topLevel = (int)ltrim($includeHeadElement[0], 'h');
  705. $outlineList = $this->buildOutlineList($topLevel, $content, $includeHeadElement);
  706. $outlineTree = $this->buildOutlineTree($outlineList);
  707. $this->view->outlineTree = $outlineTree;
  708. foreach($content as $index => $element)
  709. {
  710. preg_match('/<(h[1-6])([\S\s]*?)>([\S\s]*?)<\/\1>/', $element, $headElement);
  711. /* The current element is existed, the element is in the includeHeadElement, && the text in the element is not null. */
  712. if(isset($headElement[1]) && in_array($headElement[1], $includeHeadElement) && strip_tags($headElement[3]) != '')
  713. {
  714. $content[$index] = str_replace('<' . $headElement[1] . $headElement[2] . '>', '<' . $headElement[1] . $headElement[2] . " id='anchor{$index}'" . '>', $content[$index]);
  715. }
  716. }
  717. $doc->content = implode("\n", $content);
  718. }
  719. return $doc;
  720. }
  721. /**
  722. * 展示文档详情相关变量。
  723. *
  724. * @param int $docID
  725. * @param int $version
  726. * @param string $type
  727. * @param int $objectID
  728. * @param int $libID
  729. * @param object $doc
  730. * @param object $object
  731. * @param string $objectType
  732. * @param array $libs
  733. * @param array $objectDropdown
  734. * @access protected
  735. * @return void
  736. */
  737. protected function assignVarsForView($docID, $version, $type, $objectID, $libID, $doc, $object, $objectType, $libs, $objectDropdown)
  738. {
  739. if($type == 'execution' && $this->app->tab == 'project')
  740. {
  741. $objectType = 'project';
  742. $objectID = $object->project;
  743. }
  744. $this->view->title = $this->lang->doc->common . $this->lang->hyphen . $doc->title;
  745. $this->view->docID = $docID;
  746. $this->view->type = $type;
  747. $this->view->objectID = $objectID;
  748. $this->view->libID = $libID;
  749. $this->view->doc = $doc;
  750. $this->view->version = $version;
  751. $this->view->object = $object;
  752. $this->view->objectType = $objectType;
  753. $this->view->lib = isset($libs[$libID]) ? $libs[$libID] : new stdclass();
  754. $this->view->libs = $libs;
  755. $this->view->canBeChanged = common::canModify($type, $object); // Determines whether an object is editable.
  756. $this->view->actions = $docID ? $this->action->getList('doc', $docID) : array();
  757. $this->view->users = $this->loadModel('user')->getPairs('noclosed,noletter');
  758. $this->view->libTree = $this->doc->getLibTree((int)$libID, (array)$libs, $objectType, (int)$doc->module, (int)$objectID, 'all', 0, $docID);
  759. $this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('doc', $docID);
  760. $this->view->moduleID = $doc->module;
  761. $this->view->objectDropdown = $objectDropdown;
  762. $this->view->canExport = ($this->config->edition != 'open' && common::hasPriv('doc', $type . '2export'));
  763. $this->view->exportMethod = $type . '2export';
  764. $this->view->editors = $this->doc->getEditors($docID);
  765. $this->view->linkParams = "objectID={$objectID}&%s&browseType=&orderBy=status,id_desc&param=0";
  766. $this->view->spaceType = $objectType;
  767. $this->view->productID = $doc->product;
  768. $this->view->projectID = $doc->project;
  769. $this->view->executionID = $doc->execution;
  770. }
  771. /**
  772. * 设置空间页面的Cookie和Session。
  773. * Set the cookie and session of the space page.
  774. *
  775. * @param string $type custom|product|project|execution
  776. * @param string $browseType all|draft|bysearch
  777. * @param int $objectID
  778. * @param int $libID
  779. * @param int $moduleID
  780. * @param int $param
  781. * @access protected
  782. * @return void
  783. */
  784. protected function setSpacePageStorage($type, $browseType, $objectID, $libID, $moduleID, $param)
  785. {
  786. $uri = $this->app->getURI(true);
  787. $this->session->set('createProjectLocate', $uri, 'doc');
  788. $this->session->set('structList', $uri, 'doc');
  789. $this->session->set('spaceType', $type, 'doc');
  790. $this->session->set('docList', $uri, 'doc');
  791. $docSpaceParam = new stdclass();
  792. $docSpaceParam->type = $type;
  793. $docSpaceParam->objectID = $objectID;
  794. $docSpaceParam->libID = $libID;
  795. $docSpaceParam->moduleID = $moduleID;
  796. $docSpaceParam->browseType = $browseType;
  797. $docSpaceParam->param = $param;
  798. setCookie("docSpaceParam", json_encode($docSpaceParam), $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true);
  799. }
  800. /**
  801. * 展示空间相关api变量。
  802. * Show space related api variables.
  803. *
  804. * @param string $type custom|product|project|execution
  805. * @param string $browseType all|draft|bysearch
  806. * @param string $libType
  807. * @param int $libID
  808. * @param array $libs
  809. * @param int $objectID
  810. * @param int $moduleID
  811. * @param int $queryID
  812. * @param string $orderBy
  813. * @param int $recTotal
  814. * @param int $recPerPage
  815. * @param int $pageID
  816. * @access protected
  817. * @return void
  818. * @param int $param
  819. */
  820. protected function assignApiVarForSpace($type, $browseType, $libType, $libID, $libs, $objectID, $moduleID, $queryID, $orderBy, $param, $recTotal = 0, $recPerPage = 20, $pageID = 1)
  821. {
  822. /* Load pager. */
  823. $this->app->loadClass('pager', true);
  824. $pager = new pager($recTotal, $recPerPage, $pageID);
  825. if($libType == 'api')
  826. {
  827. $this->loadModel('api');
  828. $this->session->set('objectName', $this->lang->doc->api, 'doc');
  829. $this->view->libs = $libs;
  830. $this->view->apiID = 0;
  831. $this->view->release = 0;
  832. $this->view->apiList = $browseType == 'bySearch' ? $this->api->getApiListBySearch($libID, $queryID, $type, array_keys($libs)) : $this->api->getListByModuleId($libID, $moduleID, $param, $pager);
  833. }
  834. else
  835. {
  836. if(in_array($type, array('product', 'project'))) $this->session->set('objectName', $this->lang->doc->common, 'doc');
  837. $this->view->docs = $browseType == 'bySearch' ? $this->doc->getDocsBySearch($type, $objectID, $libID, $queryID, $orderBy, $pager) : $this->doc->getDocs($libID, $moduleID, $browseType, $orderBy, $pager);
  838. }
  839. $apiObjectType = $type == 'product' || $type == 'project' ? $type : '';
  840. $apiObjectID = $apiObjectType ? $objectID : 0;
  841. $apiLibs = $apiObjectType ? $this->doc->getApiLibs(0, $apiObjectType, $apiObjectID) : array();
  842. $canExport = $libType == 'api' ? common::hasPriv('api', 'export') : common::hasPriv('doc', $type . '2export');
  843. if($this->config->edition == 'open') $canExport = false;
  844. $this->view->canExport = $canExport;
  845. $this->view->apiLibID = key($apiLibs);
  846. $this->view->pager = $pager;
  847. }
  848. /**
  849. * 构建附件库的搜索表单
  850. * Build search form for showFiles.
  851. *
  852. * @param string $type product|project|execution
  853. * @param int $objectID
  854. * @param string $viewType
  855. * @param int $param
  856. * @access public
  857. * @return void
  858. */
  859. public function buildSearchFormForShowFiles($type, $objectID, $viewType = '', $param = 0)
  860. {
  861. $this->loadModel('file');
  862. $actionURL = $this->createLink($this->app->rawModule, $this->app->rawMethod, "type={$type}&objectID={$objectID}&viewType={$viewType}&browseType=bySearch&queryID=myQueryID");
  863. $objectTypeList = array();
  864. if($type == 'product')
  865. {
  866. $objectTypeList['product'] = $this->lang->product->common;
  867. $objectTypeList['story'] = $this->lang->doc->story;
  868. $objectTypeList['productplan'] = $this->lang->productplan->shortCommon;
  869. $objectTypeList['release'] = $this->lang->release->common;
  870. }
  871. if($type == 'project')
  872. {
  873. $objectTypeList['project'] = $this->lang->project->common;
  874. $objectTypeList['design'] = $this->lang->design->common;
  875. $objectTypeList['review'] = $this->lang->review->common;
  876. if(isset($this->lang->issue->common)) $objectTypeList['issue'] = $this->lang->issue->common;
  877. if(isset($this->lang->meeting->common)) $objectTypeList['meeting'] = $this->lang->meeting->common;
  878. }
  879. if($type == 'project' || $type == 'execution')
  880. {
  881. $objectTypeList['execution'] = $this->lang->execution->common;
  882. $objectTypeList['task'] = $this->lang->task->common;
  883. $objectTypeList['story'] = $this->lang->doc->story;
  884. $objectTypeList['build'] = $this->lang->build->common;
  885. $objectTypeList['testtask'] = $this->lang->testtask->common;
  886. }
  887. $objectTypeList['bug'] = $this->lang->bug->common;
  888. $objectTypeList['testcase'] = $this->lang->case->common;
  889. $objectTypeList['testreport'] = $this->lang->testreport->common;
  890. $objectTypeList['doc'] = $this->lang->doc->common;
  891. $this->config->file->search['params']['objectType']['values'] = $objectTypeList;
  892. $this->config->file->search['module'] = "{$type}DocFile";
  893. $this->config->file->search['onMenuBar'] = 'no';
  894. $this->config->file->search['queryID'] = (int)$param;
  895. $this->config->file->search['actionURL'] = $actionURL;
  896. $this->loadModel('search')->setSearchParams($this->config->file->search);
  897. }
  898. /**
  899. * 初始化我的空间的文档库。
  900. * Init Lib for mySpace.
  901. *
  902. * @access public
  903. * @return void
  904. */
  905. public function initLibForMySpace()
  906. {
  907. $systemMineLibCount = $this->dao->select('count(1) as count')->from(TABLE_DOCLIB)
  908. ->where('type')->eq('mine')
  909. ->andWhere('main')->eq(1)
  910. ->andWhere('addedBy')->eq($this->app->user->account)
  911. ->andWhere('vision')->eq($this->config->vision)
  912. ->fetch('count');
  913. if(!empty($systemMineLibCount)) return;
  914. $mineLib = new stdclass();
  915. $mineLib->type = 'mine';
  916. $mineLib->vision = $this->config->vision;
  917. $mineLib->name = $this->lang->doclib->defaultSpace;
  918. $mineLib->main = '1';
  919. $mineLib->acl = 'private';
  920. $mineLib->addedBy = $this->app->user->account;
  921. $mineLib->addedDate = helper::now();
  922. $this->dao->insert(TABLE_DOCLIB)->data($mineLib)->exec();
  923. }
  924. /**
  925. * 初始化团队空间的文档库。
  926. * Init Lib for teamSpace.
  927. *
  928. * @access public
  929. * @return void
  930. */
  931. public function initLibForTeamSpace()
  932. {
  933. $customLibCount = $this->dao->select('count(1) as count')->from(TABLE_DOCLIB)
  934. ->where('type')->eq('custom')
  935. ->andWhere('vision')->eq($this->config->vision)
  936. ->fetch('count');
  937. if(!empty($customLibCount)) return;
  938. $teamLib = new stdclass();
  939. $teamLib->type = 'custom';
  940. $teamLib->vision = $this->config->vision;
  941. $teamLib->name = $this->lang->doclib->defaultSpace;
  942. $teamLib->acl = 'open';
  943. $teamLib->addedBy = $this->app->user->account;
  944. $teamLib->addedDate = helper::now();
  945. $this->dao->insert(TABLE_DOCLIB)->data($teamLib)->exec();
  946. }
  947. /**
  948. * 获取所有空间。
  949. * Get all spaces.
  950. *
  951. * @param string $extra nomine|onlymine
  952. * @access public
  953. * @return array
  954. */
  955. public function getAllSpaces($extra = '')
  956. {
  957. if(strpos($extra, 'doctemplate') !== false) return $this->doc->getDocTemplateSpaces();
  958. if(strpos($extra, 'nomine') !== false) return $this->doc->getTeamSpaces();
  959. if(strpos($extra, 'onlymine') !== false) return array('mine' => $this->lang->doc->spaceList['mine']);
  960. return array('mine' => $this->lang->doc->spaceList['mine']) + $this->doc->getTeamSpaces();
  961. }
  962. /**
  963. * Record batch move actions.
  964. *
  965. * @param array $oldDocList
  966. * @param object $data
  967. * @access public
  968. * @return void
  969. */
  970. public function recordBatchMoveActions($oldDocList, $data)
  971. {
  972. $this->loadModel('action');
  973. foreach($oldDocList as $oldDoc)
  974. {
  975. $actionID = $this->action->create('doc', $oldDoc->id, 'Moved', '', json_encode(array('from' => $oldDoc->lib, 'to' => $data->lib)));
  976. $changes = common::createChanges($oldDoc, $data);
  977. $this->action->logHistory($actionID, $changes);
  978. }
  979. }
  980. /**
  981. * 在创建版本类型后的返回。
  982. * Return after create a template type.
  983. *
  984. * @param int $scope
  985. * @access public
  986. * @return string
  987. */
  988. public function responseAfterAddTemplateType($scope)
  989. {
  990. $response = array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true);
  991. return $this->send($response);
  992. }
  993. /**
  994. * 从session中获取数据。
  995. * Get data from session.
  996. *
  997. * @param string $type
  998. * @access public
  999. * @return array
  1000. */
  1001. protected function formFromSession($type)
  1002. {
  1003. $sessionName = 'zentaoList' . $type;
  1004. $session = array();
  1005. if(isset($_SESSION[$sessionName]))
  1006. {
  1007. $session = $_SESSION[$sessionName];
  1008. unset($_SESSION[$sessionName]);
  1009. }
  1010. $url = zget($session, 'url', '');
  1011. $idList = zget($session, 'idList', '');
  1012. $cols = zget($session, 'cols', array());
  1013. $data = zget($session, 'data', array());
  1014. return array($url, $idList, $cols, $data);
  1015. }
  1016. /**
  1017. * 处理表格列配置。
  1018. * Handle table column config.
  1019. *
  1020. * @access protected
  1021. * @return void
  1022. */
  1023. protected function prepareCols()
  1024. {
  1025. $cols = $this->view->cols;
  1026. if(isset($cols['actions'])) unset($cols['actions']);
  1027. foreach($cols as $key => $col)
  1028. {
  1029. $cols[$key]['name'] = $key;
  1030. $cols[$key]['sortType'] = false;
  1031. if(isset($col['link'])) unset($cols[$key]['link']);
  1032. if(isset($col['nestedToggle'])) unset($cols[$key]['nestedToggle']);
  1033. }
  1034. $this->view->cols = $cols;
  1035. }
  1036. /**
  1037. * 预览反馈列表。
  1038. * Preview feedback list.
  1039. *
  1040. * @param string $view
  1041. * @param array $settings
  1042. * @param string $idList
  1043. * @access protected
  1044. * @return void
  1045. */
  1046. protected function previewFeedback($view, $settings, $idList)
  1047. {
  1048. $cols = $this->loadModel('datatable')->getSetting('feedback', 'browse');
  1049. $data = array();
  1050. $action = $settings['action'];
  1051. if($action === 'preview' && $view === 'setting')
  1052. {
  1053. $product = (int)$settings['product'];
  1054. $condition = $settings['condition'];
  1055. $tmpProduct = isset($_SESSION['feedbackProduct']) ? $_SESSION['feedbackProduct'] : false;
  1056. $_SESSION['feedbackProduct'] = $product;
  1057. if($condition == 'customSearch')
  1058. {
  1059. $where = "`product`=$product";
  1060. foreach($settings['field'] as $index => $field)
  1061. {
  1062. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1063. }
  1064. $data = $this->dao->select('*')->from(TABLE_FEEDBACK)->where($where)->fetchAll('', false);
  1065. }
  1066. else
  1067. {
  1068. $data = $this->loadModel('feedback')->getList($condition);
  1069. }
  1070. if(is_bool($tmpProduct) && !$tmpProduct) unset($_SESSION['feedbackProduct']);
  1071. else $_SESSION['feedbackProduct'] = $tmpProduct;
  1072. }
  1073. elseif($view === 'list')
  1074. {
  1075. $data = $this->loadModel('feedback')->getByList($idList);
  1076. }
  1077. $this->view->cols = $cols;
  1078. $this->view->data = $data;
  1079. }
  1080. /**
  1081. * 预览工单列表。
  1082. * Preview ticket list.
  1083. *
  1084. * @param string $view
  1085. * @param array $settings
  1086. * @param string $idList
  1087. * @access protected
  1088. * @return void
  1089. */
  1090. protected function previeweicket($view, $settings, $idList)
  1091. {
  1092. $cols = $this->loadModel('datatable')->getSetting('ticket', 'browse');
  1093. $data = array();
  1094. $action = $settings['action'];
  1095. if($action === 'preview' && $view === 'setting')
  1096. {
  1097. $tmpProduct = isset($_SESSION['ticketProduct']) ? $_SESSION['ticketProduct'] : false;
  1098. $tmpType = isset($_SESSION['browseType']) ? $_SESSION['browseType'] : false;
  1099. $_SESSION['ticketProduct'] = (int)$settings['product'];
  1100. $_SESSION['browseType'] = 'byProduct';
  1101. $product = (int)$settings['product'];
  1102. $condition = $settings['condition'];
  1103. if($condition == 'customSearch')
  1104. {
  1105. $where = "`product`=$product";
  1106. foreach($settings['field'] as $index => $field)
  1107. {
  1108. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1109. }
  1110. $data = $this->dao->select('*')->from(TABLE_TICKET)->where($where)->fetchAll('', false);
  1111. }
  1112. else
  1113. {
  1114. $data = $this->loadModel('ticket')->getList($condition);
  1115. }
  1116. if(is_bool($tmpProduct) && !$tmpProduct) unset($_SESSION['ticketProduct']);
  1117. else $_SESSION['ticketProduct'] = $tmpProduct;
  1118. if(is_bool($tmpType) && !$tmpType) unset($_SESSION['browseType']);
  1119. else $_SESSION['browseType'] = $tmpType;
  1120. }
  1121. elseif($view === 'list')
  1122. {
  1123. $data = $this->loadModel('ticket')->getByList($idList);
  1124. }
  1125. $this->view->cols = $cols;
  1126. $this->view->data = $data;
  1127. }
  1128. /**
  1129. * 预览产品计划列表。
  1130. * Preview plan list.
  1131. *
  1132. * @param string $view
  1133. * @param array $settings
  1134. * @param string $idList
  1135. * @access protected
  1136. * @return void
  1137. */
  1138. protected function previewProductplan($view, $settings, $idList)
  1139. {
  1140. $cols = $this->loadModel('datatable')->getSetting('productplan', 'browse');
  1141. $data = array();
  1142. $action = $settings['action'];
  1143. if($action === 'preview' && $view === 'setting')
  1144. {
  1145. $productID = (int)$settings['product'];
  1146. $productPlans = $this->loadModel('productplan')->getProductPlans(array($productID));
  1147. $data = isset($productPlans[$productID]) ? $productPlans[$productID] : array();
  1148. }
  1149. elseif($view === 'list')
  1150. {
  1151. $data = $this->loadModel('productplan')->getByIDList(explode(',', $idList));
  1152. }
  1153. $this->view->cols = $cols;
  1154. $this->view->data = $data;
  1155. }
  1156. /**
  1157. * 预览产品计划下的内容列表。
  1158. * Preview plan story.
  1159. *
  1160. * @param string $view
  1161. * @param array $settings
  1162. * @param string $idList
  1163. * @access protected
  1164. * @return void
  1165. */
  1166. protected function previewPlanStory($view, $settings, $idList)
  1167. {
  1168. $cols = $this->loadModel('datatable')->getSetting('bug', 'browse');
  1169. $data = array();
  1170. $action = $settings['action'];
  1171. if($action === 'preview' && $view === 'setting')
  1172. {
  1173. $data = $this->loadModel('story')->getPlanStories((int)$settings['plan']);
  1174. }
  1175. elseif($view === 'list')
  1176. {
  1177. $data = $this->loadModel('story')->getByList($idList);
  1178. }
  1179. $this->view->cols = $cols;
  1180. $this->view->data = $data;
  1181. }
  1182. /**
  1183. * 预览产品下的Bug列表。
  1184. * Preview product story.
  1185. *
  1186. * @param string $view
  1187. * @param array $settings
  1188. * @param string $idList
  1189. * @access protected
  1190. * @return void
  1191. */
  1192. protected function previewProductBug($view, $settings, $idList)
  1193. {
  1194. $cols = $this->loadModel('datatable')->getSetting('bug', 'browse');
  1195. $data = array();
  1196. $action = $settings['action'];
  1197. if($action === 'preview' && $view === 'setting')
  1198. {
  1199. $product = (int)$settings['product'];
  1200. $condition = $settings['condition'];
  1201. if($condition == 'customSearch')
  1202. {
  1203. $where = "`product`=$product";
  1204. foreach($settings['field'] as $index => $field)
  1205. {
  1206. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1207. }
  1208. $data = $this->dao->select('*')->from(TABLE_BUG)->where($where)->fetchAll('', false);
  1209. }
  1210. else
  1211. {
  1212. $data = $this->loadModel('bug')->getProductBugs(array((int)$settings['product']));
  1213. }
  1214. }
  1215. elseif($view === 'list')
  1216. {
  1217. $data = $this->loadModel('bug')->getByIdList($idList);
  1218. }
  1219. $this->view->cols = $cols;
  1220. $this->view->data = $data;
  1221. }
  1222. /**
  1223. * 预览产品计划下的内容列表。
  1224. * Preview plan story.
  1225. *
  1226. * @param string $view
  1227. * @param array $settings
  1228. * @param string $idList
  1229. * @access protected
  1230. * @return void
  1231. */
  1232. protected function previewPlanBug($view, $settings, $idList)
  1233. {
  1234. $cols = $this->loadModel('datatable')->getSetting('bug', 'browse');
  1235. $data = array();
  1236. $action = $settings['action'];
  1237. if($action === 'preview' && $view === 'setting')
  1238. {
  1239. $data = $this->loadModel('bug')->getPlanBugs((int)$settings['plan']);
  1240. }
  1241. elseif($view === 'list')
  1242. {
  1243. $data = $this->loadModel('bug')->getByIdList($idList);
  1244. }
  1245. $this->view->cols = $cols;
  1246. $this->view->data = $data;
  1247. }
  1248. /**
  1249. * 预览产品下的用例。
  1250. * Preview product case.
  1251. *
  1252. * @param string $view
  1253. * @param array $settings
  1254. * @param string $idList
  1255. * @access protected
  1256. * @return void
  1257. */
  1258. protected function previewProductCase($view, $settings, $idList)
  1259. {
  1260. $this->loadModel('testcase');
  1261. $cols = $this->config->testcase->dtable->fieldList;
  1262. $data = array();
  1263. $action = $settings['action'];
  1264. if($action === 'preview' && $view === 'setting')
  1265. {
  1266. $product = (int)$settings['product'];
  1267. $condition = $settings['condition'];
  1268. if($condition === 'customSearch')
  1269. {
  1270. $where = "`product`=$product";
  1271. foreach($settings['field'] as $index => $field)
  1272. {
  1273. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1274. }
  1275. $data = $this->dao->select('*')->from(TABLE_CASE)->where($where)->fetchAll('', false);
  1276. }
  1277. else
  1278. {
  1279. $data = $this->loadModel('testcase')->getTestCases($product, '', $condition, 0, 0);
  1280. }
  1281. }
  1282. elseif($view === 'list')
  1283. {
  1284. $data = $this->loadModel('testcase')->getByList(explode(',', $idList));
  1285. }
  1286. $this->view->cols = $cols;
  1287. $this->view->data = $data;
  1288. }
  1289. /**
  1290. * 预览产品研发需求列表。
  1291. * Preview product story.
  1292. *
  1293. * @param string $view
  1294. * @param array $settings
  1295. * @param string $idList
  1296. * @access protected
  1297. * @return void
  1298. */
  1299. protected function previewProductStory($view, $settings, $idList)
  1300. {
  1301. $this->previewStory('story', $view, $settings, $idList);
  1302. }
  1303. /**
  1304. * 预览业务需求列表。
  1305. * Preview epic story.
  1306. *
  1307. * @param string $view
  1308. * @param array $settings
  1309. * @param string $idList
  1310. * @access protected
  1311. * @return void
  1312. */
  1313. protected function previewER($view, $settings, $idList)
  1314. {
  1315. $this->previewStory('epic', $view, $settings, $idList);
  1316. }
  1317. /**
  1318. * 预览用户需求列表。
  1319. * Preview requirement story.
  1320. *
  1321. * @param string $view
  1322. * @param array $settings
  1323. * @param string $idList
  1324. * @access protected
  1325. * @return void
  1326. */
  1327. protected function previewUR($view, $settings, $idList)
  1328. {
  1329. $this->previewStory('requirement', $view, $settings, $idList);
  1330. }
  1331. /**
  1332. * 预览项目研发需求列表。
  1333. * Preview project story.
  1334. *
  1335. * @param string $view
  1336. * @param array $settings
  1337. * @param string $idList
  1338. * @access protected
  1339. * @return void
  1340. */
  1341. protected function previewProjectStory($view, $settings, $idList)
  1342. {
  1343. $cols = $this->loadModel('datatable')->getSetting('product', 'browse');
  1344. $data = array();
  1345. $action = $settings['action'];
  1346. if($action === 'preview' && $view === 'setting')
  1347. {
  1348. $project = (int)$settings['project'];
  1349. $condition = $settings['condition'];
  1350. if($condition === 'customSearch')
  1351. {
  1352. $where = "1=1";
  1353. foreach($settings['field'] as $index => $field)
  1354. {
  1355. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1356. }
  1357. $data = $this->dao->select('DISTINCT t1.*, t2.*')->from(TABLE_PROJECTSTORY)->alias('t1')
  1358. ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story=t2.id')
  1359. ->where('project')->eq($project)
  1360. ->andWhere($where)
  1361. ->fetchAll('', false);
  1362. }
  1363. else
  1364. {
  1365. $data = $this->loadModel('story')->getExecutionStories($project, 0, '', $condition);
  1366. }
  1367. }
  1368. elseif($view === 'list')
  1369. {
  1370. $data = $this->loadModel('story')->getByList($idList);
  1371. }
  1372. $this->view->cols = $cols;
  1373. $this->view->data = $data;
  1374. }
  1375. /**
  1376. * 预览执行需求列表。
  1377. * Preview execution story.
  1378. *
  1379. * @param string $view
  1380. * @param array $settings
  1381. * @param string $idList
  1382. * @access protected
  1383. * @return void
  1384. */
  1385. protected function previewExecutionStory($view, $settings, $idList)
  1386. {
  1387. $cols = $this->loadModel('datatable')->getSetting('execution', 'story', false, 'story');
  1388. $data = array();
  1389. $action = $settings['action'];
  1390. if($action === 'preview' && $view === 'setting')
  1391. {
  1392. $data = $this->loadModel('story')->getExecutionStories((int)$settings['execution'], 0, '', $settings['condition'], '', 'story');
  1393. }
  1394. elseif($view === 'list')
  1395. {
  1396. $data = $this->loadModel('story')->getByList($idList);
  1397. }
  1398. $this->view->cols = $cols;
  1399. $this->view->data = $data;
  1400. }
  1401. /**
  1402. * 预览需求列表。
  1403. * Preview story list.
  1404. *
  1405. * @param string $storyType
  1406. * @param string $view
  1407. * @param array $settings
  1408. * @param string $idList
  1409. * @access protected
  1410. * @return void
  1411. */
  1412. protected function previewStory($storyType, $view, $settings, $idList)
  1413. {
  1414. $cols = $this->loadModel('datatable')->getSetting('product', 'browse');
  1415. $data = array();
  1416. $action = $settings['action'];
  1417. if($action === 'preview' && $view === 'setting')
  1418. {
  1419. $product = (int)$settings['product'];
  1420. $condition = $settings['condition'];
  1421. if($condition === 'customSearch')
  1422. {
  1423. $where = "`product`=$product and `type`='$storyType'";
  1424. foreach($settings['field'] as $index => $field)
  1425. {
  1426. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1427. }
  1428. $data = $this->dao->select('*')->from(TABLE_STORY)->where($where)->fetchAll('', false);
  1429. }
  1430. else
  1431. {
  1432. $data = $this->loadModel('product')->getStories($product, '', $condition, 0, 0, $storyType);
  1433. }
  1434. }
  1435. elseif($view === 'list')
  1436. {
  1437. $data = $this->loadModel('story')->getByList($idList);
  1438. }
  1439. $this->view->cols = $cols;
  1440. $this->view->data = $data;
  1441. }
  1442. /**
  1443. * 预览任务列表。
  1444. * Preview task list.
  1445. *
  1446. * @param string $view
  1447. * @param array $settings
  1448. * @param string $idList
  1449. * @access protected
  1450. * @return void
  1451. */
  1452. protected function previewTask($view, $settings, $idList)
  1453. {
  1454. $cols = $this->loadModel('datatable')->getSetting('execution', 'task');
  1455. $data = array();
  1456. $action = $settings['action'];
  1457. if($action === 'preview' && $view === 'setting')
  1458. {
  1459. $data = $this->loadModel('task')->getExecutionTasks((int)$settings['execution']);
  1460. }
  1461. elseif($view === 'list')
  1462. {
  1463. $data = $this->loadModel('task')->getByIdList(explode(',', $idList));
  1464. }
  1465. $this->view->cols = $cols;
  1466. $this->view->data = $data;
  1467. }
  1468. /**
  1469. * 预览用例库下的用例。
  1470. * Preview caselib case.
  1471. *
  1472. * @param string $view
  1473. * @param array $settings
  1474. * @param string $idList
  1475. * @access protected
  1476. * @return void
  1477. */
  1478. protected function previewCaselib($view, $settings, $idList)
  1479. {
  1480. $this->loadModel('testcase');
  1481. $cols = $this->config->testcase->dtable->fieldList;
  1482. $data = array();
  1483. $action = $settings['action'];
  1484. if($action === 'preview' && $view === 'setting')
  1485. {
  1486. $caselib = (int)$settings['caselib'];
  1487. $condition = $settings['condition'];
  1488. if($condition === 'customSearch')
  1489. {
  1490. $where = "`lib`=$caselib";
  1491. foreach($settings['field'] as $index => $field)
  1492. {
  1493. $where = $this->loadModel('search')->setWhere($where, $field, $settings['operator'][$index], $settings['value'][$index], $settings['andor'][$index]);
  1494. }
  1495. $data = $this->dao->select('*')->from(TABLE_CASE)->where($where)->fetchAll('', false);
  1496. }
  1497. else
  1498. {
  1499. $data = $this->loadModel('caselib')->getLibCases((int)$caselib, $condition);
  1500. }
  1501. }
  1502. elseif($view === 'list')
  1503. {
  1504. $data = $this->loadModel('testcase')->getByList(explode(',', $idList));
  1505. }
  1506. $this->view->cols = $cols;
  1507. $this->view->data = $data;
  1508. }
  1509. /**
  1510. * 导出禅道列表。
  1511. * Export zentao list.
  1512. *
  1513. * @param object $blockData
  1514. * @access protected
  1515. * @return string
  1516. */
  1517. protected function exportZentaoList($blockData)
  1518. {
  1519. $users = $this->loadModel('user')->getPairs('noletter|pofirst|nodeleted');
  1520. $cols = zget($blockData->content, 'cols', array());
  1521. $data = zget($blockData->content, 'data', array());
  1522. $list = array();
  1523. $list[] = array('type' => 'heading', 'props' => array('depth' => 5, 'text' => $blockData->title));
  1524. $tableProps = array();
  1525. foreach($cols as $col)
  1526. {
  1527. if(isset($col->show) && !$col->show) continue;
  1528. $width = null;
  1529. if(isset($col->width) && is_numeric($col->width)) $width = $col->width < 1 ? (($col->width * 100) . '%') : "{$col->width}px";
  1530. $tableProps['cols'][] = array('name' => $col->name, 'text' => $col->title, 'width' => $width);
  1531. }
  1532. foreach($data as $row)
  1533. {
  1534. $rowData = array();
  1535. foreach($cols as $col)
  1536. {
  1537. if(isset($col->show) && !$col->show) continue;
  1538. $value = isset($row->{$col->name}) ? $row->{$col->name} : '';
  1539. if(isset($col->map)) $value = zget($col->map, $value);
  1540. if(isset($col->type) && $col->type == 'user' && isset($users[$value])) $value = zget($users, $value);
  1541. if(isset($col->type) && $col->type == 'status' && isset($col->statusMap)) $value = zget($col->statusMap, $value);
  1542. $rowData[$col->name] = array('text' => (is_array($value) || is_object($value)) ? '' : strval($value));
  1543. }
  1544. $tableProps['data'][] = $rowData;
  1545. }
  1546. $list[] = array('type' => 'table', 'props' => $tableProps);
  1547. return json_encode($list);
  1548. }
  1549. /**
  1550. * 展示需求层级关系。
  1551. * Assign story grade data.
  1552. *
  1553. * @param string $type
  1554. * @access protected
  1555. * @return void
  1556. */
  1557. protected function assignStoryGradeData($type)
  1558. {
  1559. $gradeGroup = array();
  1560. $gradeList = $this->loadModel('story')->getGradeList('');
  1561. foreach($gradeList as $grade) $gradeGroup[$grade->type][$grade->grade] = $grade->name;
  1562. if($type != 'planStory' && $type != 'projectStory')
  1563. {
  1564. if($type == 'productStory') $storyType = 'story';
  1565. if($type == 'ER') $storyType = 'epic';
  1566. if($type == 'UR') $storyType = 'requirement';
  1567. $this->view->storyType = $storyType;
  1568. }
  1569. $this->view->gradeGroup = $gradeGroup;
  1570. }
  1571. /**
  1572. * 处理发布列表展示数据。
  1573. * Process release list display data.
  1574. *
  1575. * @param array $releaseList
  1576. * @param array $childReleases
  1577. * @access protected
  1578. * @return array
  1579. */
  1580. protected function processReleaseListData($releaseList, $childReleases)
  1581. {
  1582. $releases = array();
  1583. foreach($releaseList as $release)
  1584. {
  1585. $release->rowID = $release->id;
  1586. $release->rowspan = count($release->builds);
  1587. if(!empty($release->builds))
  1588. {
  1589. foreach($release->builds as $build)
  1590. {
  1591. $releaseInfo = clone $release;
  1592. $releaseInfo->build = $build;
  1593. $releases[] = $releaseInfo;
  1594. }
  1595. }
  1596. else
  1597. {
  1598. $releases[] = $release;
  1599. }
  1600. if(empty($release->releases)) continue;
  1601. foreach(explode(',', $release->releases) as $childID)
  1602. {
  1603. if(isset($childReleases[$childID]))
  1604. {
  1605. $child = clone $childReleases[$childID];
  1606. $child = current($this->processReleaseListData(array($child)));
  1607. $child->rowID = "{$release->id}-{$childID}";
  1608. $child->parent = $release->id;
  1609. $releases[$child->rowID] = $child;
  1610. }
  1611. }
  1612. }
  1613. return $releases;
  1614. }
  1615. /*
  1616. * Get authorized subdocuments through recursion.
  1617. * 递归获取有权限的子文档。
  1618. *
  1619. * @param int $docID
  1620. * @param int $level
  1621. * @access public
  1622. */
  1623. /**
  1624. * @param int $docID
  1625. * @param int $level
  1626. */
  1627. protected function getDocChildrenByRecursion($docID, $level)
  1628. {
  1629. if($level <= 0) return array();
  1630. $docs = $this->doc->getDocsByParent($docID);
  1631. $privDocs = $this->doc->filterPrivDocs($docs, '');
  1632. foreach($privDocs as $doc) $doc->children = $this->getDocChildrenByRecursion($doc->id, $level - 1);
  1633. return $privDocs;
  1634. }
  1635. }