taskfinish.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * The task finish 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 taskFinishEntry extends entry
  13. {
  14. /**
  15. * POST method.
  16. *
  17. * @param int $taskID
  18. * @access public
  19. * @return string
  20. */
  21. public function post($taskID)
  22. {
  23. $control = $this->loadController('task', 'finish');
  24. $task = $this->loadModel('task')->getByID($taskID);
  25. $fields = 'assignedTo,realStarted';
  26. $this->batchSetPost($fields, $task);
  27. $fields = 'finishedDate,comment';
  28. $this->batchSetPost($fields);
  29. $realStarted = $this->request('realStarted', (isset($task->realStarted) and !helper::isZeroDate($task->realStarted)) ? $task->realStarted : '');
  30. if($realStarted) $this->setPost('realStarted', $realStarted);
  31. $this->setPost('currentConsumed', $this->request('currentConsumed', 0));
  32. $this->setPost('consumed', $this->request('currentConsumed', 0) + $task->consumed);
  33. $this->requireFields('currentConsumed,realStarted,finishedDate');
  34. $control->finish($taskID);
  35. $data = $this->getData();
  36. if(!$data) return $this->send400('error');
  37. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  38. $task = $this->loadModel('task')->getByID($taskID);
  39. return $this->send(200, $this->format($task, 'openedDate:time,assignedDate:time,realStarted:time,finishedDate:time,canceledDate:time,closedDate:time,lastEditedDate:time'));
  40. }
  41. }