risks.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * The risks 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 risksEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $projectID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($projectID = 0)
  22. {
  23. if(!$projectID)
  24. {
  25. /* Get my risks defaultly. */
  26. $control = $this->loadController('my', 'risk');
  27. $control->risk($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
  28. $data = $this->getData();
  29. }
  30. else
  31. {
  32. $project = $this->loadModel('project')->getByID($projectID);
  33. if(!$project) return $this->send404();
  34. /* Get risks by project. */
  35. $control = $this->loadController('risk', 'browse');
  36. $control->browse($projectID, $this->param('type', 'all'), '', $this->param('order', ''), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
  37. $data = $this->getData();
  38. }
  39. if(!isset($data->status)) return $this->sendError(400, 'error');
  40. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  41. $pager = $data->data->pager;
  42. $result = array();
  43. foreach($data->data->risks as $risk)
  44. {
  45. $result[] = $this->format($risk, 'createdDate:time,editedDate:time');
  46. }
  47. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'risks' => $result));
  48. }
  49. /**
  50. * POST method.
  51. *
  52. * @param int $projectID
  53. * @access public
  54. * @return string
  55. */
  56. public function post($projectID = 0)
  57. {
  58. $control = $this->loadController('risk', 'create');
  59. $project = $this->loadModel('project')->getByID($projectID);
  60. if(!$project) return $this->send404();
  61. $fields = 'source,name,category,strategy,status,impact,probability,rate,identifiedDate,plannedClosedDate,actualClosedDate,resolvedBy,assignedTo,prevention,remedy,resolution';
  62. $this->batchSetPost($fields);
  63. $this->setPost('impact', $this->request('impact', 3));
  64. $this->setPost('probability', $this->request('probability', 3));
  65. $this->setPost('rate', $this->request('rate', 9));
  66. $this->setPost('pri', 'middle');
  67. $this->requireFields('name');
  68. $control->create($projectID);
  69. $data = $this->getData();
  70. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  71. if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
  72. $risk = $this->loadModel('risk')->getByID($data->id);
  73. return $this->send(201, $this->format($risk, 'createdDate:time,editedDate:time'));
  74. }
  75. }