control.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. <?php
  2. /**
  3. * The control file of productplan module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package productplan
  9. * @version $Id: control.php 4659 2013-04-17 06:45:08Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class productplan extends control
  13. {
  14. /**
  15. * 设置公共属性。
  16. * Common actions.
  17. *
  18. * @param int $productID
  19. * @param int $branch
  20. * @param bool $isFromDoc
  21. * @access public
  22. * @return void
  23. */
  24. public function commonAction($productID, $branch = 0, $isFromDoc = false)
  25. {
  26. $product = $this->loadModel('product')->getById($productID);
  27. $products = $this->product->getPairs('all', 0, '', 'all');
  28. if(empty($product) && !$isFromDoc) $this->locate($this->createLink('product', 'create'));
  29. $this->product->checkAccess($productID, $products);
  30. $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]);
  31. $this->app->loadConfig('execution');
  32. if(!$product->shadow) $this->product->setMenu($productID, $branch);
  33. $this->session->set('currentProductType', $product->type);
  34. $branches = $this->loadModel('branch')->getList($productID, 0, 'all');
  35. $branchOption = array();
  36. $branchTagOption = array();
  37. foreach($branches as $branchInfo)
  38. {
  39. $branchOption[$branchInfo->id] = $branchInfo->name;
  40. $branchTagOption[$branchInfo->id] = $branchInfo->name . ($branchInfo->status == 'closed' ? ' (' . $this->lang->branch->statusList['closed'] . ')' : '');
  41. }
  42. if($product->shadow)
  43. {
  44. $projectList = $this->product->getProjectPairsByProductIdList(array($productID));
  45. $projectID = (int) key($projectList);
  46. $this->loadModel('project')->setMenu($projectID);
  47. }
  48. $this->view->product = $product;
  49. $this->view->projectID = isset($projectID) ? $projectID : 0;
  50. $this->view->branch = $branch;
  51. $this->view->branchOption = $branchOption;
  52. $this->view->branchTagOption = $branchTagOption;
  53. }
  54. /**
  55. * 创建一个计划。
  56. * Create a plan.
  57. *
  58. * @param int $productID
  59. * @param int $branchID
  60. * @param int $parent
  61. * @access public
  62. * @return void
  63. */
  64. public function create($productID = 0, $branchID = 0, $parent = 0)
  65. {
  66. if(!empty($_POST))
  67. {
  68. $planData = form::data()
  69. ->add('createdBy', $this->app->user->account)
  70. ->add('createdDate', helper::now())
  71. ->get();
  72. $planID = $this->productplan->create($planData, (int)$this->post->future);
  73. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  74. $this->loadModel('action')->create('productplan', $planID, 'opened');
  75. $message = $this->executeHooks($planID);
  76. if($message) $this->lang->saveSuccess = $message;
  77. if($parent > 0) $this->productplan->updateParentStatus($parent);
  78. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  79. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $planID));
  80. if(isInModal())
  81. {
  82. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "loadProductPlans($productID, $branchID);"));
  83. }
  84. return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'browse', "productID=$productID")));
  85. }
  86. $this->commonAction($productID, $branchID);
  87. $lastPlan = $this->productplan->getLast($productID, '', $parent);
  88. $product = $this->loadModel('product')->getByID($productID);
  89. if($lastPlan)
  90. {
  91. $timestamp = strtotime($lastPlan->end);
  92. $weekday = date('w', $timestamp);
  93. $delta = 1;
  94. if($weekday == '5' || $weekday == '6') $delta = 8 - $weekday;
  95. $begin = date('Y-m-d', strtotime("+$delta days", $timestamp));
  96. }
  97. $this->view->begin = $lastPlan ? $begin : date('Y-m-d');
  98. if($parent) $this->view->parentPlan = $this->productplan->getByID($parent);
  99. $this->view->title = $this->view->product->name . $this->lang->hyphen . $this->lang->productplan->create;
  100. $this->view->product = $product;
  101. $this->view->lastPlan = $lastPlan;
  102. $this->view->branch = $branchID;
  103. $this->view->branches = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($productID, 'active');
  104. $this->view->parent = $parent;
  105. $this->view->parentPlanPairs = $this->productplan->getTopPlanPairs($productID, 'done,closed');
  106. $this->view->parentList = $this->productplan->getByIDList(array_keys($this->view->parentPlanPairs));
  107. $this->display();
  108. }
  109. /**
  110. * 编辑一个计划。
  111. * Edit a plan.
  112. *
  113. * @param int $planID
  114. * @access public
  115. * @return void
  116. */
  117. public function edit($planID)
  118. {
  119. $plan = $this->productplan->getByID($planID);
  120. if(!empty($_POST))
  121. {
  122. $planData = form::data($this->config->productplan->form->edit, $planID)
  123. ->setIF($this->post->future || empty($_POST['begin']), 'begin', $this->config->productplan->future)
  124. ->setIF($this->post->future || empty($_POST['end']), 'end', $this->config->productplan->future)
  125. ->get();
  126. $changes = $this->productplan->update($planData, $plan);
  127. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  128. $this->productplan->unlinkOldBranch(array($planID => $changes));
  129. if($changes)
  130. {
  131. $actionID = $this->loadModel('action')->create('productplan', $planID, 'edited');
  132. $this->action->logHistory($actionID, $changes);
  133. }
  134. $message = $this->executeHooks($planID);
  135. if($message) $this->lang->saveSuccess = $message;
  136. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $this->createLink($this->app->rawModule, 'view', "planID=$planID")));
  137. }
  138. $oldBranch = array($planID => $plan->branch);
  139. /* Get the parent plan pair exclusion itself. */
  140. $parentPlanPairs = $this->productplan->getTopPlanPairs($plan->product, 'done,closed', $plan->parent);
  141. unset($parentPlanPairs[$planID]);
  142. $this->view->parentPlanPairs = $parentPlanPairs;
  143. $this->view->parentList = $this->productplan->getByIDList(array_keys($this->view->parentPlanPairs));
  144. $this->commonAction((int)$plan->product, (int)$plan->branch);
  145. if($plan->parent > 0)
  146. {
  147. $parentPlan = $this->productplan->getByID($plan->parent);
  148. $branchPairs = array();
  149. foreach(explode(',', $parentPlan->branch) as $parentBranchID)
  150. {
  151. $parentBranchID = (int)$parentBranchID;
  152. $branchPairs[$parentBranchID] = $this->view->branchTagOption[$parentBranchID];
  153. }
  154. $this->view->branchTagOption = $branchPairs;
  155. }
  156. $this->view->title = $this->view->product->name . $this->lang->hyphen . $this->lang->productplan->edit;
  157. $this->view->productID = $plan->product;
  158. $this->view->oldBranch = $oldBranch;
  159. $this->view->plan = $plan;
  160. $this->display();
  161. }
  162. /**
  163. * 批量编辑计划。
  164. * Batch edit plan.
  165. *
  166. * @param int $productID
  167. * @param int $branch
  168. * @access public
  169. * @return void
  170. */
  171. public function batchEdit($productID, $branch = 0)
  172. {
  173. if(!empty($_POST['title']))
  174. {
  175. /* 从POST中获取数据。 */
  176. $plans = $this->productplanZen->buildPlansForBatchEdit();
  177. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  178. $this->productplan->batchUpdate($productID, $plans);
  179. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  180. $this->loadModel('score')->create('ajax', 'batchOther');
  181. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $this->session->productPlanList));
  182. }
  183. if(!$this->post->planIdList) return $this->send(array('result' => 'success', 'load' => $this->session->productPlanList));
  184. $this->commonAction($productID, $branch);
  185. $plans = $this->productplan->getByIDList($this->post->planIdList);
  186. $oldBranch = array();
  187. $parentIdList = array();
  188. foreach($plans as $plan)
  189. {
  190. $oldBranch[$plan->id] = $plan->branch;
  191. $parentIdList[$plan->parent] = $plan->parent;
  192. }
  193. $this->view->title = $this->lang->productplan->batchEdit;
  194. $this->view->plans = $plans;
  195. $this->view->oldBranch = $oldBranch;
  196. $this->view->product = $this->loadModel('product')->getByID($productID);
  197. $this->view->parentList = $this->productplan->getByIDList($parentIdList);
  198. $this->display();
  199. }
  200. /**
  201. * 批量更新计划的状态。
  202. * Batch change the status of productplan.
  203. *
  204. * @param string $status
  205. * @access public
  206. * @return void
  207. * @param int $productID
  208. */
  209. public function batchChangeStatus($status, $productID)
  210. {
  211. $planIdList = $this->post->planIdList;
  212. if($status !== 'closed' || $this->post->comment)
  213. {
  214. $this->productplan->batchChangeStatus($planIdList, $status);
  215. if(dao::isError()) return $this->sendError(dao::getError());
  216. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('browse', "product=$productID")));
  217. }
  218. $this->commonAction($productID);
  219. $this->view->plans = $this->productplan->getByIDList($planIdList);
  220. $this->view->productID = $productID;
  221. $this->display();
  222. }
  223. /**
  224. * 删除一个计划。
  225. * Delete a plan.
  226. *
  227. * @param int $planID
  228. * @access public
  229. * @return void
  230. */
  231. public function delete($planID)
  232. {
  233. $plan = $this->productplan->getByID($planID);
  234. if(!$plan || $plan->parent < 0) return $this->sendError($this->lang->productplan->cannotDeleteParent);
  235. $this->productplan->delete(TABLE_PRODUCTPLAN, $planID);
  236. if($plan->parent > 0) $this->productplan->changeParentField($planID);
  237. $message = $this->executeHooks($planID);
  238. if($message) $this->lang->saveSuccess = $message;
  239. /* if ajax request, send result. */
  240. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  241. return $this->sendSuccess(array('message' => $message, 'load' => true));
  242. }
  243. /**
  244. * 计划列表。
  245. * Browse plans.
  246. *
  247. * @param int $productID
  248. * @param string $branch
  249. * @param string $browseType
  250. * @param int $queryID
  251. * @param string $orderBy
  252. * @param int $recTotal
  253. * @param int $recPerPage
  254. * @param int $pageID
  255. * @access public
  256. * @return void
  257. * @param string $from
  258. * @param int $blockID
  259. */
  260. public function browse($productID = 0, $branch = '', $browseType = 'undone', $queryID = 0, $orderBy = 'begin_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1, $from = 'product', $blockID = 0)
  261. {
  262. if($from === 'doc' || $from == 'ai')
  263. {
  264. $this->app->loadLang('doc');
  265. $products = $this->loadModel('product')->getPairs('nodeleted', 0, '', 'all');
  266. if(empty($products)) return $this->send(array('result' => 'fail', 'message' => $this->lang->doc->tips->noProduct));
  267. $productID = $this->product->checkAccess($productID, $products);
  268. }
  269. $branchID = $branch === '' ? 'all' : $branch;
  270. if(!$branch) $branch = '';
  271. /* Load pager. */
  272. $this->app->loadClass('pager', true);
  273. $pager = new pager($recTotal, $recPerPage, $pageID);
  274. /* Append id for second sort. */
  275. $sort = common::appendOrder($orderBy);
  276. if(strpos($sort, 'branchName_') !== false) $sort = str_replace('branchName_', 'branch_', $sort);
  277. $this->session->set('productPlanList', $this->app->getURI(true), 'product');
  278. $viewType = $this->cookie->viewType ? $this->cookie->viewType : 'list';
  279. $this->commonAction($productID, (int)$branch, ($from == 'doc' || $from == 'ai') ? true : false);
  280. $product = $this->view->product;
  281. $productName = empty($product) ? '' : $product->name;
  282. if($product->type != 'normal') $this->config->productplan->dtable->fieldList['branchName']['title'] = $this->lang->product->branch;
  283. if($product->type == 'normal') unset($this->config->productplan->dtable->fieldList['branchName']);
  284. /* Build the search form. */
  285. $queryID = $browseType == 'bySearch' ? (int)$queryID : 0;
  286. $actionURL = $this->createLink($this->app->rawModule, 'browse', "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID&orderBy=$orderBy&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID&from=$from&blockID=$blockID");
  287. $this->productplan->buildSearchForm($queryID, $actionURL, $product);
  288. if($viewType == 'kanban') $this->productplanZen->assignKanbanData($product, $branchID, $orderBy);
  289. $plans = $this->productplan->getList($productID, (string)$branch, $browseType, $pager, $sort, "", $queryID);
  290. $plans = $this->productplanZen->buildDataForBrowse($plans, $this->view->branchOption);
  291. $this->view->title = $productName . $this->lang->hyphen . $this->lang->productplan->browse;
  292. $this->view->productID = $productID;
  293. $this->view->branchID = $branchID;
  294. $this->view->browseType = $browseType;
  295. $this->view->viewType = $viewType;
  296. $this->view->orderBy = $orderBy;
  297. $this->view->plans = $plans;
  298. $this->view->pager = $pager;
  299. $this->view->queryID = $queryID;
  300. $this->view->summary = $this->productplanZen->getSummary($plans);
  301. $this->view->projects = $this->product->getProjectPairsByProduct($productID, (string)$branch, '', 'noclosed', 'multiple');
  302. $this->view->from = $from;
  303. $this->view->blockID = $blockID;
  304. if($from === 'doc')
  305. {
  306. $content = $this->loadModel('doc')->getDocBlockContent($blockID);
  307. $this->view->idList = zget($content, 'idList', '');
  308. }
  309. $this->display();
  310. }
  311. /**
  312. * 查看计划详情。
  313. * View a plan.
  314. *
  315. * @param int $planID
  316. * @param string $type
  317. * @param string $orderBy
  318. * @param string $link
  319. * @param string $param
  320. * @param int $recTotal
  321. * @param int $recPerPage
  322. * @param int $pageID
  323. * @access public
  324. * @return void
  325. */
  326. public function view($planID = 0, $type = 'story', $orderBy = 'order_desc', $link = 'false', $param = '', $recTotal = 0, $recPerPage = 100, $pageID = 1)
  327. {
  328. $this->app->loadLang('requirement');
  329. $this->app->loadLang('epic');
  330. $plan = $this->productplan->getByID($planID, true);
  331. if(!$plan)
  332. {
  333. if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => '404 Not found'));
  334. return $this->sendError($this->lang->notFound, $this->createLink('product', 'index'));
  335. }
  336. /* Append id for second sort. */
  337. $orderBy = ($type == 'bug' && $orderBy == 'order_desc') ? 'id_desc' : $orderBy;
  338. $sort = common::appendOrder($orderBy);
  339. if(strpos($sort, 'pri_') !== false) $sort = str_replace('pri_', 'priOrder_', $sort);
  340. $this->commonAction($plan->product, (int)$plan->branch);
  341. $products = $this->product->getProductPairsByProject((int)$this->session->project);
  342. /* Load pager. */
  343. $this->app->loadClass('pager', true);
  344. if(in_array($this->app->getViewType(), array('mhtml', 'xhtml'))) $recPerPage = 10;
  345. $bugPager = new pager(0, $recPerPage, $type == 'bug' ? $pageID : 1);
  346. $storyPager = new pager(0, $recPerPage, $type == 'story' ? $pageID : 1);
  347. /* Get stories of plan. */
  348. $modulePairs = $this->loadModel('tree')->getOptionMenu($plan->product, 'story', 0, 'all');
  349. $planStories = $this->loadModel('story')->getPlanStories($planID, 'all', $type == 'story' ? $sort : 'id_desc', $storyPager);
  350. if($planStories) $this->productplanZen->reorderStories();
  351. foreach($planStories as $story)
  352. {
  353. if(!isset($modulePairs[$story->module])) $modulePairs += $this->tree->getModulesName((array)$story->module);
  354. }
  355. $this->executeHooks($planID);
  356. $this->productplanZen->setSessionForViewPage($planID, $type, $orderBy, $pageID, $recTotal);
  357. $this->productplanZen->assignViewData($plan);
  358. $this->view->title = "PLAN #$plan->id $plan->title/" . zget($products, $plan->product, '');
  359. $this->view->modulePairs = $modulePairs;
  360. $this->view->planStories = $planStories;
  361. $this->view->planBugs = $this->loadModel('bug')->getPlanBugs($planID, 'all', $type == 'bug' ? $sort : 'id_desc', $bugPager);
  362. $this->view->summary = $this->productplanZen->buildViewSummary($planStories);
  363. $this->view->type = $type;
  364. $this->view->orderBy = $orderBy;
  365. $this->view->link = $link;
  366. $this->view->param = $param;
  367. $this->view->storyCases = $this->loadModel('testcase')->getStoryCaseCounts($planStories ? array_keys($planStories) : array());
  368. $this->view->tabUrl = $this->createLink('productplan', 'view', "planID=$planID&type=%s&orderBy=$orderBy&link=$link&param=$param&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID");
  369. if($this->viewType != 'json')
  370. {
  371. $this->view->storyPager = $storyPager;
  372. $this->view->bugPager = $bugPager;
  373. }
  374. $this->display();
  375. }
  376. /**
  377. * 开始计划。
  378. * Start a plan.
  379. *
  380. * @param int $planID
  381. * @access public
  382. * @return void
  383. */
  384. public function start($planID)
  385. {
  386. $this->productplan->updateStatus($planID, 'doing', 'started');
  387. if(dao::isError()) return $this->sendError(dao::getError());
  388. return $this->sendSuccess(array('load' => true, 'closeModal' => true));
  389. }
  390. /**
  391. * 完成一个计划。
  392. * Finish a plan.
  393. *
  394. * @param int $planID
  395. * @access public
  396. * @return void
  397. */
  398. public function finish($planID)
  399. {
  400. $this->productplan->updateStatus($planID, 'done', 'finished');
  401. if(dao::isError()) return $this->sendError(dao::getError());
  402. return $this->send(array('result' => 'success', 'load' => true, 'closeModal' => true));
  403. }
  404. /**
  405. * 关闭一个计划。
  406. * Close a plan.
  407. *
  408. * @param int $planID
  409. * @access public
  410. * @return void
  411. */
  412. public function close($planID)
  413. {
  414. if(!empty($_POST))
  415. {
  416. $this->productplan->updateStatus($planID, 'closed', 'closed');
  417. if(dao::isError()) return $this->sendError(dao::getError());
  418. return $this->send(array('result' => 'success', 'load' => true, 'closeModal' => true));
  419. }
  420. $this->view->productplan = $this->productplan->getById($planID);
  421. $this->view->actions = $this->loadModel('action')->getList('productplan', $planID);
  422. $this->view->users = $this->loadModel('user')->getPairs();
  423. $this->display();
  424. }
  425. /**
  426. * 激活一个计划。
  427. * Activate a plan.
  428. *
  429. * @param int $planID
  430. * @param string $confirm
  431. * @access public
  432. * @return void
  433. */
  434. public function activate($planID)
  435. {
  436. $this->productplan->updateStatus($planID, 'doing', 'activated');
  437. if(dao::isError()) return $this->sendError(dao::getError());
  438. return $this->sendSuccess(array('load' => true, 'closeModal' => true));
  439. }
  440. /**
  441. * 根据产品获取计划列表。
  442. * Ajax: Get product plans.
  443. *
  444. * @param int $productID
  445. * @param int $branch
  446. * @access public
  447. * @return void
  448. */
  449. public function ajaxGetProductplans($productID, $branch = 0)
  450. {
  451. $plans = $this->productplan->getPairs($productID, empty($branch) ? '' : $branch, '', true);
  452. $items = array();
  453. foreach($plans as $planID => $planName) $items[] = array('text' => $planName, 'value' => $planID, 'keys' => $planName);
  454. return print(json_encode($items));
  455. }
  456. /**
  457. * 设置需求排序。
  458. * Sort story for productplan.
  459. *
  460. * @param int $planID
  461. * @access public
  462. * @return bool
  463. */
  464. public function ajaxStorySort($planID = 0)
  465. {
  466. if(empty($planID)) return true;
  467. /* Get story id list. */
  468. $storyIdList = json_decode($this->post->storyIdList, true);
  469. asort($storyIdList);
  470. $storyIdList = array_flip($storyIdList);
  471. /* Update the story order according to the plan. */
  472. $this->loadModel('story')->sortStoriesOfPlan($planID, $storyIdList, $this->post->orderBy, $this->post->pageID, $this->post->recPerPage);
  473. return $this->send(array('result' => 'success'));
  474. }
  475. /**
  476. * 根据产品和分支获取项目。
  477. * Get projects by product id.
  478. *
  479. * @param int $productID
  480. * @param string $branch
  481. * @access public
  482. * @return void
  483. */
  484. public function ajaxGetProjects($productID, $branch = '0')
  485. {
  486. $projects = $this->loadModel('product')->getProjectPairsByProduct($productID, $branch, '', $status = 'noclosed', 'multiple');
  487. $items = array();
  488. foreach($projects as $projectID => $projectName) $items[] = array('text' => $projectName, 'value' => $projectID, 'keys' => $projectName);
  489. return print(json_encode($items));
  490. }
  491. /**
  492. * 关联需求。
  493. * Link stories.
  494. *
  495. * @param int $planID
  496. * @param string $browseType
  497. * @param int $param
  498. * @param string $orderBy
  499. * @param int $recTotal
  500. * @param int $recPerPage
  501. * @param int $pageID
  502. * @access public
  503. * @return void
  504. */
  505. public function linkStory($planID = 0, $browseType = '', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 100, $pageID = 1)
  506. {
  507. if(!empty($_POST['stories']))
  508. {
  509. $this->productplan->linkStory($planID, $this->post->stories);
  510. if(dao::isError()) return $this->sendError(dao::getError());
  511. return $this->send(array('result' => 'success', 'load' => inlink('view', "planID=$planID&type=story&orderBy=order_desc")));
  512. }
  513. $this->session->set('storyList', inlink('view', "planID=$planID&type=story&orderBy=$orderBy&link=true&param=" . helper::safe64Encode("&browseType=$browseType&queryID=$param")), 'product');
  514. $plan = $this->productplan->getByID($planID);
  515. if(!$plan) return $this->sendError($this->lang->notFound, true);
  516. $this->commonAction($plan->product, (int)$plan->branch);
  517. /* Load pager. */
  518. $this->app->loadClass('pager', true);
  519. $pager = new pager($recTotal, $recPerPage, $pageID);
  520. /* Build search form. */
  521. $this->productplanZen->buildLinkStorySearchForm($plan, $browseType == 'bySearch' ? (int)$param : 0, $orderBy);
  522. $planStories = $this->loadModel('story')->getPlanStories($planID);
  523. if($browseType == 'bySearch')
  524. {
  525. $allStories = $this->story->getBySearch($plan->product, "0,{$plan->branch}", (int)$param, $orderBy, 0, $this->config->enableER ? 'all' : 'story,requirement', array_keys($planStories), '', $pager);
  526. }
  527. else
  528. {
  529. $allStories = $this->story->getProductStories($this->view->product->id, $plan->branch ? "0,{$plan->branch}" : 0, '0', 'draft,reviewing,active,changing', $this->config->enableER ? 'all' : 'story,requirement', $orderBy, true, array_keys($planStories), $pager);
  530. }
  531. $modules = $this->loadModel('tree')->getOptionMenu($plan->product, 'story', 0, 'all');
  532. foreach($allStories as $story)
  533. {
  534. if(!isset($modules[$story->module])) $modules += $this->tree->getModulesName(array($story->module));
  535. }
  536. $this->view->allStories = $allStories;
  537. $this->view->plan = $plan;
  538. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  539. $this->view->browseType = $browseType;
  540. $this->view->modules = $modules;
  541. $this->view->param = $param;
  542. $this->view->orderBy = $orderBy;
  543. $this->view->pager = $pager;
  544. $this->display();
  545. }
  546. /**
  547. * 移除计划中的需求。
  548. * Unlink story.
  549. *
  550. * @param int $storyID
  551. * @param int $planID
  552. * @access public
  553. * @return void
  554. */
  555. public function unlinkStory($storyID, $planID)
  556. {
  557. $this->productplan->unlinkStory($storyID, $planID);
  558. $this->loadModel('action')->create('productplan', $planID, 'unlinkstory', '', $storyID);
  559. if($this->session->storyList) return $this->sendSuccess(array('load' => $this->session->storyList));
  560. return $this->sendSuccess(array('load' => $this->createLink('productplan', 'view', "planID=$planID&type=story")));
  561. }
  562. /**
  563. * 批量移除计划中的需求。
  564. * Batch unlink story.
  565. *
  566. * @param int $planID
  567. * @param string $orderBy
  568. * @access public
  569. * @return void
  570. */
  571. public function batchUnlinkStory($planID, $orderBy = 'id_desc')
  572. {
  573. if($this->post->storyIdList)
  574. {
  575. foreach($this->post->storyIdList as $storyID) $this->productplan->unlinkStory((int)$storyID, $planID);
  576. $this->loadModel('action')->create('productplan', $planID, 'unlinkstory', '', implode(',', $this->post->storyIdList));
  577. }
  578. return $this->sendSuccess(array('load' => $this->createLink('productplan', 'view', "planID=$planID&type=story&orderBy=$orderBy")));
  579. }
  580. /**
  581. * 计划管理Bug列表。
  582. * Link bug list.
  583. *
  584. * @param int $planID
  585. * @param string $browseType
  586. * @param string $param
  587. * @param string $orderBy
  588. * @param int $recTotal
  589. * @param int $recPerPage
  590. * @param int $pageID
  591. * @access public
  592. * @return void
  593. */
  594. public function linkBug($planID = 0, $browseType = '', $param = '0', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 100, $pageID = 1)
  595. {
  596. if(!empty($_POST['bugs']))
  597. {
  598. $this->productplan->linkBug($planID, $this->post->bugs);
  599. if($this->viewType == 'json') return $this->send(array('result' => 'success'));
  600. return $this->send(array('result' => 'success', 'load' => inlink('view', "planID={$planID}&type=bug&orderBy={$orderBy}")));
  601. }
  602. /* Set session. */
  603. $this->session->set('bugList', inlink('view', "planID=$planID&type=bug&orderBy=$orderBy&link=true&param=" . helper::safe64Encode("&browseType=$browseType&queryID=$param")), 'qa');
  604. /* Init vars. */
  605. $executions = $this->app->user->view->sprints . ',0';
  606. $plan = $this->productplan->getByID($planID);
  607. $productID = $plan->product;
  608. $queryID = $browseType == 'bysearch' ? (int)$param : 0;
  609. /* Set drop menu. */
  610. $this->commonAction($productID);
  611. /* Load pager. */
  612. $this->app->loadClass('pager', $static = true);
  613. $pager = new pager($recTotal, $recPerPage, $pageID);
  614. $this->productplanZen->buildBugSearchForm($plan, $queryID, $orderBy);
  615. $planBugs = $this->loadModel('bug')->getPlanBugs($planID);
  616. if($browseType == 'bySearch')
  617. {
  618. $allBugs = $this->bug->getBySearch('bug', array($productID), $plan->branch, 0, 0, $queryID, implode(',', array_keys($planBugs)), 'id_desc', $pager);
  619. }
  620. else
  621. {
  622. $allBugs = $this->bug->getActiveBugs($productID, $plan->branch, $executions, array_keys($planBugs), $pager);
  623. }
  624. $this->view->allBugs = $allBugs;
  625. $this->view->planBugs = $planBugs;
  626. $this->view->plan = $plan;
  627. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  628. $this->view->browseType = $browseType;
  629. $this->view->param = $param;
  630. $this->view->orderBy = $orderBy;
  631. $this->view->pager = $pager;
  632. $this->display();
  633. }
  634. /**
  635. * 移除计划中的Bug。
  636. * Remove bug from plan.
  637. *
  638. * @param int $bugID
  639. * @param int $planID
  640. * @access public
  641. * @return void
  642. */
  643. public function unlinkBug($bugID, $planID)
  644. {
  645. $this->productplan->unlinkBug($bugID);
  646. $this->loadModel('action')->create('productplan', $planID, 'unlinkbug', '', $bugID);
  647. return $this->sendSuccess(array('load' => true));
  648. }
  649. /**
  650. * 批量移除计划中的Bug。
  651. * Batch unlink bug.
  652. *
  653. * @param int $planID
  654. * @param string $orderBy
  655. * @access public
  656. * @return void
  657. */
  658. public function batchUnlinkBug($planID, $orderBy = 'id_desc')
  659. {
  660. if($this->post->bugIdList)
  661. {
  662. foreach($this->post->bugIdList as $bugID) $this->productplan->unlinkBug((int)$bugID);
  663. $this->loadModel('action')->create('productplan', $planID, 'unlinkbug', '', implode(',', $this->post->bugIdList));
  664. }
  665. return $this->sendSuccess(array('load' => $this->createLink('productplan', 'view', "planID=$planID&type=bug&orderBy=$orderBy")));
  666. }
  667. /**
  668. * 获取分支冲突的需求和Bug。
  669. * AJAX: Get conflict story and bug.
  670. *
  671. * @param int $planID
  672. * @param int $newBranch
  673. * @access public
  674. * @return void
  675. */
  676. public function ajaxGetConflict($planID, $newBranch)
  677. {
  678. $plan = $this->productplan->getByID($planID);
  679. $oldBranch = $plan->branch;
  680. $planStories = $this->loadModel('story')->getPlanStories($planID, 'all');
  681. $planBugs = $this->loadModel('bug')->getPlanBugs($planID, 'all');
  682. $branchPairs = $this->loadModel('branch')->getPairs($plan->product);
  683. $removeBranches = '';
  684. foreach(explode(',', $oldBranch) as $oldBranchID)
  685. {
  686. if($oldBranchID and strpos(",$newBranch,", ",$oldBranchID,") === false) $removeBranches .= "{$branchPairs[$oldBranchID]},";
  687. }
  688. $conflictStoryCounts = 0;
  689. $conflictBugCounts = 0;
  690. if($oldBranch)
  691. {
  692. foreach($planStories as $story)
  693. {
  694. if($story->branch and strpos(",$newBranch,", ",$story->branch,") === false) $conflictStoryCounts ++;
  695. }
  696. foreach($planBugs as $bug)
  697. {
  698. if($bug->branch and strpos(",$newBranch,", ",$bug->branch,") === false) $conflictBugCounts ++;
  699. }
  700. }
  701. if($conflictStoryCounts and $conflictBugCounts)
  702. {
  703. printf($this->lang->productplan->confirmChangePlan, trim($removeBranches, ','), $conflictStoryCounts, $conflictBugCounts);
  704. }
  705. elseif($conflictStoryCounts)
  706. {
  707. printf($this->lang->productplan->confirmRemoveStory, trim($removeBranches, ','), $conflictStoryCounts);
  708. }
  709. elseif($conflictBugCounts)
  710. {
  711. printf($this->lang->productplan->confirmRemoveBug, trim($removeBranches, ','), $conflictBugCounts);
  712. }
  713. }
  714. /**
  715. * 获取最近一次创建的计划。
  716. * AJAX: Get last plan.
  717. *
  718. * @param int $productID
  719. * @param string $branch
  720. * @param int $parent
  721. * @access public
  722. * @return string
  723. */
  724. public function ajaxGetLast($productID, $branch = '', $parent = 0)
  725. {
  726. $lastPlan = $this->productplan->getLast($productID, $branch, $parent);
  727. echo json_encode($lastPlan);
  728. }
  729. /**
  730. * 获取父计划的分支。
  731. * AJAX: Get parent branches.
  732. *
  733. * @param int $productID
  734. * @param int $parentID
  735. * @access public
  736. * @return void
  737. */
  738. public function ajaxGetParentBranches($productID = 0, $parentID = 0)
  739. {
  740. $branchPairs = $this->loadModel('branch')->getPairs($productID, 'active');
  741. if(!empty($parentID))
  742. {
  743. $parentBranches = array();
  744. $parentPlan = $this->productplan->getByID($parentID);
  745. foreach(explode(',', $parentPlan->branch) as $parentBranchID)
  746. {
  747. if(!isset($branchPairs[$parentBranchID])) continue;
  748. $parentBranches[$parentBranchID] = $branchPairs[$parentBranchID];
  749. }
  750. }
  751. $branches = empty($parentID) ? $branchPairs : $parentBranches;
  752. $items = array();
  753. foreach($branches as $id => $name)
  754. {
  755. if($id === '' && $name != BRANCH_MAIN) continue;
  756. $items[] = array('text' => $name, 'value' => $id, 'keys' => $name);
  757. }
  758. return print(json_encode($items));
  759. }
  760. /**
  761. * 获取未关联计划的分支的提示信息。
  762. * AJAX: Get diff branches tips.
  763. *
  764. * @param int $productID
  765. * @param int $parentID
  766. * @param string $branches
  767. * @access public
  768. * @return void
  769. */
  770. public function ajaxGetDiffBranchesTip($productID = 0, $parentID = 0, $branches = '')
  771. {
  772. if(empty($parentID) || empty($productID)) return;
  773. /* If it has children, return. */
  774. $parentBranch = $this->productplan->getByID($parentID);
  775. if($parentBranch->parent == '-1') return;
  776. /* Find diff branches between parent plan and child plan. */
  777. $diffBranches = array();
  778. $diffBranchesTip = '';
  779. $product = $this->loadModel('product')->getByID($productID);
  780. $branchPairs = $this->loadModel('branch')->getPairs($productID);
  781. foreach(explode(',', $parentBranch->branch) as $parentBranchID)
  782. {
  783. if(empty($parentBranchID)) continue;
  784. if(strpos(",$branches,", ",$parentBranchID,") === false)
  785. {
  786. $diffBranches[$parentBranchID] = $parentBranchID;
  787. $diffBranchesTip .= "{$branchPairs[$parentBranchID]},";
  788. }
  789. }
  790. if(empty($diffBranchesTip)) return;
  791. /* Find stories and bugs in diff branches. */
  792. $unlinkStories = $this->productplan->checkUnlinkObjects($diffBranches, $parentID, 'story');
  793. $unlinkBugs = $this->productplan->checkUnlinkObjects($diffBranches, $parentID, 'bug');
  794. if(empty($unlinkStories) && empty($unlinkBugs)) return;
  795. $this->lang->productplan->diffBranchesTip = str_replace('@branch@', $this->lang->product->branchName[$product->type], $this->lang->productplan->diffBranchesTip);
  796. printf($this->lang->productplan->diffBranchesTip, trim($diffBranchesTip, ','));
  797. }
  798. /**
  799. * 计划下的需求列表。
  800. * Story list block for document.
  801. *
  802. * @param int $productID
  803. * @param int $planID
  804. * @param int $blockID
  805. * @param string $orderBy
  806. * @param int $recTotal
  807. * @param int $recPerPage
  808. * @param int $pageID
  809. * @access public
  810. * @return void
  811. * @param string $from
  812. */
  813. public function story($productID = 0, $planID = 0, $blockID = 0, $orderBy = 'order', $recTotal = 0, $recPerPage = 20, $pageID = 1, $from = 'doc')
  814. {
  815. $this->app->loadLang('doc');
  816. $products = $this->loadModel('product')->getPairs('nodeleted', 0, '', 'all');
  817. if(($this->app->tab == 'doc' || $from == 'ai') && empty($products)) return $this->send(array('result' => 'fail', 'message' => $this->lang->doc->tips->noProduct));
  818. if(empty($productID) && empty($this->session->product)) $productID = (int)key($products);
  819. $this->app->loadClass('pager', true);
  820. $pager = new pager($recTotal, $recPerPage, $pageID);
  821. $planStories = $this->loadModel('story')->getPlanStories($planID, 'all', $orderBy, $pager);
  822. if($planStories) $this->productplanZen->reorderStories();
  823. $modulePairs = $this->loadModel('tree')->getOptionMenu($productID, 'story', 0, 'all');
  824. foreach($planStories as $story)
  825. {
  826. if(!isset($modulePairs[$story->module])) $modulePairs += $this->tree->getModulesName((array)$story->module);
  827. }
  828. $idList = '';
  829. $docBlock = $this->loadModel('doc')->getDocBlock($blockID);
  830. if($docBlock)
  831. {
  832. $content = json_decode($docBlock->content, true);
  833. if(isset($content['idList'])) $idList = $content['idList'];
  834. }
  835. $gradeList = $this->loadModel('story')->getGradeList('');
  836. $gradeGroup = array();
  837. foreach($gradeList as $grade) $gradeGroup[$grade->type][$grade->grade] = $grade->name;
  838. $this->view->title = $this->lang->doc->zentaoList['planStory'];
  839. $this->view->product = $this->product->getByID($productID);
  840. $this->view->products = $products;
  841. $this->view->branchOption = $this->loadModel('branch')->getPairs($productID);
  842. $this->view->plans = $this->loadModel('productplan')->getPairs($productID, '', '', true);
  843. $this->view->planStories = $planStories;
  844. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  845. $this->view->modulePairs = $modulePairs;
  846. $this->view->productID = $productID;
  847. $this->view->planID = $planID;
  848. $this->view->gradeGroup = $gradeGroup;
  849. $this->view->blockID = $blockID;
  850. $this->view->docBlock = $docBlock;
  851. $this->view->idList = $idList;
  852. $this->view->orderBy = $orderBy;
  853. $this->view->pager = $pager;
  854. $this->view->from = $from;
  855. $this->display();
  856. }
  857. /**
  858. * 计划下的Bug列表。
  859. * Bug list block for document.
  860. *
  861. * @param int $productID
  862. * @param int $planID
  863. * @param int $blockID
  864. * @param string $orderBy
  865. * @param int $recTotal
  866. * @param int $recPerPage
  867. * @param int $pageID
  868. * @access public
  869. * @return void
  870. * @param string $from
  871. */
  872. public function bug($productID = 0, $planID = 0, $blockID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1, $from = 'doc')
  873. {
  874. $this->app->loadLang('doc');
  875. $products = $this->loadModel('product')->getPairs('nodeleted', 0, '', 'all');
  876. if(($this->app->tab == 'doc' || $from == 'ai') && empty($products)) return $this->send(array('result' => 'fail', 'message' => $this->lang->doc->tips->noProduct));
  877. if(empty($productID) && empty($this->session->product)) $productID = (int)key($products);
  878. $idList = '';
  879. $docBlock = $this->loadModel('doc')->getDocBlock($blockID);
  880. if($docBlock)
  881. {
  882. $content = json_decode($docBlock->content, true);
  883. if(isset($content['idList'])) $idList = $content['idList'];
  884. }
  885. $this->app->loadClass('pager', true);
  886. $pager = new pager($recTotal, $recPerPage, $pageID);
  887. $this->view->title = $this->lang->doc->zentaoList['planStory'];
  888. $this->view->products = $products;
  889. $this->view->plans = $this->loadModel('productplan')->getPairs($productID, '', '', true);
  890. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  891. $this->view->productID = $productID;
  892. $this->view->planID = $planID;
  893. $this->view->blockID = $blockID;
  894. $this->view->docBlock = $docBlock;
  895. $this->view->bugs = $planID ? $this->loadModel('bug')->getPlanBugs($planID, 'all', $orderBy, $pager) : array();
  896. $this->view->idList = $idList;
  897. $this->view->orderBy = $orderBy;
  898. $this->view->pager = $pager;
  899. $this->view->from = $from;
  900. $this->display();
  901. }
  902. }