lite.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Get the project or execution in which the user participates..
  4. *
  5. * @param string $account
  6. * @param string $type project|execution
  7. * @param string $status
  8. * @param string $orderBy
  9. * @param object $pager
  10. * @access public
  11. * @return array
  12. */
  13. public function getObjects($account, $type = 'execution', $status = 'all', $orderBy = 'id_desc', $pager = null)
  14. {
  15. $objectType = $type == 'execution' ? 'sprint,stage,kanban' : $type;
  16. $myObjectsList = $this->dao->select('t1.*,t2.*')->from(TABLE_TEAM)->alias('t1')
  17. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.root = t2.id')
  18. ->where('t1.type')->eq($type)
  19. ->andWhere('t2.type')->in($objectType)
  20. ->beginIF(strpos('doing|wait|suspended|closed', $status) !== false)->andWhere('status')->eq($status)->fi()
  21. ->beginIF($status == 'done')->andWhere('status')->in('done,closed')->fi()
  22. ->beginIF($status == 'undone')->andWhere('status')->notin('done,closed')->fi()
  23. ->beginIF($status == 'openedbyme')->andWhere('openedBy')->eq($account)->fi()
  24. ->beginIF($type == 'execution' and !$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->sprints)->fi()
  25. ->beginIF($type == 'project' and !$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->projects)->fi()
  26. ->andWhere('t1.account')->eq($account)
  27. ->andWhere('t2.deleted')->eq(0)
  28. ->andWhere('t2.vision')->eq($this->config->vision)
  29. ->orderBy("t2.$orderBy")
  30. ->page($pager)
  31. ->fetchAll('root');
  32. $objectIdList = array();
  33. $projectIdList = array();
  34. foreach($myObjectsList as $object)
  35. {
  36. $objectIdList[] = $object->id;
  37. $projectIdList[] = $object->project;
  38. }
  39. /* Get all tasks and compute totalConsumed, totalLeft, totalWait, progress according to them. */
  40. $hours = array();
  41. $emptyHour = array('totalConsumed' => 0, 'totalLeft' => 0, 'progress' => 0, 'waitTasks' => 0, 'assignedToMeTasks' => 0, 'doneTasks' => 0, 'taskTotal' => 0);
  42. $searchField = $type == 'project' ? 'project' : 'execution';
  43. $tasks = $this->dao->select('id, project, execution, consumed, `left`, status, assignedTo,finishedBy')
  44. ->from(TABLE_TASK)
  45. ->where('parent')->lt(1)
  46. ->andWhere($searchField)->in($objectIdList)->fi()
  47. ->andWhere('deleted')->eq(0)
  48. ->fetchGroup($searchField, 'id');
  49. /* Compute totalEstimate, totalConsumed, totalLeft. */
  50. foreach($tasks as $objectID => $objectTasks)
  51. {
  52. $hour = (object)$emptyHour;
  53. $hour->taskTotal = count($objectTasks);
  54. foreach($objectTasks as $task)
  55. {
  56. if($task->status == 'wait') $hour->waitTasks += 1;
  57. if($task->finishedBy != '') $hour->doneTasks += 1;
  58. if($task->status != 'cancel') $hour->totalConsumed += $task->consumed;
  59. if($task->status != 'cancel' and $task->status != 'closed') $hour->totalLeft += $task->left;
  60. if($task->assignedTo == $account) $hour->assignedToMeTasks += 1;
  61. }
  62. $hours[$objectID] = $hour;
  63. }
  64. /* Compute totalReal and progress. */
  65. foreach($hours as $hour)
  66. {
  67. $hour->totalConsumed = round($hour->totalConsumed, 1);
  68. $hour->totalLeft = round($hour->totalLeft, 1);
  69. $hour->totalReal = $hour->totalConsumed + $hour->totalLeft;
  70. $hour->progress = $hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0;
  71. }
  72. $myObjects = array();
  73. $projectList = $this->loadModel('project')->getByIdList($projectIdList);
  74. foreach($myObjectsList as $object)
  75. {
  76. /* Judge whether the project or execution is delayed. */
  77. if($object->status != 'done' and $object->status != 'closed' and $object->status != 'suspended')
  78. {
  79. $delay = helper::diffDate(helper::today(), $object->end);
  80. if($delay > 0) $object->delay = $delay;
  81. }
  82. /* Process the hours. */
  83. $object->progress = isset($hours[$object->id]) ? $hours[$object->id]->progress : 0;
  84. $object->waitTasks = isset($hours[$object->id]) ? $hours[$object->id]->waitTasks : 0;
  85. $object->doneTasks = isset($hours[$object->id]) ? $hours[$object->id]->doneTasks : 0;
  86. $object->taskTotal = isset($hours[$object->id]) ? $hours[$object->id]->taskTotal : 0;
  87. $object->totalConsumed = isset($hours[$object->id]) ? $hours[$object->id]->totalConsumed : 0;
  88. $object->assignedToMeTasks = isset($hours[$object->id]) ? $hours[$object->id]->assignedToMeTasks : 0;
  89. if($object->project)
  90. {
  91. $parentProject = zget($projectList, $object->project, '');
  92. $object->projectName = $parentProject ? $parentProject->name : '';
  93. }
  94. $myObjects[$object->id] = $object;
  95. }
  96. return $myObjects;
  97. }
  98. /**
  99. * @param object $user
  100. */
  101. public function getFeatureBarMenus($user)
  102. {
  103. $featureBarMenus = parent::getFeatureBarMenus($user);
  104. $liteBarMenus = array();
  105. $liteBarMenus['todo'] = $featureBarMenus['todo'];
  106. $liteBarMenus['task'] = $featureBarMenus['task'];
  107. $liteBarMenus['story'] = $featureBarMenus['story'];
  108. $liteBarMenus['execution'] = $featureBarMenus['execution'];
  109. $liteBarMenus['dynamic'] = $featureBarMenus['dynamic'];
  110. $liteBarMenus['profile'] = $featureBarMenus['profile'];
  111. return $liteBarMenus;
  112. }