todos.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * The todos 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 todosEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @access public
  18. * @return string
  19. */
  20. public function get()
  21. {
  22. $control = $this->loadController('my', 'todo');
  23. $control->todo($this->param('type', 'all'), $this->param('userID', ''), $this->param('status', 'all'), $this->param('order', 'date_desc,status,begin'), $this->param('total', 0), $this->param('limit', 100), $this->param('page', 1));
  24. $data = $this->getData();
  25. if(!isset($data->status)) return $this->sendError(400, 'error');
  26. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  27. $pager = $data->data->pager;
  28. $result = array();
  29. foreach($data->data->todos as $todo)
  30. {
  31. $result[] = $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time');
  32. }
  33. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'todos' => $result));
  34. }
  35. /**
  36. * POST method.
  37. *
  38. * @access public
  39. * @return string
  40. */
  41. public function post()
  42. {
  43. $control = $this->loadController('todo', 'create');
  44. $fields = 'name,desc,begin,end,private';
  45. $this->batchSetPost($fields);
  46. $this->setPost('date', $this->request('date', date("Y-m-d")));
  47. $this->setPost('type', $this->request('type', 'custom'));
  48. $this->setPost('status', $this->request('status', 'wait'));
  49. $this->setPost('begin', str_replace(':', '', $this->request('begin')));
  50. $this->setPost('end', str_replace(':', '', $this->request('end')));
  51. $this->setPost('pri', $this->request('pri', '3'));
  52. $this->requireFields('name');
  53. $control->create();
  54. $data = $this->getData();
  55. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  56. if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
  57. $todo = $this->loadModel('todo')->getByID($data->id);
  58. return $this->send(201, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time'));
  59. }
  60. }