control.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * The control file of space 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 Jianhua Wang <wangjianhua@easycorp.ltd>
  8. * @package space
  9. * @link https://www.zentao.net
  10. */
  11. class space extends control
  12. {
  13. /**
  14. * DevOps应用列表。
  15. * Browse departments and users of a space.
  16. *
  17. * @param int $spaceID
  18. * @param string $browseType
  19. * @param string $orderBy
  20. * @param int $recTotal
  21. * @param int $recPerPage
  22. * @param int $pageID
  23. @access public
  24. * @return void
  25. */
  26. public function browse($spaceID = 0, $browseType = '', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  27. {
  28. if(!$browseType) $browseType = $this->config->inQuickon ? 'running' : 'all';
  29. if(!commonModel::hasPriv('space', 'browse')) $this->loadModel('common')->deny('space', 'browse', false);
  30. $space = null;
  31. if($spaceID) $space = $this->space->getByID($spaceID);
  32. if(empty($space)) $space = $this->space->defaultSpace($this->app->user->account);
  33. $allInstances = $this->spaceZen->getSpaceInstances($browseType);
  34. /* Data sort. */
  35. list($order, $sort) = explode('_', $orderBy);
  36. $createdColumn = helper::arrayColumn($allInstances, $order == 'id' ? 'createdAt' : $order);
  37. array_multisort($createdColumn, $sort == 'desc' ? SORT_DESC : SORT_ASC, $allInstances);
  38. /* Pager. */
  39. $this->app->loadClass('pager', true);
  40. $newRecTotal = count($allInstances);
  41. if($recPerPage * ($pageID - 1) > $newRecTotal) $pageID = 1;
  42. $pager = new pager($newRecTotal, $recPerPage, $pageID);
  43. $allInstances = array_chunk($allInstances, $pager->recPerPage);
  44. $this->view->title = $this->lang->space->common;
  45. $this->view->pager = $pager;
  46. $this->view->orderBy = $orderBy;
  47. $this->view->browseType = $browseType;
  48. $this->view->instances = (empty($allInstances) or empty($allInstances[$pageID - 1])) ? array() : $allInstances[$pageID - 1];
  49. $this->view->users = $this->loadModel('user')->getPairs('noclosed,noletter');
  50. $this->display();
  51. }
  52. /**
  53. * 创建一个应用。
  54. * Create a application.
  55. *
  56. * @param int $appID
  57. * @access public
  58. * @return void
  59. */
  60. public function createApplication($appID = 0)
  61. {
  62. if(!commonModel::hasPriv('instance', 'manage')) $this->loadModel('common')->deny('instance', 'manage', false);
  63. $this->app->loadLang('sonarqube');
  64. $this->app->loadLang('jenkins');
  65. $apps = array();
  66. $defaultApp = '';
  67. if($this->config->inQuickon)
  68. {
  69. $pagedApps = $this->loadModel('store')->searchApps('', '', 0, 1, 10000);
  70. foreach($pagedApps->apps as $app)
  71. {
  72. if(!$appID && $app->alias == 'GitLab') $defaultApp = $app->id;
  73. $apps[$app->id] = $app->alias;
  74. }
  75. $mysqlList = $this->loadModel('cne')->sharedDBList('mysql');
  76. $pgList = $this->cne->sharedDBList('postgresql');
  77. $versionList = $this->store->getVersionPairs($appID);
  78. $cloudApp = $this->loadModel('store')->getAppInfo($appID);
  79. $showDb = !empty($cloudApp) && ((!empty($cloudApp->dependencies->mysql) && $mysqlList) || (!empty($cloudApp->dependencies->postgresql) && $pgList));
  80. $this->view->pgList = $pgList;
  81. $this->view->mysqlList = $mysqlList;
  82. $this->view->versionList = $versionList;
  83. $this->view->showDb = $showDb;
  84. $this->view->thirdDomain = $this->loadModel('instance')->randThirdDomain();
  85. }
  86. $this->view->apps = $apps;
  87. $this->view->defaultApp = $defaultApp;
  88. $this->view->title = $this->lang->space->install;
  89. $this->view->appID = (int)$appID;
  90. $this->display();
  91. }
  92. /**
  93. * 获取应用商店app信息。
  94. * Get a store app info.
  95. *
  96. * @param int $appID
  97. * @access public
  98. * @return void
  99. */
  100. public function getStoreAppInfo($appID)
  101. {
  102. if(!commonModel::hasPriv('space', 'browse')) $this->loadModel('common')->deny('space', 'browse', false);
  103. $cloudApp = $this->loadModel('store')->getAppInfo($appID);
  104. $versionPairs = $this->store->getVersionPairs($appID);
  105. $versionItems = array();
  106. foreach($versionPairs as $code => $version) $versionItems[] = array('text' => $version, 'value' => $code);
  107. $cloudApp->versionList = $versionItems;
  108. echo json_encode($cloudApp);
  109. }
  110. }