count_of_assigned_task.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * 按人员统计的任务数。
  4. * Count of assigned task in user.
  5. *
  6. * 范围:user
  7. * 对象:task
  8. * 目的:scale
  9. * 度量名称:按人员统计的任务数
  10. * 单位:个
  11. * 描述:按人员统计的任务数表示每个人的任务数量之和。反映了每个人在需要处理的任务数量上的规模。该数值越大,说明需要投入越多的时间处理任务。
  12. * 定义:所有任务个数求和;指派给为某人;过滤已删除的任务;过滤已删除项目的任务;过滤已删除执行的任务;
  13. *
  14. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  15. * @author Zemei Wang <wangzemei@easycorp.ltd>
  16. * @package
  17. * @uses func
  18. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  19. * @Link https://www.zentao.net
  20. */
  21. class count_of_assigned_task extends baseCalc
  22. {
  23. public $dataset = '';
  24. public $fieldList = array();
  25. public $result = array();
  26. public function calculate($row)
  27. {
  28. $assignedTo = $row->assignedTo;
  29. $mode = $row->mode;
  30. if($row->status == 'closed') return false;
  31. if($mode == 'multi')
  32. {
  33. foreach(explode(',', $row->teamMembers) as $user)
  34. {
  35. if(!$user) continue;
  36. if(!isset($this->result[$user])) $this->result[$user] = array();
  37. $this->result[$user][$row->id] = $row->id;
  38. }
  39. }
  40. else
  41. {
  42. if(!isset($this->result[$assignedTo])) $this->result[$assignedTo] = array();
  43. $this->result[$assignedTo][$row->id] = $row->id;
  44. }
  45. }
  46. public function getResult($options = array())
  47. {
  48. foreach($this->result as $assignedTo => $tasks)
  49. {
  50. if(!is_array($tasks))
  51. {
  52. unset($this->result[$assignedTo]);
  53. continue;
  54. }
  55. $this->result[$assignedTo] = count($tasks);
  56. }
  57. $records = $this->getRecords(array('user', 'value'));
  58. return $this->filterByOptions($records, $options);
  59. }
  60. }