model.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * The model file of release module 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 release
  9. * @version $Id: model.php 4129 2013-01-18 01:58:14Z wwccss $
  10. * @link https://www.zentao.net
  11. */
  12. ?>
  13. <?php
  14. class projectreleaseModel extends model
  15. {
  16. /**
  17. * 获取项目发布列表。
  18. * Get list of releases.
  19. *
  20. * @param int $projectID
  21. * @param string $type
  22. * @param string $orderBy
  23. * @param object $pager
  24. * @access public
  25. * @return array
  26. */
  27. public function getList($projectID, $type = 'all', $orderBy = 't1.date_desc', $pager = null)
  28. {
  29. $releases = $this->dao->select('t1.*, t2.name AS productName, t2.type AS productType')->from(TABLE_RELEASE)->alias('t1')
  30. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
  31. ->where('t1.deleted')->eq('0')
  32. ->andWhere("FIND_IN_SET($projectID, t1.project)")
  33. ->beginIF($type != 'all' && $type != 'review')->andWhere('t1.status')->eq($type)->fi()
  34. ->beginIF($type == 'review')->andWhere("FIND_IN_SET('{$this->app->user->account}', t1.reviewers)")->fi()
  35. ->orderBy($orderBy)
  36. ->page($pager)
  37. ->fetchAll('', false);
  38. $buildIdList = array();
  39. $productIdList = array();
  40. foreach($releases as $release)
  41. {
  42. $buildIdList = array_merge($buildIdList, explode(',', $release->build));
  43. $productIdList[$release->product] = $release->product;
  44. }
  45. $branchGroup = $this->loadModel('branch')->getByProducts($productIdList);
  46. $builds = $this->dao->select("id, project, product, branch, execution, name, scmPath, filePath")->from(TABLE_BUILD)->where('id')->in(array_unique($buildIdList))->fetchAll('id');
  47. foreach($releases as $release) $this->projectreleaseTao->processRelease($release, $branchGroup, $builds);
  48. return $releases;
  49. }
  50. /**
  51. * 获取最新的发布。
  52. * Get last release.
  53. *
  54. * @param int $projectID
  55. * @access public
  56. * @return bool|object
  57. */
  58. public function getLast($projectID)
  59. {
  60. return $this->dao->select('id, name')->from(TABLE_RELEASE)
  61. ->where('deleted')->eq(0)
  62. ->andWhere("FIND_IN_SET({$projectID}, project)")
  63. ->orderBy('date DESC')
  64. ->limit(1)
  65. ->fetch();
  66. }
  67. /**
  68. * 获取项目已发布的版本。
  69. * Get released builds from project.
  70. *
  71. * @param int $projectID
  72. * @access public
  73. * @return array
  74. */
  75. public function getReleasedBuilds($projectID)
  76. {
  77. /* Get release. */
  78. $releases = $this->dao->select('shadow,build')->from(TABLE_RELEASE)
  79. ->where('deleted')->eq(0)
  80. ->andWhere("FIND_IN_SET({$projectID}, project)")
  81. ->fetchAll();
  82. /* Get released builds. */
  83. $buildIdList = '';
  84. foreach($releases as $release) $buildIdList .= ",{$release->build},{$release->shadow}";
  85. $buildIdList = explode(',', trim($buildIdList, ','));
  86. return array_unique($buildIdList);
  87. }
  88. /**
  89. * 判断按钮是否可以点击。
  90. * Judge button is clickable or not.
  91. *
  92. * @param object $release
  93. * @param string $action
  94. * @static
  95. * @access public
  96. * @return bool
  97. */
  98. public static function isClickable($release, $action)
  99. {
  100. if(!empty($release->deleted)) return false;
  101. global $app;
  102. if($app->rawMethod == 'browse' && !empty($release->releases) && $action == 'view') return false;
  103. $action = strtolower($action);
  104. if($action == 'notify') return ($release->bugs || $release->stories) && $release->status == 'normal';
  105. if($action == 'play') return $release->status == 'terminate';
  106. if($action == 'pause') return $release->status == 'normal';
  107. if($action == 'publish') return $release->status == 'wait' || $release->status == 'fail';
  108. if(!empty($release->releases) && ($action == 'linkstory' || $action == 'linkbug')) return false;
  109. return true;
  110. }
  111. }