task.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * The task 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 taskEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $taskID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($taskID)
  22. {
  23. $this->resetOpenApp($this->param('tab', 'execution'));
  24. $control = $this->loadController('task', 'view');
  25. $control->view($taskID);
  26. $data = $this->getData();
  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. $task = $data->data->task;
  30. if(!empty($task->children)) $task->children = array_values((array)$task->children);
  31. if($task->parent > 0) $task->parentPri = $this->dao->findById($task->parent)->from(TABLE_TASK)->fetch('pri');
  32. /* Set execution name */
  33. $task->executionName = $data->data->execution->name;
  34. $task->executionStatus = $data->data->execution->status;
  35. /* Set module title */
  36. $moduleTitle = '';
  37. if(empty($task->module)) $moduleTitle = '/';
  38. if($task->module)
  39. {
  40. $modulePath = $data->data->modulePath;
  41. foreach($modulePath as $key => $module)
  42. {
  43. $moduleTitle .= $module->name;
  44. if(isset($modulePath[$key + 1])) $moduleTitle .= '/';
  45. }
  46. }
  47. $task->moduleTitle = $moduleTitle;
  48. $queryAccounts = array();
  49. if($task->assignedTo) $queryAccounts[$task->assignedTo] = $task->assignedTo;
  50. if(!empty($task->team))
  51. {
  52. foreach($task->team as $account => $team) $queryAccounts[$account] = $account;
  53. }
  54. $usersWithAvatar = $this->loadModel('user')->getListByAccounts($queryAccounts, 'account');
  55. if(!empty($task->team))
  56. {
  57. $teams = array();
  58. foreach($task->team as $account => $team)
  59. {
  60. $user = zget($usersWithAvatar, $account, '');
  61. $team->realname = $user ? $user->realname : $account;
  62. $team->avatar = $user ? $user->avatar : '';
  63. $team->estimate = round($team->estimate, 1);
  64. $team->consumed = round($team->consumed, 1);
  65. $team->left = round($team->left, 1);
  66. $allHours = $team->consumed + $team->left;
  67. $team->progress = empty($allHours) ? 0 : round($team->consumed / $allHours * 100, 1);
  68. $teams[] = $team;
  69. }
  70. $task->team = $teams;
  71. }
  72. $task->actions = $this->loadModel('action')->processActionForAPI($data->data->actions, $data->data->users, $this->lang->task);
  73. $preAndNext = $data->data->preAndNext;
  74. $task->preAndNext = array();
  75. $task->preAndNext['pre'] = $preAndNext->pre ? $preAndNext->pre->id : '';
  76. $task->preAndNext['next'] = $preAndNext->next ? $preAndNext->next->id : '';
  77. $operateMenu = $this->loadModel('common')->buildOperateMenu($task, 'task');
  78. $task->operateMenu = array_column(zget($operateMenu, 'mainActions', array()), 'name');
  79. return $this->send(200, $this->format($task, 'deadline:date,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,realStarted:time,finishedBy:user,finishedDate:time,closedBy:user,closedDate:time,canceledBy:user,canceledDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool,mailto:userList'));
  80. }
  81. /**
  82. * PUT method.
  83. *
  84. * @param int $taskID
  85. * @access public
  86. * @return string
  87. */
  88. public function put($taskID)
  89. {
  90. $control = $this->loadController('task', 'edit');
  91. $oldTask = $this->loadModel('task')->getByID($taskID);
  92. /* Set $_POST variables. */
  93. $fields = 'name,type,mode,desc,assignedTo,pri,estimate,left,consumed,story,parent,execution,module,closedReason,status,estStarted,deadline,team,teamEstimate,teamConsumed,teamLeft,multiple,mailto,uid,teamSource,team,teamEstimate,teamConsumed,teamLeft';
  94. $this->batchSetPost($fields, $oldTask);
  95. if($_POST['status'] == 'done')
  96. {
  97. if(!empty($oldTask->finishedBy)) $this->setPost('finishedBy', $oldTask->finishedBy);
  98. if(!empty($oldTask->finishedDate)) $this->setPost('finishedDate', $oldTask->finishedDate);
  99. }
  100. $control->edit($taskID);
  101. $data = $this->getData();
  102. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  103. $task = $this->task->getByID($taskID);
  104. return $this->send(200, $this->format($task, 'deadline:date,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,realStarted:time,finishedBy:user,finishedDate:time,closedBy:user,closedDate:time,canceledBy:user,canceledDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool,mailto:userList'));
  105. }
  106. /**
  107. * DELETE method.
  108. *
  109. * @param int $taskID
  110. * @access public
  111. * @return string
  112. */
  113. public function delete($taskID)
  114. {
  115. $control = $this->loadController('task', 'delete');
  116. $control->delete(0, $taskID, 'true');
  117. $this->getData();
  118. return $this->sendSuccess(200, 'success');
  119. }
  120. }