* Split space methods.

This commit is contained in:
caoyanyi
2023-12-06 14:13:35 +08:00
parent 6a7c4207c7
commit bd095c5aef
4 changed files with 117 additions and 95 deletions
+20 -69
View File
@@ -7,16 +7,16 @@ declare(strict_types=1);
* @license ZPL (http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Jianhua Wang <wangjianhua@easycorp.ltd>
* @package space
* @version $Id$
* @link https://www.zentao.net
*/
class space extends control
{
/**
* DevOps应用列表。
* Browse departments and users of a space.
*
* @param int $param
* @param string $type
* @param int $spaceID
* @param string $browseType
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
@@ -24,59 +24,14 @@ class space extends control
@access public
* @return void
*/
public function browse($spaceID = null, $browseType = 'all', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
public function browse(int $spaceID = 0, string $browseType = 'all', string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1)
{
if(!commonModel::hasPriv('space', 'browse')) $this->loadModel('common')->deny('space', 'browse', false);
$this->app->loadLang('instance');
$this->loadModel('instance');
$this->loadModel('store');
$spaceType = $this->cookie->spaceType ? $this->cookie->spaceType : 'bycard';
$space = null;
if($spaceID) $space = $this->space->getByID($spaceID);
if(empty($space)) $space = $this->space->defaultSpace($this->app->user->account);
$search = '';
if(!empty($_POST))
{
$conditions = fixer::input('post')
->trim('search')
->setDefault('search', '')
->get();
$search = $conditions->search;
}
$instances = $this->space->getSpaceInstances(0, $browseType, $search);
foreach($instances as $instance)
{
$instance->externalID = 0;
$instance->orgID = $instance->id;
$instance->type = 'store';
if(in_array($instance->appName, $this->config->space->zentaoApps))
{
$externalApp = $this->space->getExternalAppByApp($instance);
if($externalApp) $instance->externalID = $externalApp->id;
}
}
$maxID = 0;
$pipelines = array();
if($browseType == 'all' || $browseType == 'running') $pipelines = $this->loadModel('pipeline')->getList('', 'id_desc');
if(!empty($instances)) $maxID = max(array_keys($instances));
foreach($pipelines as $key => $pipeline)
{
if($pipeline->createdBy == 'system') unset($pipelines[$key]);
$pipeline->createdAt = $pipeline->createdDate;
$pipeline->appName = $this->lang->space->appType[$pipeline->type];
$pipeline->status = 'running';
$pipeline->type = 'external';
$pipeline->externalID = $pipeline->id;
$pipeline->orgID = $pipeline->id;
$pipeline->id = ++ $maxID;
}
$allInstances = array_merge($instances, $pipelines);
$allInstances = $this->spaceZen->getSpaceInstances($browseType);
/* Data sort. */
list($order, $sort) = explode('_', $orderBy);
@@ -93,17 +48,13 @@ class space extends control
$solution = $this->loadModel('solution')->getLastSolution();
if($solution && $solution->status == 'installing') $solutionID = $solution->id;
$this->view->title = $this->lang->space->common;
$this->view->position[] = $this->lang->space->common;
$this->view->pager = $pager;
$this->view->orderBy = $orderBy;
$this->view->solutionID = $solutionID;
$this->view->browseType = $browseType;
$this->view->spaceType = $spaceType;
$this->view->instances = (empty($allInstances) or empty($allInstances[$pageID - 1])) ? array() : $allInstances[$pageID - 1];
$this->view->currentSpace = $space;
$this->view->searchName = $search;
$this->view->users = $this->loadModel('user')->getPairs('noclosed,noletter');
$this->view->title = $this->lang->space->common;
$this->view->pager = $pager;
$this->view->orderBy = $orderBy;
$this->view->solutionID = $solutionID;
$this->view->browseType = $browseType;
$this->view->instances = (empty($allInstances) or empty($allInstances[$pageID - 1])) ? array() : $allInstances[$pageID - 1];
$this->view->users = $this->loadModel('user')->getPairs('noclosed,noletter');
$this->display();
}
@@ -112,11 +63,11 @@ class space extends control
* 创建一个应用。
* Create a application.
*
* @param int $appID
* @param int $appID
* @access public
* @return void
*/
public function createApplication($appID = 0)
public function createApplication(int $appID = 0)
{
if(!commonModel::hasPriv('instance', 'manage')) $this->loadModel('common')->deny('instance', 'manage', false);
@@ -127,8 +78,7 @@ class space extends control
$defaultApp = '';
if($this->config->inQuickon)
{
$this->loadModel('cne');
$pagedApps = $this->loadModel('store')->searchApps('', '', array(), 1, 10000);
$pagedApps = $this->loadModel('store')->searchApps('', '', array(), 1, 10000);
foreach($pagedApps->apps as $app)
{
if(strpos($app->name, 'zentao') === 0 || strpos($app->name, 'zdoo') === 0 || strpos($app->name, 'xuanxuan') === 0) continue;
@@ -137,7 +87,7 @@ class space extends control
$apps[$app->id] = $app->alias;
}
$mysqlList = $this->cne->sharedDBList('mysql');
$mysqlList = $this->loadModel('cne')->sharedDBList('mysql');
$pgList = $this->cne->sharedDBList('postgresql');
$versionList = $this->store->getVersionPairs($appID);
$cloudApp = $this->loadModel('store')->getAppInfo($appID);
@@ -154,7 +104,6 @@ class space extends control
$this->view->defaultApp = $defaultApp;
$this->view->title = $this->lang->space->install;
$this->view->appID = $appID;
$this->view->addType = empty($appID) ? 'external' : 'store';
$this->display();
}
@@ -169,12 +118,14 @@ class space extends control
public function getStoreAppInfo(int $appID)
{
if(!commonModel::hasPriv('space', 'browse')) $this->loadModel('common')->deny('space', 'browse', false);
$cloudApp = $this->loadModel('store')->getAppInfo($appID);
$versionPairs = $this->store->getVersionPairs($appID);
$versionItems = array();
foreach($versionPairs as $k => $v) $versionItems[] = array('text' => $v, 'value' => $k);
foreach($versionPairs as $code => $version) $versionItems[] = array('text' => $version, 'value' => $code);
$cloudApp->versionList = $versionItems;
return print(json_encode($cloudApp));
echo json_encode($cloudApp);
}
}
+38 -26
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* The model file of space module of ZenTaoPMS.
*
@@ -6,72 +7,83 @@
* @license ZPL (http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Jianhua Wang <wangjianhua@easycorp.ltd>
* @package space
* @version $Id$
* @link https://www.zentao.net
*/
class spaceModel extends model
{
/**
* 获取用户的空间列表。
* Get space list by user account.
*
* @param string $account
* @access public
* @return array
*/
public function getSpacesByAccount($account)
public function getSpacesByAccount(string $account): array
{
return $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('owner')->eq($account)->fetchAll();
return $this->dao->select('*')->from(TABLE_SPACE)
->where('deleted')->eq(0)
->andWhere('owner')->eq($account)
->fetchAll();
}
/**
* 获取用户的默认空间。
* Get user's default space by user account.
*
* @param string $account
* @access public
* @return object
*/
public function defaultSpace($account)
public function defaultSpace(string $account): ?object
{
$default = $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('owner')->eq($account)->orderBy('default desc')->limit(1)->fetch();
$default = $this->dao->select('*')->from(TABLE_SPACE)
->where('deleted')->eq(0)
->andWhere('owner')->eq($account)
->orderBy('default desc')
->fetch();
if(empty($default)) return $this->createDefaultSpace($account);
return $default;
}
/**
* 获取用户的系统空间。
* Get system space.
*
* @param string $account
* @access public
* @return object
*/
public function getSystemSpace($account)
public function getSystemSpace(string $account): ?object
{
$k8space = $this->config->k8space;
$sysSpace = $this->dao->select('*')->from(TABLE_SPACE)->where('k8space')->eq($k8space)->andWhere('owner')->eq($account)->fetch();
$sysSpace = $this->dao->select('*')->from(TABLE_SPACE)
->where('k8space')->eq($this->config->k8space)
->andWhere('owner')->eq($account)
->andWhere('deleted')->eq(0)
->fetch();
if($sysSpace) return $sysSpace;
$spaceData = new stdClass;
$spaceData->name = $this->lang->space->systemSpace;
$spaceData->owner = $account;
$spaceData->k8space = $k8space;
$spaceData->k8space = $this->config->k8space;
$spaceData->default = 0;
$spaceData->createdAt = date('Y-m-d H:i:s');
$this->dao->insert(TABLE_SPACE)->data($spaceData)->autoCheck()->exec();
return $this->dao->select('*')->from(TABLE_SPACE)->where('id')->eq($this->dao->lastInsertId())->fetch();
return $this->fetchByID($this->dao->lastInsertId());
}
/**
* 创建默认空间。
* Create default space by account
*
* @param string $account
* @access public
* @return object
*/
public function createDefaultSpace($account)
public function createDefaultSpace(string $account): ?object
{
$default = new stdclass;
$default->name = $this->lang->space->defaultSpace;
@@ -79,24 +91,24 @@ class spaceModel extends model
$default->owner = $account;
$default->default = true;
$default->createdAt = date('Y-m-d H:i:s');
$this->dao->insert(TABLE_SPACE)->data($default)->autoCheck()->exec();
return $this->dao->select('*')->from(TABLE_SPACE)->where('id')->eq($this->dao->lastInsertId())->fetch();
return $this->fetchByID($this->dao->lastInsertId());
}
/**
* Get app list in space
* 获取用户空间的应用列表。
* Get app list in space by space id.
*
* @param int $spaceID
* @param string $status
* @param string $searchName
* @param object $pager
* @access public
* @return array
*/
public function getSpaceInstances($spaceID, $status = 'all', $searchName = '', $pager = null)
public function getSpaceInstances(int $spaceID, string $status = 'all', string $searchName = '', object $pager = null): array
{
$space = $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('id')->eq($spaceID)->fetch();
$instances = $this->dao->select('*')->from(TABLE_INSTANCE)
->where('deleted')->eq(0)
->beginIF($spaceID)->andWhere('space')->eq($spaceID)->fi()
@@ -110,22 +122,22 @@ class spaceModel extends model
$solutionIDList = helper::arrayColumn($instances, 'solution');
$solutions = $this->dao->select('*')->from(TABLE_SOLUTION)->where('id')->in($solutionIDList)->fetchAll('id');
foreach($instances as $instance) $instance->solutionData = zget($solutions, $instance->solution, new stdclass);
return $instances;
}
/**
* 根据ID获取空间。
* Get space by id.
*
* @param int $id
* @param int $spaceID
* @access public
* @return object
*/
public function getByID($id)
public function getByID(int $spaceID): ?object
{
return $this->dao->select('*')->from(TABLE_SPACE)
return $this->dao->select('*')->from(TABLE_SPACE)
->where('deleted')->eq(0)
->andWhere('id')->eq($id)
->andWhere('id')->eq($spaceID)
->andWhere('owner')->eq($this->app->user->account)
->fetch();
}
@@ -136,9 +148,9 @@ class spaceModel extends model
*
* @param object $instance
* @access public
* @return object|false
* @return object
*/
public function getExternalAppByApp(object $instance): object|false
public function getExternalAppByApp(object $instance): ?object
{
return $this->dao->select('*')->from(TABLE_PIPELINE)
->where('deleted')->eq('0')
+1
View File
@@ -20,6 +20,7 @@ foreach($instances as $instance) if('store' === $instance->type) $statusMap[$ins
jsVar('statusMap', $statusMap);
jsVar('idList', array_keys($statusMap));
$this->loadModel('instance');
$instances = initTableData($instances, $config->space->dtable->fieldList, $this->instance);
featureBar
+58
View File
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/**
* The zen file of space module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
* @package space
* @link https://www.zentao.net
*/
class spaceZen extends space
{
/**
* 获取空间下的应用实例。
* Get space instances.
*
* @param string $browseType
* @access protected
* @return array
*/
protected function getSpaceInstances(string $browseType = 'all'): array
{
$instances = $this->space->getSpaceInstances(0, $browseType);
foreach($instances as $instance)
{
$instance->externalID = 0;
$instance->orgID = $instance->id;
$instance->type = 'store';
if(in_array($instance->appName, $this->config->space->zentaoApps))
{
$externalApp = $this->space->getExternalAppByApp($instance);
if($externalApp) $instance->externalID = $externalApp->id;
}
}
$maxID = 0;
$pipelines = array();
if($browseType == 'all' || $browseType == 'running') $pipelines = $this->loadModel('pipeline')->getList('', 'id_desc');
if(!empty($instances)) $maxID = max(array_keys($instances));
foreach($pipelines as $key => $pipeline)
{
$maxID ++;
if($pipeline->createdBy == 'system') unset($pipelines[$key]);
$pipeline->createdAt = $pipeline->createdDate;
$pipeline->appName = $this->lang->space->appType[$pipeline->type];
$pipeline->status = 'running';
$pipeline->type = 'external';
$pipeline->externalID = $pipeline->id;
$pipeline->orgID = $pipeline->id;
$pipeline->id = $maxID;
}
return array_merge($instances, $pipelines);
}
}