productprojects.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * The product projects 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 productProjectsEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $productID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($productID = 0)
  22. {
  23. if(empty($productID)) $productID = $this->param('product', 0);
  24. if(empty($productID)) return $this->sendError('400', "Need product id");
  25. $appendFields = $this->param('fields', '');
  26. $control = $this->loadController('product', 'project');
  27. $control->project($this->param('status', 'all'), $productID, $this->param('branch', 0), $this->param('involved', 0), $this->param('order', 'order_desc'), 0, $this->param('limit', 20), $this->param('page', 1));
  28. $data = $this->getData();
  29. if(isset($data->status) and $data->status == 'success')
  30. {
  31. $result = array();
  32. foreach($data->data->projectStats as $project)
  33. {
  34. foreach($project->hours as $field => $value) $project->$field = $value;
  35. $project = $this->filterFields($project, 'id,name,code,model,type,budget,budgetUnit,parent,begin,end,status,openedBy,openedDate,PM,delay,progress,' . $appendFields);
  36. $result[] = $this->format($project, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time');
  37. }
  38. $data = array();
  39. $data['total'] = count($result);
  40. $data['projects'] = $result;
  41. $withUser = $this->param('withUser', '');
  42. if(!empty($withUser)) $data['users'] = $users;
  43. return $this->send(200, $data);
  44. }
  45. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  46. // TODO There is no handle for 401.
  47. return $this->sendError(400, 'error');
  48. }
  49. /**
  50. * POST method.
  51. *
  52. * @access public
  53. * @return string
  54. */
  55. public function post()
  56. {
  57. $control = $this->loadController('project', 'create');
  58. $fields = 'name,begin,end,products';
  59. $this->batchSetPost($fields);
  60. $this->setPost('code', $this->request('code', ''));
  61. $this->setPost('acl', $this->request('acl', 'private'));
  62. $this->setPost('parent', $this->request('program', 0));
  63. $this->setPost('whitelist', $this->request('whitelist', array()));
  64. $this->setPost('PM', $this->request('PM', ''));
  65. $this->setPost('model', $this->request('model', 'scrum'));
  66. $this->requireFields('name,code,begin,end,products');
  67. $control->create($this->request('model', 'scrum'));
  68. $data = $this->getData();
  69. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  70. if(!isset($data->result)) return $this->sendError(400, 'error');
  71. $project = $this->loadModel('project')->getByID($data->id);
  72. return $this->send(201, $this->format($project, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time'));
  73. }
  74. /**
  75. * Get drop menu.
  76. *
  77. * @access public
  78. * @return string
  79. */
  80. public function getDropMenu()
  81. {
  82. $control = $this->loadController('project', 'ajaxGetDropMenu');
  83. $control->ajaxGetDropMenu($this->request('projectID', 0), $this->request('module', 'project'), $this->request('method', 'browse'));
  84. $data = $this->getData();
  85. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  86. $dropMenu = array('owner' => array(), 'other' => array(), 'closed' => array());
  87. foreach($data->data->projects as $programID => $projects)
  88. {
  89. foreach($projects as $project)
  90. {
  91. if(helper::diffDate(date('Y-m-d'), $project->end) > 0) $project->delay = true;
  92. $project = $this->filterFields($project, 'id,model,type,name,code,parent,status,PM,delay');
  93. if($project->status == 'closed')
  94. {
  95. $dropMenu['closed'][] = $project;
  96. }
  97. elseif($project->PM == $this->app->user->account)
  98. {
  99. $dropMenu['owner'][] = $project;
  100. }
  101. else
  102. {
  103. $dropMenu['other'][] = $project;
  104. }
  105. }
  106. }
  107. return $this->send(200, $dropMenu);
  108. }
  109. }