product.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * The product entry point 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 entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class productEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $productID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($productID)
  22. {
  23. $fields = $this->param('fields');
  24. $control = $this->loadController('product', 'view');
  25. $control->view($productID);
  26. $data = $this->getData();
  27. if(!$data or !isset($data->status)) return $this->send400('error');
  28. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  29. $product = $this->format($data->data->product, 'createdDate:time,whitelist:userList,createdBy:user,PO:user,RD:user,QD:user,feedback:user');
  30. $this->loadModel('testcase');
  31. $product->caseReview = ($this->config->testcase->needReview or !empty($this->config->testcase->forceReview));
  32. if(!$fields) return $this->send(200, $product);
  33. /* Set other fields. */
  34. $fields = explode(',', strtolower($fields));
  35. foreach($fields as $field)
  36. {
  37. switch($field)
  38. {
  39. case 'modules':
  40. $control = $this->loadController('tree', 'browse');
  41. $control->browse($productID, 'story');
  42. $data = $this->getData();
  43. if(isset($data->status) and $data->status == 'success')
  44. {
  45. $product->modules = $data->data->tree;
  46. }
  47. break;
  48. case 'execution':
  49. $product->execution = $this->loadModel('product')->getExecutionPairsByProduct($productID);
  50. break;
  51. case 'bugstatistic':
  52. $product->bugStatistic = $this->loadModel('bug')->getStatistic($productID);
  53. break;
  54. case 'moduleoptionmenu':
  55. $modules = $this->loadModel('tree')->getOptionMenu($productID, $this->param('moduleType', 'story'));
  56. $product->moduleOptionMenu = array();
  57. foreach($modules as $id => $name) $product->moduleOptionMenu[] = array('id' => $id, 'name' => $name);
  58. break;
  59. case 'parentstories':
  60. $product->parentstories= $this->loadModel('story')->getParentStoryPairs($productID);
  61. break;
  62. case 'builds':
  63. $product->builds = $this->loadModel('build')->getBuildPairs(array($productID), 'all', 'noempty,noterminate,nodone,withbranch', $this->param('object', 0), $this->param('objectType', 'execution'));
  64. break;
  65. case 'actions':
  66. $product->addComment = common::hasPriv('action', 'comment') ? true : false;
  67. $users = $this->loadModel('user')->getPairs();
  68. $actions = $data->data->actions;
  69. $product->actions = $this->loadModel('action')->processActionForAPI($actions, $users, $this->lang->product);
  70. break;
  71. case 'lastexecution':
  72. $execution = $this->dao->select('t2.id,t2.name,t2.type,t2.progress')->from(TABLE_PROJECTPRODUCT)->alias('t1')
  73. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  74. ->where('t2.deleted')->eq(0)
  75. ->andWhere('t1.product')->eq($productID)
  76. ->andWhere('t2.type')->in('sprint,stage')
  77. ->orderBy('t2.id desc')
  78. ->limit(1)
  79. ->fetch();
  80. $product->lastExecution = $execution;
  81. break;
  82. }
  83. }
  84. return $this->send(200, $product);
  85. }
  86. /**
  87. * PUT method.
  88. *
  89. * @param int $productID
  90. * @access public
  91. * @return string
  92. */
  93. public function put($productID)
  94. {
  95. $control = $this->loadController('product', 'edit');
  96. $useCode = $this->checkCodeUsed();
  97. $oldProduct = $this->loadModel('product')->getByID($productID);
  98. /* Set $_POST variables. */
  99. $fields = 'program,line,name,PO,QD,RD,type,desc,whitelist,status,acl';
  100. if($useCode) $fields .= ',code';
  101. $this->batchSetPost($fields, $oldProduct);
  102. $control->edit($productID);
  103. $data = $this->getData();
  104. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  105. $product = $this->product->getByID($productID);
  106. return $this->send(200, $this->format($product, 'createdDate:time,whitelist:userList,createdBy:user,PO:user,RD:user,QD:user'));
  107. }
  108. /**
  109. * DELETE method.
  110. *
  111. * @param int $productID
  112. * @access public
  113. * @return string
  114. */
  115. public function delete($productID)
  116. {
  117. $control = $this->loadController('product', 'delete');
  118. $control->delete($productID, 'yes');
  119. $this->getData();
  120. return $this->sendSuccess(200, 'success');
  121. }
  122. }