diff --git a/module/host/model.php b/module/host/model.php index cbb59cee95..3c622a823c 100644 --- a/module/host/model.php +++ b/module/host/model.php @@ -64,6 +64,35 @@ class hostModel extends model ->fetchAll(); } + /** + * 获取主机键值对列表。 + * Get pairs. + * + * @param string $moduleIdList + * @access public + * @return array + */ + public function getPairs(string $moduleIdList = ''): array + { + $modules = array(); + if($moduleIdList) + { + $this->loadModel('tree'); + foreach(explode(',', $moduleIdList) as $moduleID) + { + if(empty($moduleID)) continue; + $modules += $this->tree->getAllChildId($moduleID); + } + } + + return $this->dao->select('id, name')->from(TABLE_HOST) + ->where('deleted')->eq('0') + ->andWhere('type')->eq('normal') + ->beginIF($modules)->andWhere('`group`')->in($modules)->fi() + ->orderBy('`group`') + ->fetchPairs(); + } + /** * 创建主机。 * create a host.