todo.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * The todo 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 todoEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $todoID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($todoID)
  22. {
  23. $control = $this->loadController('todo', 'view');
  24. $control->view($todoID, $this->param('from', 'my'));
  25. $data = $this->getData();
  26. if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
  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. $todo = $data->data->todo;
  30. return $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time'));
  31. }
  32. /**
  33. * PUT method.
  34. *
  35. * @param int $todoID
  36. * @access public
  37. * @return string
  38. */
  39. public function put($todoID)
  40. {
  41. $control = $this->loadController('todo', 'edit');
  42. $oldTodo = $this->loadModel('todo')->getByID($todoID);
  43. /* Set $_POST variables. */
  44. $fields = 'date,type,name,pri,desc,status,begin,end,private';
  45. $this->batchSetPost($fields, $oldTodo);
  46. $this->setPost('objectID', 0);
  47. $this->setPost('date', $this->request('date', date("Y-m-d", strtotime($oldTodo->date))));
  48. $this->setPost('begin', $this->request('begin') ? str_replace(':', '', $this->request('begin')) : $oldTodo->begin);
  49. $this->setPost('end', $this->request('end') ? str_replace(':', '', $this->request('end')) : $oldTodo->end);
  50. $control->edit($todoID);
  51. $data = $this->getData();
  52. if(!isset($data->status)) return $this->sendError(400, 'error');
  53. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  54. $todo = $this->todo->getByID($todoID);
  55. return $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time'));
  56. }
  57. /**
  58. * DELETE method.
  59. *
  60. * @param int $todoID
  61. * @access public
  62. * @return string
  63. */
  64. public function delete($todoID)
  65. {
  66. $control = $this->loadController('todo', 'delete');
  67. $control->delete($todoID, 'yes');
  68. $this->getData();
  69. return $this->sendSuccess(200, 'success');
  70. }
  71. }