risk.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * The risk 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 riskEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $riskID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($riskID)
  22. {
  23. $control = $this->loadController('risk', 'view');
  24. $control->view($riskID);
  25. $data = $this->getData();
  26. if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
  27. if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->risk, 'createdDate:time,editedDate:time'));
  28. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  29. $this->sendError(400, 'error');
  30. }
  31. /**
  32. * PUT method.
  33. *
  34. * @param int $riskID
  35. * @access public
  36. * @return string
  37. */
  38. public function put($riskID)
  39. {
  40. $control = $this->loadController('risk', 'edit');
  41. $oldRisk = $this->loadModel('risk')->getByID($riskID);
  42. if(!$oldRisk) return $this->send404();
  43. /* Set $_POST variables. */
  44. $fields = 'source,name,category,strategy,status,impact,probability,rate,identifiedDate,plannedClosedDate,actualClosedDate,resolvedBy,assignedTo,prevention,remedy,resolution';
  45. $this->batchSetPost($fields, $oldRisk);
  46. $control->edit($riskID);
  47. $data = $this->getData();
  48. if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
  49. $risk = $this->risk->getByID($riskID);
  50. return $this->send(200, $this->format($risk, 'createdDate:time,editedDate:time'));
  51. }
  52. /**
  53. * DELETE method.
  54. *
  55. * @param int $riskID
  56. * @access public
  57. * @return string
  58. */
  59. public function delete($riskID)
  60. {
  61. $control = $this->loadController('risk', 'delete');
  62. $control->delete($riskID, 'true');
  63. $this->getData();
  64. return $this->sendSuccess(200, 'success');
  65. }
  66. }