tao.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * The model file of user module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Gang Liu <liugang@easycorp.ltd>
  8. * @package user
  9. * @link https://www.zentao.net
  10. */
  11. class userTao extends userModel
  12. {
  13. /**
  14. * 获取某个用户参与的项目和他在项目中的团队信息。
  15. * Get the projects that the user joined.
  16. *
  17. * @param string $account
  18. * @param string $status
  19. * @param string $orderBy
  20. * @param object $pager
  21. * @access public
  22. * @return array
  23. */
  24. public function fetchProjects($account, $status = 'all', $orderBy = 'id_desc', $pager = null)
  25. {
  26. return $this->dao->select('t1.role, t1.join, t1.days, t1.hours, t2.*')->from(TABLE_TEAM)->alias('t1')
  27. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.root = t2.id')
  28. ->where('t1.type')->eq('project')
  29. ->andWhere('t1.account')->eq($account)
  30. ->andWhere('t2.deleted')->eq('0')
  31. ->andWhere('t2.type')->eq('project')
  32. ->andWhere('t2.vision')->eq($this->config->vision)
  33. ->beginIF(strpos('doing|wait|suspended|closed', $status) !== false)->andWhere('t2.status')->eq($status)->fi()
  34. ->beginIF($status == 'done')->andWhere('t2.status')->in('done,closed')->fi()
  35. ->beginIF($status == 'undone')->andWhere('t2.status')->notin('done,closed')->fi()
  36. ->beginIF($status == 'openedbyme')->andWhere('t2.openedBy')->eq($account)->fi()
  37. ->beginIF($status == 'delayed')->andWhere('t2.status')->notIn('done,closed,suspend')->andWhere('t2.end')->lt(helper::today())->fi()
  38. ->beginIF(!$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->projects)->fi()
  39. ->orderBy("t2.$orderBy")
  40. ->page($pager)
  41. ->fetchAll('id');
  42. }
  43. /**
  44. * 获取某个用户参与的项目和项目包含的执行数键值对。
  45. * Get the projects that the user joined and the execution count of the project.
  46. *
  47. * @param array $projectIdList
  48. * @access public
  49. * @return array
  50. */
  51. public function fetchProjectExecutionCount($projectIdList)
  52. {
  53. if(!$projectIdList) return array();
  54. return $this->dao->select('project, COUNT(1) AS count')->from(TABLE_PROJECT)
  55. ->where('deleted')->eq('0')
  56. ->andWhere('multiple')->eq('1')
  57. ->andWhere('vision')->eq($this->config->vision)
  58. ->andWhere('type')->in('sprint,stage,kanban')
  59. ->andWhere('project')->in($projectIdList)
  60. ->groupBy('project')
  61. ->fetchPairs();
  62. }
  63. /**
  64. * 获取某个用户参与的项目和项目关联的需求规模数和需求数。
  65. * Get the projects that the user joined and the story estimate and count of the project.
  66. *
  67. * @param array $projectIdList
  68. * @access public
  69. * @return array
  70. */
  71. public function fetchProjectStoryCountAndEstimate($projectIdList)
  72. {
  73. if(!$projectIdList) return array();
  74. return $this->dao->select('t1.id, count(t3.id) as count, SUM(IFNULL(t3.estimate, 0)) AS estimate')->from(TABLE_PROJECT)->alias('t1')
  75. ->leftJoin(TABLE_PROJECTSTORY)->alias('t2')->on('t1.id = t2.project')
  76. ->leftJoin(TABLE_STORY)->alias('t3')->on('t2.story = t3.id')
  77. ->where('t1.deleted')->eq('0')
  78. ->andWhere('t1.vision')->eq($this->config->vision)
  79. ->andWhere('t1.id')->in($projectIdList)
  80. ->groupBy('t1.id')
  81. ->fetchAll('id');
  82. }
  83. /**
  84. * 获取某个用户参与的执行和他在执行中的团队信息。
  85. * Get the executions that the user joined.j
  86. *
  87. * @param string $account
  88. * @param string $status
  89. * @param string $orderBy
  90. * @param object $pager
  91. * @access public
  92. * @return array
  93. */
  94. public function fetchExecutions($account, $status = 'all', $orderBy = 'id_desc', $pager = null)
  95. {
  96. return $this->dao->select('t1.role, t1.join, t1.days, t1.hours, t2.*')->from(TABLE_TEAM)->alias('t1')
  97. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.root = t2.id')
  98. ->where('t1.type')->eq('execution')
  99. ->andWhere('t1.account')->eq($account)
  100. ->andWhere('t2.deleted')->eq('0')
  101. ->andWhere('t2.multiple')->eq('1')
  102. ->andWhere('t2.type')->in('sprint,stage,kanban')
  103. ->andWhere('t2.vision')->eq($this->config->vision)
  104. ->beginIF(strpos('doing|wait|suspended|closed', $status) !== false)->andWhere('t2.status')->eq($status)->fi()
  105. ->beginIF($status == 'done')->andWhere('t2.status')->in('done,closed')->fi()
  106. ->beginIF($status == 'undone')->andWhere('t2.status')->notin('done,closed')->fi()
  107. ->beginIF($status == 'openedbyme')->andWhere('t2.openedBy')->eq($account)->fi()
  108. ->beginIF($status == 'delayed')->andWhere('t2.end')->gt('1970-1-1')->andWhere('t2.end')->lt(date(DT_DATE1))->andWhere('t2.status')->notin('done,closed,suspended')->fi()
  109. ->beginIF(!$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->sprints)->fi()
  110. ->orderBy("t2.$orderBy")
  111. ->page($pager)
  112. ->fetchAll('id');
  113. }
  114. /**
  115. * 获取某个用户参与的执行和执行中指派给他的任务数键值对。
  116. * Get the executions that the user joined and the task count of the execution.
  117. *
  118. * @param string $account
  119. * @param array $executionIdList
  120. * @access public
  121. * @return array
  122. */
  123. public function fetchExecutionTaskCount($account, $executionIdList)
  124. {
  125. if(!$executionIdList) return array();
  126. return $this->dao->select('execution, COUNT(1) AS count')->from(TABLE_TASK)
  127. ->where('deleted')->eq('0')
  128. ->andWhere('assignedTo')->eq($account)
  129. ->andWhere('execution')->in($executionIdList)
  130. ->groupBy('execution')
  131. ->fetchPairs();
  132. }
  133. /**
  134. * 删除 im_userdevice 表该用户的数据,以防止禅道修改密码后,禅道大桌面记住密码还能登录
  135. * Delete the im_userdevice table data of the user to prevent the user from logging in after the password is modified
  136. *
  137. * @param int $userID
  138. * @access public
  139. * @return void
  140. */
  141. public function deleteImUserDevice($userID)
  142. {
  143. try
  144. {
  145. $this->dao->delete()->from(TABLE_IM_USERDEVICE)->where('user')->eq($userID)->exec();
  146. } catch (Exception $e) {}
  147. }
  148. }